Getting Started with the Tessel Microcontroller Board
This is the first article in a series chronicling my projects exploring the Internet of Things and working with microcontrollers. This page focuses on getting started with the Tessel microcontroller.
I've started building a simple weather station using a Tessel microcontroller and weather module. My initial motivation for this project came from an interest in using technology to improve my gardening efforts and an interest in learning to work with microcontrollers and electronics.
The Tessel
Tessel is a microcontroller board with built-in wifi and NodeJS. Its additional modules (temperature sensors, cameras, etc) are plug and play - no sodering required.
Getting the Tessel hooked up to wifi and reading the temperature from the weather module was easy. However, the temperature readings were roughly 10°F higher than what they should be. A quick examination of the Tessel forums showed the reason for this was the heat transfer from the Tessel unit and that to resolve this I should use jumper wires to distance the weather module from the Tessel.
Done. Now the Tessel reports temperature accurately:
Weather Reporter Code and HTTP Communication
I tried to get the Tessel reporting weather data over HTTP using a variety of Node packages which could have simplified the code I'd need to write. Node on the Tessel supports a subset of available packages at npm and I ran into compatibility issues with most of the packages I tried.
Ultimately I realized I needed to keep the code as basic as possible and just use the built-in http
library.
Here's the simple logic flow:
- request and store sensor temp in °F
- request and store sensor temp in °C
- request and store sensor relative humidity
- create and send weather report to database via http
- delay and repeat
Here is the initial Javascript:
I tested the initial code with success while having the Tessel plugged into my laptop but as soon as I put the Tessel outside untethered I quickly discovered the Tessel needed to be closer to the wifi router or it would have problems connecting. Time to rethink where I'll ultimately be mounting the Tessel outside so it doesn't struggle to maintain a connection. And as you can see in the code above, there is no code for handling wifi connection or issues.
The next problems I had were slightly more complex. After a few hours of reporting the Tessel would start to send more signals than I was expecting (1 per minute). At times I'd see as many as three extra reports per minute.
Eventually the Tessel would stop reporting - usually after 14-18 hours, sometimes sooner.
In addition to needing to handle wifi issues the code needed to store and properly clear timeouts. Rookie mistake. And kicking off initialization after the climate sensor ready event is probably not wise if the wifi connection hasn't been established.
After improving the code, there are no additional reports and the Tessel now will report for days uninterrupted.
I added a handler for request error events:
And a resetWifi()
function:
The timeout problem was resolved by storing the timeout as a variable and clearing it properly in the reset function:
With the code changes above, and a replacement power supply of higher quality, the Tessel is now running fairly smoothly. Unfortunately I do still see the Tessel stop reporting at times which I am still investigating. For now I'm collecting a ton of weather data and the fact that there are gaps is okay. I'm still getting plenty of data to play with and learn from.
The existing code is here. Or checkout the entire Github repository for this project.
Testing Locations
At this point things are running fairly smoothly - the code could probably use an improvement or two but the weather reports keep coming in reliably. During my testing I'd seen that without proper protection of the Tessel and attached weather sensor, the reported weather data in the mid-afternoon would be inaccurate thanks to direct sun on the hardware.
My initial hope for the final location was to hide the Tessel in an outdoor light fixture after removing the bulbs. Unfortunately the location was just outside the Tessel's comfort range for Wifi stability.
To resolve these two issues, heat and wifi stability, I stuck the unit in a clay pot in a reasonably protected corner of the porch, within the wifi comfort zone:
Bugs, Concerns and Moving Forward
With the Tessel reliably reporting data now, my current focus is on the database and the data visualizations. As the Tessel continues to report data, I will be paying attention to a variety of concerns:
The Tessel still seems to crap out after roughly a week of reporting data. Why?
How will the unit perform once the excessively humid and hot summer arrives?
Speaking of summer, how can I properly protect the unit from our crazy summer storms where rain will blow sideways? A screen over the top will keep birds out but how can I keep the Tessel safe without altering how the sensors report data?
Data and Visualizations
With the Tessel reporting data reliably, it's now time to focus on building a front-end for visualizing data and an API to handle data retrieval from MongoDB. Read about that next to see how this project progresses with a little NodeJS, MongoDB and Raspberry Pi.