Blog

Ship IoT with the TI CC3100 and Google Sheets

Jul 2015/ Posted By: wotio team

<h2 id="prerequisites">Prerequisites</h2>
<p>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:</p>
<ul>
<li>a <a href="https://store.ti.com/Tiva-C-LaunchPad.aspx">TI Tiva-C Launchpad</a> or <a href="http://www.ti.com/tool/ek-lm4f120xl">TI Stellaris&reg; LM4F120 LaunchPad</a></li>
<li>a <a href="http://www.ti.com/tool/cc3100boost">SimpleLink Wi-Fi CC3100 BoosterPack</a></li>
<li>a <a href="https://www.sparkfun.com/products/12756">MMA8452Q Triple Axis Accelerometer </a></li>
<li>two 330Ω resistors</li>
<li>a breadboard</li>
<li>a fistful of jumper wires</li>
<li>a multimeter</li>
<li>(and if you don't have a breakout board, two additional 10kΩ resistors)</li>
</ul>
<p>Some additional tools that are useful but not absolutely necessary (but you should definitely acquire):</p>
<ul>
<li>an oscilloscope</li>
<li>a <a href="http://dangerousprototypes.com/docs/Bus_Pirate">Bus Pirate</a></li>
</ul>
<p>In addition to the physical goods, you will also need:</p>
<ul>
<li><a href="https://docs.google.com/spreadsheets/">a Google account</a></li>
<li><a href="https://shipiot.net">a bip.io account</a></li>
</ul>
<h2 id="configuringbipio">Configuring bip.io</h2>
<p>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 <code>ShipIoT</code> and rename <code>Sheet1</code> to <code>accel</code>.</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/sheet.png" alt="Google Sheet" /></p>
<p>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.</p>
<p>Next we'll</p>
<p><a href="https://shipiot.net/dash#bipio/new/trigger"><img title="" src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/Screen-Shot-2015-07-30-at-9-40-14-AM.png" alt="Create A Bip" /></a></p>
<p>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:</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/blank-1.png" alt="blank bip canvas" /></p>
<p>From here, it take about two minutes to configure the workflow:</p>
<p><iframe src="https://www.youtube.com/embed/rZ9FdvF_6OQ" frameborder="0" width="560" height="315" allowfullscreen="allowfullscreen"></iframe></p>
<p>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:</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/trigger-selection.png" alt="trigger selection" /></p>
<p>Select the <code>Incoming Web Hook</code> 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:</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/event-trigger.png" alt="trigger" /></p>
<p>You can now see the center circle has changed to our <code>Incoming Web Hook</code> 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 <code>Untitled</code>. For this example, let's name this <code>sheets</code>.</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/url-named.png" alt="url filled out" /></p>
<p>Clicking on the <code>Show/Hide Endpoint</code> button will assemble the URL into one suitable for copying and pasting into your application.</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/url.png" alt="url listing" /></p>
<p>Next we'll add an action to add the data sent to the <code>Incoming Web Hook</code> to our Google Sheet. Click the <code>Add an Action</code> button to open the action selection modal:</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/action-selection.png" alt="action selection" /></p>
<p>Select <code>Google Drive</code>, 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:</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/google-drive-actions.png" alt="select action" /></p>
<p>Select the <code>Append To A Spreadsheet</code> 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 <code>Incoming Web Hook</code> to the <code>Google Drive</code> icon to link them.</p>
<p>After they are linked, we'll describe the data coming from the <code>Incoming Web Hook</code> by selecting the <code>Parser</code> tab. In the left hand panel, we can type some sample data that the accelerometer will send:</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/json-schema-before.png" alt="json schema before" /></p>
<p>If we then hit the <code>Parse</code> 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.</p>
<p>Next back at the <code>Setup</code> tab, double click on the <code>Google Drive</code> 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 <code>ShipIoT</code> and the worksheet <code>accel</code>:</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/google-drvie-options.png" alt="drive options" /></p>
<p>If you then scroll down, you'll see a section for the <code>New Row</code> contents, which we will use the <code>Custom</code> option to select the <code>Attributes</code> 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.</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/row-attributes.png" alt="row attributes" /></p>
<p>Then all that is left to do is to click <code>OK</code> and then <code>Save</code>, and our new workflow is now running. We can use the <code>Auth</code> 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 <code>Basic Auth</code> 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.</p>
<h2 id="settinguptheboard">Setting up the Board</h2>
<p>Once you have all of your components together:</p>
<ul>
<li>insert the MMA8452Q breakout board in column j</li>
<li>trim the leads on two of the 330Ω resistors</li>
<li>insert the 330Ω resistors in series with the SDA and SCL pins bridging the gap</li>
</ul>
<p>The board should look like this:</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/resistors.jpg" alt="breadboard w/ resitors" /></p>
<p>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.</p>
<p>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:</p>
<ul>
<li>Red f1 to 1.01 (3.3V)</li>
<li>Black f6 to 3.02 (GND)</li>
<li>Green a2 to 1.10 (I2C1SDA)</li>
<li>Yellow a3 to 1.09 (I2C1SCL)</li>
</ul>
<p>The breadboard will look roughly like this:</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/boardwires.jpg" alt="breadboard wiring" /></p>
<p>On the other side, the CC3100BOOST should be installed on top of the TIVA-C or LM4F120 Launchpad. The jumper wires should look like:</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/top-1.jpg" alt="topside jumpers" /></p>
<p>If you only have male to male jumper, you can wire up the back of the Launchpad as follows (remember that everything is backwards!)</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/underside.jpg" alt="underside of Launchpad" /></p>
<h2 id="verifyingthei2caddressoptional">Verifying the I2C address (optional)</h2>
<p>If you have a <a href="http://dangerousprototypes.com/docs/Bus_Pirate">Bus Pirate</a> 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:</p>
<p><iframe src="https://www.youtube.com/embed/zSjYC_diu9c" frameborder="0" width="560" height="315" allowfullscreen="allowfullscreen"></iframe></p>
<p>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:</p>
<p><iframe src="https://www.youtube.com/embed/qQ_H30ykV34" frameborder="0" width="560" height="315" allowfullscreen="allowfullscreen"></iframe></p>
<h2 id="programmingtheboard">Programming the Board</h2>
<p>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 <a href="https://github.com/WoTio/shipiot-cc3100-mma8452">Github</a>.</p>
<blockquote>
<p>git clone <a href="https://github.com/WoTio/shipiot-cc3100-mma8452.git">https://github.com/WoTio/shipiot-cc3100-mma8452.git</a></p>
</blockquote>
<p>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.</p>
<p>Once all of the files are installed, open the ShipIoT<em>CC3100</em>MMA8452Q.ino file in Energia, and you will see the following source:</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/Screen-Shot-2015-07-30-at-2-52-16-PM.png" alt="ShipIoT_CC3100_MMA8452Q.ino source" /></p>
<p>The things that you need to change to work in your environment:</p>
<ul>
<li>change the ssid to your network's SSID</li>
<li>change the password to your network's password</li>
<li>change the bip.io URL, user, and password</li>
<li>change the address passed to accel if necessary</li>
</ul>
<p>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 <code>Tools &gt;&gt; Board</code> and <code>Tools &gt;&gt; Serial Port</code> from the Energia menu should make it possible just to compile and load onto your board.</p>
<p>Once running, open up the <code>Serial Console</code> 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.</p>
<p><iframe src="https://www.youtube.com/embed/BnXmNQmJKc0" frameborder="0" width="420" height="315" allowfullscreen="allowfullscreen"></iframe></p>
<h2 id="oddsandends">Odds and Ends</h2>
<p>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:</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/IMG_6582.JPG" alt="probes" /></p>
<p>If you look at the <code>SFE_MMA8452Q.cpp</code> line 45, there's a special <code>Wire.setModule(1)</code> 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:</p>
<p><img src="http://idfiles.leveelabs.com/55bd0288af0b0930ba599bd0c4b7ca38/resources/img_new/labs_wot_io/IMG_6580.JPG" alt="scope picture" /></p>
<p>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.</p>
<p>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.</p>