TinyZero Accelerometer BMA250 Internet of Things Project with Cayenne

by Laverena Wienclaw November 21, 2018

TinyZero Accelerometer BMA250 Internet of Things Project with Cayenne

In this tutorial, we will use Cayenne to capture some accelerometer readings on their nice Internet of Things dashboard that can be accessed from computer or mobile application!

This tutorial builds on a couple of things, so you may want to checkout the TinyZero Setup Tutorial, the TinyZero with Accelerometer BMA250 Tutorial, and the WiFi TinyShield connection tutorial before getting started with this project. 


Materials Needed

Hardware: 

or

Software: 


Step 1: Assembly (Hardware)

You will build this setup by connecting the WiFi shield to the TinyZero board with the 32-pin connectors. You can snap them together like legos, it's that easy. 


Step 2: Software (Setup)

This part may be a little involved, but it'll be broken down into a lot of small steps.

Create a Cayenne account (or use a previous one)

Create device a device:

Click in the top left: Add new.../Device/Widget and then you should be opened to this screen where you can select Arduino:

Make the selections Arduino Pro Wifi101 Shield. You should see your Cayenne mqtt username, password, and client id on this page:

In order to move on from this screen, the board must connect to Cayenne via your WiFi and Cayenne authentication info, so we will move on to the Arduino IDE to prepare for the program by downloading some libraries:

Go to Sketch/Include Library/Manage Libraries...  and type in WiFi101 in the window that pops up, click Install on the library called WiFi101:

 You'll use the same process to Install the library CayenneMQTT:


Step 3: The Code!

Now you can download and program your TinyZero! 

Plug in your USB to your TinyZero and make sure your Tools tab choices are correct! Make the following Tools selections to connect to your TinyDuino: 

  • Board -> TinyZero
  • Port -> COM##  (If you're not sure which Port your Arduino is connected to, check this out for Windows/Mac help)
  • Programmer: "Arduino as ISP"

So now we can download or create files for the program below. When downloading these files or copying and pasting them into new files, make sure the folder they're in has the same name as the .ino program so that everything compiles correctly in Arduino. Often, error windows will pop up immediately to let you know you need to fix this.

You’ll need to change:

  • The ssid[] variable, make this your WiFi's name 
  • The wifiPassword[] variable, make it your WiFi password 
  • The username[], password[], and clientID[] variables generated from Cayenne

Once you make those changes and download the program, you must open up the Serial Monitor in the Arduino IDE under Tools/Serial Monitor. If you do not open the Serial Monitor, the program won't move forward from the line that says "while(!SerialUSB);" so the WiFi won't connect until you do this step.

The Serial Monitor will print out the values from the BMA250 accelerometer sensor so you can see them before they are sent to Cayenne.

Speaking of Cayenne, once the WiFi connects with your authentication info, the Cayenne screen should find your device and open up to your dashboard: 

At the end of the program, a function called CAYENNE_OUT_DEFAULT() will be sending the x, y, z, and temperature data read from the BMA250 sensor to Cayenne. This data should show up after a minute or two and look something like this: 

You should see a '+' button to add those channels to your dashboard permanently. 

Now that you have data coming from the BMA250 sensor, you can re-label and make the data look a little nicer!

You can click on the graph icon on any of the data blocks to see a graph of data readings over time.

Customize your dashboard however you like to use your new Internet-Connected device! Cayenne even has an app you can use to monitor your data readings on the go.


    Contact Us

    If you have any questions or feedback, feel free to email info@tinycircuits.com.

    Share your moisture reporting plants and other projects by tagging @TinyCircuits on Instagram, Twitter, or Facebook so we can feature it!

    Thanks for making with us!

     



    Laverena Wienclaw
    Laverena Wienclaw

    Author



    Also in Learn

    TinyZero Setup Tutorial
    TinyZero Setup Tutorial

    by Laverena Wienclaw November 21, 2018

    Ready to get started with your new TinyCircuits product? This tutorial will cover basic setup of the TinyZero.

    View full article →

    Using the TinyZero Accelerometer
    Using the TinyZero Accelerometer

    by Laverena Wienclaw November 21, 2018

    This tutorial will guide you through reading values from the Accelerometer that can be populated on the TinyZero

    View full article →

    SRAM TinyShield Tutorial
    SRAM TinyShield Tutorial

    by Nick DiVitto July 02, 2018

    The SRAM Tinyshield allows you to add memory to your TinyDuino projects that can read and write at a virtually instant rate. Here's...

    View full article →