Things used in this project
|Software apps and online services:|
In this tutorial, we will cover how to use bip.io to connect a TI Launchpad module with dedicated ARM MCU to a Google Sheet. What you'll need to follow along:
- a TI Tiva-C Launchpad or TI Stellaris® LM4F120 LaunchPad
- a SimpleLink Wi-Fi CC3100 BoosterPack
- a MMA8452Q Triple Axis Accelerometer
- two 330Ω resistors
- a breadboard
- a fistful of jumper wires
- a multimeter
- (and if you don't have a breakout board, two additional 10kΩ resistors)
Some additional tools that are useful but not absolutely necessary (but you should definitely acquire):
- an oscilloscope
- a Bus Pirate
In addition to the physical goods, you will also need:
Before going in and creating your workflow, it is a good idea to first setup a new Google Sheet for this project. The two things you should do are create a doc named
ShipIoT and rename
The integration with Google Sheets in bip.io can use both of these values to identify where to put your data. By renaming the sheet, you can easily save the data for later.
which will become our workflow for collecting our accelerometer data in a Google Sheet. Once you click that button, you will be presented with a blank canvas:
From here, it take about two minutes to configure the workflow:
If you didn't catch all that, click on the circle in the center, and you will be presented with a menu of event triggers:
Incoming Web Hook option so that our CC3100 board will be able to connect to bip.io via a HTTP connection used by the library. This will generate the following view:
You can now see the center circle has changed to our
Incoming Web Hook icon. We also have a URL above that broken out into parts. We need to provide the final component in the path which is currently
Untitled. For this example, let's name this
Clicking on the
Show/Hide Endpoint button will assemble the URL into one suitable for copying and pasting into your application.
Next we'll add an action to add the data sent to the
Incoming Web Hook to our Google Sheet. Click the
Add an Action button to open the action selection modal:
Google Drive, and if this is your first time through, proceed through the activation process. When you have Google Drive selected you will be presented with a set of individual actions that this module can perform:
Append To A Spreadsheet action. We'll later configure the properties of this action to write to the Google Sheet we created earlier. But first we'll drag and drop from the
Incoming Web Hook to the
Google Drive icon to link them.
After they are linked, we'll describe the data coming from the
Incoming Web Hook by selecting the
Parser tab. In the left hand panel, we can type some sample data that the accelerometer will send:
If we then hit the
Parse button, it will generate a JSON schema that we can use to parse the incoming messages. There's no need to save the schema, as we will be using it in just a moment.
Next back at the
Setup tab, double click on the
Google Drive icon, and you'll be presented with an options screen. Fill out the fields according to how you setup your Google Sheet. In my case I named the spreadsheet
ShipIoT and the worksheet
If you then scroll down, you'll see a section for the
New Row contents, which we will use the
Custom option to select the
Attributes of the incoming message to populate. Because we configured the JSON schema before coming here, we will be presented with a list of fields that correspond to our device's data.
Then all that is left to do is to click
OK and then
Save, and our new workflow is now running. We can use the
Auth tab to change the authentication credentials on the endpoint. By default it uses your user name and your API Token (found under settings) as the password. Selecting
Basic Auth can allow you to change the username and password which is generally a good idea if you want to make the service available to someone else.
Setting up the Board
Once you have all of your components together:
- insert the MMA8452Q breakout board in column j
- trim the leads on two of the 330Ω resistors
- insert the 330Ω resistors in series with the SDA and SCL pins bridging the gap
The board should look like this:
It is a good idea to leave some free holes between the resistors and the board so that you can safely probe the lines. These two resistors are there for current limiting on the data (SDA) and clock (SCL) of the I2C bus.
Next we'll add some jumpers to the board. I'm going to use red (3.3V), black (GND), yellow (SCL), and green (SDA), but you can pick your own favorite colors. My pin out will look like:
- Red f1 to 1.01 (3.3V)
- Black f6 to 3.02 (GND)
- Green a2 to 1.10 (I2C1SDA)
- Yellow a3 to 1.09 (I2C1SCL)
The breadboard will look roughly like this:
On the other side, the CC3100BOOST should be installed on top of the TIVA-C or LM4F120 Launchpad. The jumper wires should look like:
If you only have male to male jumper, you can wire up the back of the Launchpad as follows (remember that everything is backwards!)
Verifying the I2C address (optional)
If you have a Bus Pirate handy, now is a great time to verify that your accelerometer is working, and ensuring it works. To start, we'll make sure we have the right leads:
Once you're certain you have the correct leads with 3.3v and ground, it is time to test to see if your MMA8452 is working correctly. The Bus Pirate allows us to connect search the I2C bus for the address of the device. If you're using the Sparkfun breakout board, there are two possible addresses: 0x1D or 0x1C. By tying the jumper on the bottom to ground, you can select the second address. To make sure you have the right address you can search the I2C bus this way:
Programming the Board
Now that we have verified that the MMA8452 is working, we can program the board. If you don't like typing, you can download the code for this tutorial from Github.
You will need to install the directories contained within into the libraries directory for your Energia setup. On Mac OS X, you should be able to place both the ShipIoT and SFE_MMA8452Q directories into ~/Documents/Energia/libraries.
Once all of the files are installed, open the ShipIoTCC3100MMA8452Q.ino file in Energia, and you will see the following source:
The things that you need to change to work in your environment:
- change the ssid to your network's SSID
- change the password to your network's password
- change the bip.io URL, user, and password
- change the address passed to accel if necessary
If you use my credentials from the image, you will get an access denied response from the server. But points if you tried it :) Plugging in the board, and selecting the correct
Tools >> Board and
Tools >> Serial Port from the Energia menu should make it possible just to compile and load onto your board.
Once running, open up the
Serial Console and you should see a sequence of dots as it connects to your WiFi network, obtains an ip address, and then the device should start making HTTP request to your URL. If everything is working correctly you should start seeing data appear in you spreadsheet.
Odds and Ends
If it all worked, you should have seen results appearing in your spreadsheet within seconds of the device finishing it's programming. Though in the real world not everything goes as planned. In fact, the first time I tried using the Wire library, I got no activity on any of the pins. So I hooked it up to a scope:
If you look at the
SFE_MMA8452Q.cpp line 45, there's a special
Wire.setModule(1) line which is necessary for selecting which of the I2C interfaces Energia's Wire library should use. After discovering this method however, I was able to get something on the scope:
In this picture the SCL is on probe 1, and the SDA is on probe 2. I2C is active low, so all you'll see if it isn't working is a 1.8V trace. You can see that the clock isn't terribly square, and there is some ringing, but nothing too much.
If you run into issues with I2C, this is a good place to start looking. And always remember to ground yourself, test w/ your multimeter, and double check with your scope. The Bus Pirate was also very useful in ensuring that the I2C communications were going through once everything was running. Macro (2) can be a very powerful tool for finding communication problems.
Did you replicate this project? Share it!I made one
Love this project? Think it could be improved? Tell us what you think!