Electric Garden: My First IoT Device

By
Kate Loguteva
October 24, 2019


Probably you know that our boss Victoria supports many digital initiatives across New Zealand. One day she has shared with us one of the latest Digital Future Aotearoa initiative called Electric Garden. This is an Internet of Things solution for garden monitoring which teachers can use to deliver digital technologies education to children.

For some reason I was flabbergasted with the elegance of the solution. I have heard an IoT buzz, but I had never thought that it could be so easy that even kids can make something. It doesn’t mean I thought it would be too hard for me; it had never appeared to me that I can also try my hands at electronics. I have decided to give it a go immediately.

My project

I’m not at school anymore, so I couldn’t get that kit for my own, but that’s even better as I needed something more challenging to start with. So, I went to… my partner, because that’s his hobby. He was astounded. For eleven years we have known each other I was barely listening when he told me about yet another amplifier or FPGA circuit he had designed and made from the parts himself; now I wanted to understand. He had planned a challenge for me, designed a circuit on a high level and provided with all the required parts; so, it was kind of a kit I got, but it was a real challenge, harder than assembling Ikea furniture. My soil moisture sensor should wake up every 30 minutes, do the measurement and send the result to the Internet service.

The parts I was given were:

  • Microcontroller MSP430 – the sensor’s “brains”
  • Wi-fi chip ESP8266 – the sensor’s antennae
  • Texas Instruments LaunchPad development kit for programming the microcontroller
  • Extra parts, like the diode, resistors, battery
  • FTDI USB to serial chip for debugging the code
  • All the stuff required for soldering: protoboard, wires, solder and soldering iron

Later I learned that this is the hardest way to get into the electronics. There are so many simple kits to start from, like Arduino. Anyway, I have learned a lot about electronics from the very start.

I was good at physics at school, but forgot a lot since then. I had to refresh my memories about Ohm’s law and Kirchhoff’s laws for example. That’s because in the circuit you have to worry about the voltage. I have used a typical rechargeable 3.7V Li-Ion battery, which actually produce a bit more voltage when fully charged, and this can fry the microcontroller if connected straight to it; I’ve learned how to use diode to fix this.

All parts are soldered, the device is ready for assembling

The part I enjoyed the most was the programming. After I got the values from the sensor, I needed to form an HTTP request to be sent to the Internet. I have used the Adafruit IO service to collect data from the sensor. It has very simple API and dashboard, it stores the data for 30 days for free.

I have used MSP430 GCC compiler, Gnome Builder IDE and C programming language. I’d never written a line in C before, but as this is the grandmother of most of the modern programming languages, I was able to get straight to code without learning the syntax first. Also, it doesn’t require to write everything from scratch, I have combined my code from the examples I found on the internet. TI provides good documentation and libraries.

Unlike all the programming I’d done before, this project required enormous patience to troubleshoot. Some obstacles I have faced were so unexplainable that I was about to give up many times.

You have to worry about memory, the MSP430 controllers have tiny amount of RAM. It is not helping if you need to form a lengthy HTTP request string.

Although most of the code examples are available in the internet, due to the differences between microcontroller’s families, they don’t always work as expected on yours.

I have added the second data feed to read the battery charge level to know when it is getting low before it just stops working.

Here is an example of code:

[code]#include "msp430g2553.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"

unsigned int measure_supply_voltage()
{
   ADC10CTL1 = INCH_11 | SHS_0 | ADC10DIV_0 | ADC10SSEL_0;
   ADC10CTL0 = SREF_1 | REFON |  REF2_5V | ADC10SHT_3 | ADC10SR | ADC10ON;

   ADC10CTL0 &= ~(ENC);
   while (ADC10CTL1 & ADC10BUSY);

   ADC10DTC1 = 0;
   ADC10SA = 0;

   ADC10CTL0 |= ENC | ADC10SC;
   while (ADC10CTL1 & ADC10BUSY);

   ADC10CTL0 &= ~ENC;
   ADC10CTL0 &= ~(ADC10IFG | ADC10ON | REFON);

   unsigned int value = ADC10MEM;

   ADC10CTL0 = 0;
   ADC10CTL1 = 0;
   unsigned long l = value;
   return (l * 5000l / 1024l);
}
[/code]

Here I should be good and mention one very important thing – security.  The lack of security makes IoT to be criticised a lot. Many devices get exposed to the global network are vulnerable to hacking. In my case I could only hope that my low-power device that switches on from time to time just for one operation is secured by design. But I would definitely need to research how I can secure my next project from unauthorised access.

How valuable is this skill?

It probably doesn’t give me much except for dropping my new hobby casually in the conversation to amaze the interlocutor. I am definitely not ready for the new turn in my career.

My favourite example of IoT device success story is Fitbit. The Fitbit’s founders were looking for investors while having their device in the stage of a circuit in a balsa box. They haven’t invented activity tracker, but they were first to combine it with a web-based service: right offer at right time. They have made a fortune since then. Otherwise, there are many cool projects on Kickstarter, but very few of them end up on the production line or got known at all.

However, what’s really cool about the Electric Garden is combining IT with “real life”. I struggle with this concept in my mind, but youngsters who have interacted with the Electric Garden early enough won’t have this divergence; for them IT would be just a mean of improvement their everyday tasks. The Arduino and 3D-printing allow infinite possibilities to make almost any device. I was choosing whether I wanted to be a lawyer or a veterinarian and at the end I chose IT as my career. It would be so cool when someone without a degree in information technology would be able to identify how IT can help their daily tasks or even prototype a device themselves.

Kate
Data masseuse

Image of Kate Loguteva with the OptimalBI logo in the background.

Kate writes technical blogs about data warehouses, and is a Data Vault convert who works mostly with MS SQL Server.

You can connect with Kate on LinkedIn, or read her other blogs here.

Copyright © 2019 OptimalBI LTD.