This tutorial uses the Thunderboard Sense 2 connecting to a Raspberry Pi 3 over Bluetooth to send your sensor data to the cloud over Ethernet or WiFi.
In this Quick Start Guide, you will:
- Set up your Raspberry Pi
- Create a Medium One account
- Set up your Thunderboard
- Link your accounts together
- Set up your dashboard
- Create a workflow
Here’s what you need to get started:
- Medium One Prototyping Sandbox Account + Silicon Labs Thunderboard Sense 2 + Raspberry Pi 3 [Buy Kit]
- Micro SD card
- HDMI Cable
- USB Keyboard and mouse
Step 1: Setting up your Raspberry Pi 3
Now that you have your Raspberry Pi 3, you will need to follow a few steps before you can use it. You will need to:
- Set up your SD card with the Raspberry Pi Operating System
- Set up your environment
- Set up the Pi to automatically connect to the Thunderboard when it turns on
1. Setting up your SD card
Download and install the Raspbian Stretch with Desktop on your SD card. Instructions for this can be found on the link below. Skip to “Download and image Raspbian directly,” about halfway down the page. If you do not have a built in mini SD card reader on your computer, you can use an external one.
2. Setting up your environment
Put the SD card in your Raspberry Pi.
Plug an Ethernet cable and HDMI cord into your Pi.
Plug in a USB keyboard and mouse.
Turn on the Raspberry Pi by plugging in a USB Mini and connecting it to a power source.
Wait and watch on your monitor until the Raspberry Pi has completed turning on. You should see a screen like this. If the screen is black, make sure the SD card is plugged in correctly, then unplug it then plug it back in. If it is still black or it does not load correctly, a problem may have occurred during installation- try the Setting Up Your SD Card step again.
3. Setting up the Pi to automatically connect to Thunderboard
Next, open a web browser by clicking on the blue orb in the upper lefthand corner. We are going to download some files to prepare to connect to the Thunderboard later. Visit this link and see the following files:
Move these 5 files to /home/pi.
Click “Clone or Download” in green.
Click “Download as ZIP” in the dropdown
The file should save and show up on the bottom of the browser. Click on it.
A dialog box should open. Click Action→ Extract.
Click on the folder button to change where it is saved. It is very important to follow these steps to extract the script in the right folder! The script to set up the Raspberry Pi expects all the files to be here, and it will not run if they are not here.
Click on “Pi” on the side.
Click on “Open.”
Uncheck the box “Extract with full path.”
Click extract. Now that you have downloaded all 5 files in the correct directory, click on the black box in the upper left hand corner to open the command line. You can close the web browser and unarchiever.
Type “sudo sh setup.sh,” then hit enter.
After about 40 seconds, you will see a message that says “Are you sure you would like to install? Y/N” in the command line. Type Y.
Wait another minute for the script to complete.
Congrats, you have set up your Raspberry Pi. You will need to come back to the command line later to configure it with information from your Medium One account and Thunderboard.
Step 2: Setting up a Medium One Account
In this step, you will do the following:
- Create a new Medium One account, if you do not already have one
- Create a Medium One project on your Medium One account
- Create a user for your Thunderboard
- Find our API key
- Create two datastreams
Later on, you will log back in and make sure data is coming in, set up your dashboard, and create a workflow.
During this step, you will get some information from your Medium One account that you will need to use later when configuring your Raspberry Pi. This information is:
- API Key
Write these down because you will need them later.
1. Create a new Medium One account
Note: This step is if you do not have a Medium One account.
Navigate to https://www.medium.one/. On the upper right hand corner, click “Sign Up.”
Enter your information, then click “Create Account.”
Check your email. You should get two emails, one that says Welcome to Medium One with a temporary password, and one that says that you have been added to a project.
Navigate to https://app-sandbox.mediumone.com/login. Log in with your email and the temporary password provided. You can set a new password by clicking “My Account” underneath the “Setup” tab on the left hand side.
2. Create a new Medium One Project
Note: This step is if you already have a Medium One account.
Log into your Medium One account. On the upper right hand corner, click on the name of your last project. Then, click “Create New Project.”
A box will pop up prompting you to put in a new Project Name. Enter this, then hit “Activate.”
3. Create a user for your Thunderboard.
On the left hand side, click on “Setup.” Then, click on “Manage Users.”
Click “Add New User”
In the first box, put what you want the name of your device to be. This is the username, and you will need to save it for later. Enter a password in the next two boxes. You will need to save this as well.
4. Find your API key
Under “Setup,” click on “Manage API Keys.”
Click “Add New API key”
Enter any description you want, make sure “Enabled” stays checked, and click “Save.” You will be redirected to the next page. The long string outlined in RED is your API key: save this for later.
5. Create datastreams
You will now create datastreams for the Thunderboard to send data from. On the left hand side, click Config→ Data Streams.
Click “Create a new stream.”
For the name, type “sensor_data.” Click “Save Data Stream.”
Once again, click “Create a new stream.”
For the name, type “device_data.” Click “Save.”
You should see both your streams now.
Step 3: Setting up your Thunderboard Sense 2
In this step, we will use the Raspberry Pi to find the device address of your Thunderboard. You will need to save this information for the next step, to tell the Raspberry Pi how to find your Thunderboard.
Open the Command Line on your Raspberry Pi. Type “sudo python scan.py”
Unbox and power on your Thunderboard. If you previously connected it to your phone via the mobile app, make sure bluetooth is off on your phone so it does not automatically connect.
Now that it is turned on, look back at the command prompt of your Raspberry Pi. This script scans and looks for any Thunderboards nearby, and prints their address. You should see something like the following on your screen after a couple seconds.
If nothing shows up, try turning your Thunderboard off then back on.
The sequence of letters, numbers, and colons in the red box after the word “addr” is your device address. Save it for the next step. You can end the script by typing “CTRL-C,” or just closing the terminal.
Step 4: Linking your Raspberry Pi Thunderboard to Medium One
Now, we will put everything together. Open the command line on your Raspberry Pi and type “sudo nano /m1/login.txt.”
This opens a text editor you will use to put your login info. You should see the following on the screen.
Type in, on four separate lines:
- Line 1: Username
- Line 2: Password
- Line 3: API key
- Line 4: Device Address
When you are done, press CTRL-X to save. You will get prompted to overwrite or not. Type Y.
It will prompt you where to save it. Hit Enter.
Reset the board. Congratulations, you have linked everything together
Step 5: Set up your dashboard
You will now make sure everything is hooked together. First, restart the Raspberry Pi by turning it off then back on. Wait about 1-2 minutes or, if you are still connected to the monitor, when it has completely turned on and is on the desktop.
Log into your Medium One account. At the bottom of the screen, in the widgets, find “Real Time Events Stream.”
In the drop down box, find the username you picked earlier.
Now, plug in your Thunderboard. After a few moments, it should start blinking a red light. On Medium One, you should see data starting to come in!
This widget is called the “Real Time Events Stream.” Each of the lines above, beginning with the date in blue on the left, is a piece of data coming in from the Thunderboard. You can see in the text, sensor readings like pressure, temperature, and humidity. You can also see x_max, y_max, and z_max, which are the maximum vibration in the x, y, and z directions since data was last sent.
Now, scroll down and click on “Real Time Line Chart.”
Select your username from the dropdown. Then, click on the gear.
Select “sensor_data.x_max,” “sensor_data.y_max,” and “sensor_data.z_max.”
The Real Time Line Chart widget shows you the maximum values of the vibration in the x, y, and z directions over time. You will use this widget later on to see how motion sends out an alert.
Scroll down and click on “Real Time Gauge.”
Select your user, then click on the gear.
Select “sensor_data.co2”, “sensor_data.temperature”, “sensor_data.pressure”, and “sensor_data.humidity.”
The Real Time Gauges show you readings from the different sensors on the Thunderboard. The values will change on these gauges as new data comes in.
Scroll down and click on Last Value table.
Select your user. Then, click on the gear.
Select “device_data.ip_address,” “device_data.lan_ip_address,” “device_data.mac_address,” and “sensor_data.battery.”
The Last Value Table shows the last value for key information such as IP addresses, device address and battery. The values will change in real time as new values are sent.
Very important: Scroll up to the top and click “Save.” Otherwise, you’ll need to do this every time you log in!
Step 6: Building a workflow
In this step, you’re going to create a workflow. Workflows are python applications that run as data comes in. This particular workflow checks to see if the Thunderboard has moved based on the G-Force. If the board has moved, it sends an email and text message alert. It limits the number of alerts to be sent to one per day. We’re going to modify the workflow to send the alerts to your phone number and email address.
Click on “Workflow Studio.”
Click on “Create”
Where it says Enter Workflow Name, type “Alert on Vibration.”
We are going to first connect the pieces of the workflow, then edit the python code. On the righthand side, click where it says “Tags and Triggers.”
Click on “Sensor Data.” See the tags representing your sensor data drop down.
Click and drag “x_max” onto the blank canvas. A green box should appear.
Repeat this with y_max, then z_max. It should look like this.
Now, click on “Modules.”
Click on “Foundation.”
Click and drag “Base Python” onto the screen. Your workflow should look like this.
Double click on “Base Python.” A box should come up.
Click on “Inputs/Outputs.”
Click “Add input” twice. It should look like this. Click “Save.”
There should now be three white circles on the top of the blue box, labeled “in1,” “in2,” and “in3.” Drag the white circle under the green box that says sensor_data.x_max to “in1.”
Drag the white circle under the green box that says sensor_data.y_max to “in2.”
Drag the white circle under the green box that says sensor_data.z_max to “in3.”
Now we are going to add the python code. Double click on the blue box, and delete everything in the text area so it is empty.
Copy and paste the following python code from here:
On line 10, replace the phone number with your phone number, excluding country code. Make sure to keep it in the quotation marks. On line 11, replace the email with your email address. Make sure to keep it in the quotation marks.
Click “Save and Activate.”
Test Your Alerts
- Make sure your Thunderboard is still blinking a red light. If not, press the reset button.
- Go back to the dashboard on the Medium One Sandbox by clicking on Dashboard icon in left menu. Find the “Real Time Line Chart”. Here, you can see the changes in vibration on the thunderboard.
- Shake the Thunderboard board back and forth for about 10 seconds. The Real Time Line Chart should jump, and you should receive a text message and an email.
Step 7: Now what?
Congratulations! You have connected your bluetooth Thunderboard Sense 2 device to the cloud using Ethernet over a Raspberry Pi 3. Here are some further tutorials to show you what else you can do using the Medium One Sandbox:
- Another fun project you can do with a Raspberry Pi. How about building a Home Weather Station. Check out this tutorial: https://blog.mediumone.com/2017/08/home-weather-station-using-raspberry-pi-and-sense-hat/
- More cool stuff for you to try out such as using Alexa’s voice-controlled speaker to tell your sensor system what to do! That and much more here on our Blog Site: https://blog.mediumone.com/
- Last but not least, everything you wanted to know about the Medium One system can be found here. Documentation: http://docs.mediumone.com/
Step 8: Configuring WiFi on your RPI
Your Raspberry Pi is able to connect to WiFi, but you will need to configure the SSID and password. You will need a USB mouse, keyboard, as well as a monitor with an HDMI cable.
Plug the monitor, keyboard, and mouse into the Raspberry Pi. Power it on after they are plugged in and the monitor is on.
After about 30 seconds, you will see the desktop. Click on the WiFi button in the upper right hand corner.
Find the WiFi network you want to connect to and click it. Type the password in the pop up box.
Your Raspberry Pi will now automatically connect to this network when it turns on!
Important Note: Boot up Sequence
The Thunderboard 2 will try and find a device to pair with for about twenty seconds, and then it goes into sleep mode. You can tell if the Thunderboard 2 looking to pair because a green light on it blinks. Because of this short pairing window, it is important to turn on the Raspberry Pi first, then turn on the Thunderboard 2. That way, the Raspberry Pi will pair with the Thunderboard 2 right when it turns on. If the Thunderboard 2 is not blinking a green light indicating it is searching, or a red light indicating it is connected to the Raspberry Pi and the cloud, then you should power it off then back on.