I really love the Thingy* devices from Nordic Semiconductor. They are prototyping platforms with a bunch of sensors baked right in, plus a battery. I have been able to prototype entire use cases for clients in my former life as a hardware consultant. The Thingy91 is the cellular version that includes the nRF9160 SIP, a Cat-M1 and NB-IOT capable modem + microcontroller. Tons of great sensors on board too, like the BME680 from Bosch for weather/gas sensing, the Rohm Semiconductor BH1749 for light and color detection, and the Analog Devices ADXL362 accelerometer for sensing orientation and movement/fall detection.
The starter images from Nordic are great, especially the Asset Tracker V2, which comes preloaded on the Thingy91. This is a super intricate demo that allows you to create an asset tracker using this off the shelf device. FYI, it’s not a super discrete as an asset tracker, as it has a bright orange case…you won’t be using this for spycraft anytime soon!
Ready for your second demo?
Once you want to move outside of that first demo, it’s normally up to the user to start piecing together samples from the
nrf folders contained within the nRF Connect SDK. I have done that a few times, but I wanted to have another “all-in-one” demo akin to the Asset Tracker V2, but one that mostly takes advantage of the sensors and other fun stuff on board. What else can we do with this thing(y)?
My favorite unused feature
After I peeked at the schematic, I noticed a buzzer on board. But none of the samples I could find took advantage of the piezoelectric transducer (aka buzzer), on board the Thingy91. It’s a pretty generic component directly driven by PWM, so I figured someone must have made it into a tiny musical device…right? It turns out that no, no one had yet. So there’s my first task!
With the help of my coworker Mike, we were able to create a framework for inputting songs into the code so we could easily translate from sheet music to a series of beeps that approximates songs. Check out the demo video below to see it in action
Hooking it all up to a data platform
All of this sensor data and fun music making is great, but what should we do with it? We decided to use our Golioth SDK (which works in conjunction with the Nordic nRF Connect SDK) to make it easy to push and pull data from this cellular device in the field. The demo and code shown below outlines how we structured the program to interact with various services that Golioth provides. This is also covered in a blog post.
Collecting Sensor data
This is the most obvious one for the Thingy91, since it has so many great sensors on board. All of the sensors are in the Zephyr DeviceTree, so that means we only need to enable them in the code in order to take advantage of the data coming off of them. We are able to extract the data from the sensor during our sensor reading loop on the device and then format that data to be sent to the cloud:
This uses Golioth’s LightDB Stream service, which is a timeseries database. Once you push data to LightDB Stream, it shows up on the Cloud as a formatted number that you can display on the Golioth Console or query over the REST API from a visualization platform.
Controlling functions on the device
We have all these songs on the device now, how do we trigger them to go off? Remote Procedure Calls allow a user to send a command from the cloud down to a specific device and tell it to run a function on the device. In this case, we’re telling it to play a song, but we can also pass which song we want it to play.
The LEDs on the Thingy91 are critical way to interact with the device because there is no screen and no standard output for the user holding the device to understand what’s happening inside. So we use LEDs! This is a key feature of the Asset Tracker V2. What if I want to specifically control the LEDs though? The Golioth Settings service allows you to set arbitrary variables on the cloud and push them out to devices in the field. In this case, we’re setting the red, green, and blue color intensities, as well as the speed the LEDs are fading. The LED fades are happening inside a thread, which Zephyr does great as it is a Real Time Operating System.
Try out the binary
There are lots of other things we could do, but why not just try it out for yourself? We not only wrote and released the code shown in the video below, but we also created a binary so you can try these functions on your Thingy91 without needing to write any code at all. Much like the Asset Tracker V2, we think this gives you the opportunity to understand what the Thingy91 can do, while also trying out a device management platform like Golioth. Watch it in action in the video below.