I had written about my weatherstation, why I use Xbee rather than WiFi and and a few posts about sensors and placement. The last remaining topic is to talk about receiving / displaying the data and sending it to the internet.
This receiver / basestation / coordinator has been the ugliest component of the build, likely because I wanted it to do too much. It is supposed to be an actual weatherstation with interactive display, a clock and my central hub for my XBee network. While it has been a useful exercise in learning how to program wildly different requirements it quickly exceeded what an Arduino Uno can do. I had to move to an Arduino Mega (knockoff from Aliexpress, by the way, works great) which in turn meant that the Sparkfun WiFi shield doesn’t work anymore.
The entire assembly is an unholy mess of wires and connectors.
- Top right: Standard LCD Display with shield allowing me to communicate with I2C (about that later)
- Left: Arduino Mega, Aliexpress knockoff. This is the Coordinator
- Middle: breadboard with XBee (in coordinator mode), real time clock (top) and a TMP36 analog temperature sensor.
- Bottom: Arduino Uno with a WiFi Shield connected by I2C to the Coordinator Arduino. I added an external antenna to the shield(black lead left side of image)
How it works
The Xbee Weatherstation sends data every 30 seconds from its position on the roof. The Coordinator receives the data, displays it on the LCD shield and sends it via I2C to the connected Arduino Uno. The Uno is connected via its WiFi shield to ThingSpeak and sends it the data as it comes in. The Thingspeak data is embedded into this blog.
The code is here: Mega (Coordinator) and WiFi Conector (Uno) and most of it is pretty straight forward but inelegant. Especially the coordinator “grew” in scope over time but it has been pretty stable, so I left it. The Arduino Mega still has plenty of memory and ports left so there is no real reason to tighten the design =re-write). If it ain’t broke and all that. The LCD shield has shown to be very limiting. I wanted to show the time derived from real time clock as well as the current weather conditions with in/outdoor temperature, outdoor humidity, wind speed, wind direction, gusts rain rate, I just had too many numbers to display at any time. I personally can not stand displays that automatically scroll through values and hence I enabled the buttons on the shield to switch between the states. Up Button now shows the outdoor temperature and humidity. Right Button the indoor temperature of the TMP36 (which by the way is frequently reporting -100 C data, likely bad connection). Button Down is Barometric pressure, Button Left is Wind Speed, gusts and directions in degrees (need to make lookup table for actual compass rose values). The “Select Button” switches the display to Rain Rate.
The Mega uses I2C to communicate with the LCD shield as well as the Real Time Clock and hence has to serve as master for the devices. I2C is a pretty elegant protocol as it enables communication with only two wires (and ground) but I found it hard to learn until I found the I2CAnything library from Nick Gammon (thank you!). I have to send float values across the I2C bus and doing this without the library exceeded my programming skills. I2C also allowed me a pretty straight forward connection to the Arduino Uno whose sole purpose is to drive the WiFi shield. The Uno is in “slave mode” and waits for data to be sent to it, the sends it to my Thingspeak channel.
Aside from being badly soldered (LCD shield), being a mess on a breadboard (everything else), expensive (2 arduinos,1 WiFi shield) and using a TMP36 which gives me issues its working perfectly!
To clean up, I bought an Adafruit Huzzahh ESP8266 breakout board, the promise is / was that it is a fully-fledged Arduino with integrated WiFi, it just has fewer ports. The goal was to connect it to the Mega and scrap the Uno / WiFi shield to make the entire package cheaper and more transportable. Turns out the ESP8266 is well documented and can be used as a I2C master but does not currently work as a slave. This is a problem since I can not see myself re-writing the entire code for the Mega and allow the ESP8266 as a Master. Apparently, there are tricks to use systems with 2 masters but this is getting unwieldy. I could send the data by serial port (the Mega of course has many serial ports left) but as stated above, reliably sending floats is something I yet have to learn.
For now, I decided to live with the system but pack it into a more self contained box, use actual boards and soldered connections rather than the breadboard and stick it into a box that hides the mess. I will also need to clean up some code (wind direction as actual compass directions for example and find a system to set the clock manually, I didn’t appreciate just how much the RTC drifts over time). After that, I will focus on other projects and eventually move the entire coordinator / display into a PC (I have an old Linux laptop somewhere) and was itching to learn how to use “Processing” anyway).