This is the third post of this series. I’ll describe here:
- The software that I have developed for the Arduino Mega board
- The IoT platform I have used to store and visualize the data collected on the field.
It is worth remembering that most of the choices I have made have been driven by the limited amount of time available for this project.
Software running on Arduino Mega
Since I had never used Arduino before, I firstly had a look at some tutorials and examples on the Internet. As there are tons of such resources, and thanks to the fact that I am not a complete newbie at embedded systems, I have tried to find an example related to PowerOne Aurora inverter interfacing. I got lucky because I quickly found this example by Davide Rosa, that suits my needs. I would like to thank him for allowing me to use his class in my code. I have found this project very helpful because it has introduced me to the Thread library as well. I have immediately realized that the use of this library would have made the code more readable, maintainable, and modular. So I have decided to use it.
I have implemented three “threads” :
- This thread just blinks the built-in LED of Arduino Mega board in order to show that it is up and running
- This thread is responsible for managing the WiFi link connection
- This thread is the most important. It periodically reads humidity, temperature, grid power, and total cumulated energy, and it uploads such values to the cloud.
To access humidity/temperature sensor I have used the well-known DHTLib library. While debugging the code, I found a small bug that prevents the correct reading of data. I discussed this with DHTLib’s maintainer Rob Tillaart. At the end of the day, we agreed to replace this line in _readSensor method
delayMicroseconds(wakeupDelay * 1000UL);
with this code
if (wakeupDelay > 9) delay(wakeupDelay); else delayMicroseconds(wakeupDelay * 1000UL);
In regard to uploading data to Ubidots, there are several examples showing how to do this. For example, see this one. I have also found this page extremely useful in understanding how to properly format the strings for the HTTP requests.
The code is released under GPL v2 license. It is available for download here. There are some debug options that you can enable to increase the verbosity of the messages printed on the first serial port.
 I use quotation marks (aka inverted commas) because they are not real parallel tasks.
The IoT cloud platform
Nowadays, there are a lot of IoT platforms providing cloud services. Most of them offer basic free services as well. This article helped me quite a bit when it came to deciding which one to use. The same author published this series of posts that are also very useful:
Ubidots allows you to easily create data sources and to visualize collected data in customizable charts (called dashboards) that can be publicly accessible. Click on the links to view the dashboards I have created for my photovoltaic system:
- This chart combines the temperature and the grid power
- This chart shows the total cumulated energy produced by the system
- This one shows the temperature and the umidity.
Another interesting feature is the possibility to embed such charts—that are updated in real-time—in any HTML page. For example, the following code (generated automatically by Ubidots platform) allows you to embed the temperature/grid power dashboard.
<iframe width="430" height="280" frameborder="0" src="https://app.ubidots.com/ubi/getchart/T3towH_0XKfS0w5ChE5y1NTm2pI"></iframe>
Unfortunately, my hosting provider seems to filter out such frames, so this feature is not possible on this very page. The following image shows an example of one of the dashboards I have defined.
The Arduino ecosystem has proved itself to be very mature. There is a huge community providing a lot of free resources, such as examples and tutorials. To edit and build the code, I have used the Arduino IDE that, frankly speaking, is not very powerful. However, there are several other options available. In retrospect, I probably should have chosen a better IDE to speed up the coding/debugging cycle.
Ubidots is extremely easy to setup and configure. I struggled only slightly when formatting the strings that upload the data.
A final consideration: just some years ago, it would take man-months to make the same project. Generally speaking, the increase in personal productivity due to modern information technologies looks really impressive, especially to people like me who started playing with Electronics in the 20th century. The question is if we as human beings will be able to use such a power wisely.