A big thing that came out of the recent element14 Dreamboard competition was seeing that two features in high demand are expandability and onboard sensors. Particularly the runner up, the Mother H.E.N board, was loaded with light, temperature and humidity sensors along with the standard range of GPIO you would expect from a great single board computer. While none of the boards are in production (yet!), there is a great prototyping platform from Texas Instruments that is optimised for expandability and using a variety of sensors.
The Tiva C series Launchpad comes in two versions: a stand alone version and a network enabled version for developing various Internet of Things projects. A unique feature of the Launchpad line is the ability to expand functionality and I/O using a range of Boosterpacks. They are small daughterboards that snap onto the four lines of pins on a Launchpad. The range includes Wifi networking modules, small LCD screens and different types of sensors. For this project, I will be using the SensorHub Boosterpack .
At first look, you might notice something strange with the Launchpad - the board has two identical looking microUSB ports, the same kind you would using to charge a phone with. The Debug port is on the narrow top edge of the board. You'll use this the most, it is for loading programs and live debugging. On the left side is the Device USB port that is used for a great feature on the Tiva C, the ability to let the board simulate a USB device when connected to a PC.
The small switch in the corner is used to select what USB port the Launchpad gets its power from. This is useful, as it allows you to debug while running programs that use the device port without having to swap around the USB cable. If you power a Launchpad from a wall wart or cellphone charger, make sure it can provide a smooth and clean power. Some low cost chargers can have fluctuations in the power they can provide that could potentially damage the Launchpad.
Besides the I/O pins the Tiva C Launchpad has three tact switches for input. The one near the top of the unit is a dedicated restart button while the other two are fully user programmable.
Connecting any BoosterPack to a Launchpad is done just by sliding it onto the four rows of pins. They are designed to be stackable, on the Tiva C you can see that there are connectors on both the top and bottom of the board. Because there is a large amount of I/O available, you can stack multiple BoosterPacks on the top and bottom of a Launchpad to get the right combination of sensors and peripherals for your projects.
One of the most full featured BoosterPacks available, the Sensor Hub BoosterPack, adds five high fidelity sensors to the Launchpad platform along with two user definable buttons, a programmable LED and RF connectors. All of the sensors on the board can be used simultaneously.
The Five sensors on the board are:
- Infrared temperature sensor - TMP006
- Air pressure sensor - BMP180
- Light sensor - ISL29023
- Humidity sensor - SHT21
- 9-axis Motion sensor (Combining an accelerometer, gyroscope and magnetometer) - MPU9250
Before you can begin programming the Launchpad you'll need the drivers installed. The best way to get these installed is by downloading TivaWare. This also contains a suite of software, examples and tools to help with developing on a Tiva C series Launchpad and its various BoosterPacks. You'll need to install multiple drivers for things like the In-Circuit Debug Interface and for the Virtual COM port to enable terminal access to the Launchpad through a Windows program like Putty.
Tip - The virtual COM port number your Launchpad gets assigned will be different depending on how your PC is configured. To find out what number it has been assigned, open Device Manager and look under Ports for something named 'VirtualSerialPort'. If you've just installed the drivers the Launchpad will most likely be the device with the highest COM port number.
While many options are available, there are two main programming environments most hobbyists would use for the Tiva C Launchpad - Energia and Code Composer Studio. Both are free to use and are fully functional without trial periods or other restrictions.
Energia is an adaption of the Arduino development environment for the Launchpad range (Named after a Russian word for 'Energy' and the name of rocket from the 1980's). It is very simple to use, especially for anyone familiar with coding for Arduino. The interface is basic, it comes with coding examples for every model of Launchpad and is easy to configure. Once installed it's just a matter of selecting what Launchpad board you're using from the Tools menu.
Code Composer Studio, often shortened to CCS, is the official IDE made by Texas Instruments for all their microcontroller components. It does require that a Launchpad be plugged into the PC in order to compile and debug programs, lacking a software emulator by default. Code Composer Studio is much more in depth than Energia, being a fully fledged professional coding studio. It can seem daunting, but does have a simple mode that hides any advanced features that a simple hobbyist probably wouldn't use. If you get stuck, try the Getting Started feature to guide you through and help by importing some examples you can play with. While the whole studio is entirely free for personal use, downloading it does require signing up for a MyTI account.
If you want to load one of the example programs that TivaWare provides without installing Code Composer Studio you can flash them directly using LM Flash Programmer. Just select your Launchpad model in the configuration tab and load the .bin file from the directory of your PC where TivaWare was installed. The directory where the example files are located is a little long - /examples/boards/"boardname"/"example"/ccs/Debug/ - where "boardname" is the model name of your Launchpad including the name of the BoosterPack you're using and "example" is the name of the program you want to run.
A great example program using the motion sensor is the airmouse. It makes the Launchpad combined with the Sensor Hub BoosterPack function as a USB mouse that works in a 3D space without lasers, optics or balls. While it might not be the most ergonomic form for a mouse, it really demonstrates the fidelity of the motion sensor. Tilting forward, back, left and right controls the mouse cursor and the buttons on the Launchpad are used for left and right clicking. For a real challenge try playing Call of Duty or another first person shooter game. After a step learning curve I started to get good!
For my project using the Launchpad, I opted to use Energia to code it. Libraries for everything on the Sensor Hub Boosterpack aren't available by default, but the TMP006 temperature sensor libraries are pre installed courtesy of Adafruit. The project is a simple temperature alarm, involving connecting a buzzer to the Launchpad and sounding it when a certain temperature is reached. Because I have an old mechanical gas heating in my house, if I fall asleep late at night with the heating set to maximum I sometimes wake up hours later sweating from the heat. This alarm will ensure that I'll be notified before the room temperature gets out of control. I also set up one of the buttons on the Launchpad to disable the alarm for 20 minutes so it wasn't constantly sounding while waiting for the temperature to lower.
I used male-female jumper wires connected to the sockets on the bottom of the Launchpad to attach a cheap piezo buzzer . When doing this, be sure to look up the documentation for any BoosterPacks you are using to make sure you don't have any pin conflicts. After researching I opted to use pin 40 to power the buzzer and pin 20 for ground, following the Energia pin numbering schematic.
The Launchpad is primarily for development and prototyping, but to give it a bit of protection while using it in a more permanent project like this I wanted a case. I made a initial mock up out of paper to get the measurements correct before using thick stock card for the final.
Lightly scoring the back of the card where the folds are gives a cleaner finish. Because the microUSB ports on the Launchpad extend out slightly from the edge of the board they are able to help hold it in place. Given the BoosterPack has light and temperature sensors, putting a top onto the case isn't a practical idea. Using a hard setting glue to adhere the tabs in place gives the structure more rigidity. I bent the pins on the jumper cables for the buzzer to a right angle, connected them to the bottom of the board then looped them around. The buzzer was mounted to the front of the case between the reset button and debug USB port on the Launchpad.
This is the code used for the temperature alarm
#include <Wire.h> #include "Adafruit_TMP006.h" const int buttonPin = PUSH2; int buttonState = 0; Adafruit_TMP006 tmp006(0x41); void setup() { pinMode(buttonPin, INPUT_PULLUP); tmp006.begin(); } void loop() { buttonState = digitalRead(buttonPin); if (buttonState == LOW) { delay(1200000); } float objt = tmp006.readObjTempC(); if (objt > 23) { tone(40,10); } delay(4000); noTone(40); }
- Lines 1 and 2 import the libraries the project uses
- Lines 3 and 4 creates variables for the button use
- Line 5 sets up the temperature sensors address
- Lines 6 - 9 is the setup loop, getting the Launchpads button ready to listen for presses and starting the temperature sensor
- Lines 11 - 13 detects if the button is pressed, then pauses for 20 seconds if it is
- Line 15 reads the current temperature from the sensor
- Line 16 checks if the current temperature is over 23 degrees Celsius
- Line 17 sounds the buzzer connected to pin 40 on the Launchpad at a frequency of 10hz
- Line 19 pauses for 4 seconds before testing the temperature again
- Line 20 stops the buzzer at the end of the loop.
23 degrees may be uncomfortably warm for me, but if you want to run colder or warmer just change the number on line 16. Setting the buzzer to 10hz gives a beeping sound rather than a constant buzz. Putting at around 100 will make it sound like fly buzzing around if that is what you prefer.
Installing libraries for the other sensors on the BoosterPack is simple. When you installed Energia it made a new folder under Documents in Windows. Just copy the Energia library folder you want to install into the /Energia/libraries/ directory inside.
The light sensor has a suitable library available on Github, and it includes examples. Using this I transformed the project from a heat sensor into somewhat of a 'Lazy Alarm'. It works by sounding the buzzer not at a certain time but when it detects a given level of light. This means if its a grey and overcast day it will let you sleep in, but if it's a glorious sunny day it sounds the alarm to make sure you don't miss a minute in the sun!
#include <isl29023.h> #include <Wire.h> ISL29023 isl = ISL29023(); const int buttonPin = PUSH2; int buttonState = 0; void setup() { pinMode(buttonPin, INPUT_PULLUP); isl.init(); Wire.begin(); } void loop() { buttonState = digitalRead(buttonPin); if (buttonState == LOW) { delay(1200000); } float objt = isl.read(); if (objt > 100) { tone(40,10); } delay(4000); noTone(40); }
To change the level of light that the alarm sounds at adjust the value on line 17.
The Tiva C Launchpad combined with the Sensor Hub BoosterPack makes a great platform for testing out things for projects using temperature, light or many other sensors. If you have any ideas of projects you're interested in making using different types of sensors, share them in the comments below. If you have any questions you can comment below or hit me up on Twitter - @aaronights.