So this project is basically a hardware and software project. I am designing a microcontroller project which will monitor a garden (soil moisture content etc) and trigger sprinklers when required. It will log the sensor data and upload it to a website. An advanced step may be converting this data into graphs on the server end. This project requires getting to know the ESP8266 wifi chip and the TI Stellaris LM4F120.. Both of which aren’t quite as well documented as the ubiquitous Arduino platform…

It alarms me that the ESP8266 guys aren’t hosting firmware… If there was a malicious firmware that got loose, like is just BEGGING to happen at the moment (all these google drive linked binaries), it could surely harm their reputation, something like FTDIgate.. I guess there’s the SDK?

Stellaris

So, I’m learning the ARM toolchain, as much as getting code running on a Rpi would probably be easier, I’ve got a bunch of Stellaris boards I got for like $6 each delivered. I did even find an Arduino IDE (energia) ported to them which I used to begin making a rfid alarm system in 2014. So basically I’m programming a Stellaris (with all the evident horsepower that it contains) to receive IO from light, batt voltage, 3x moisture, humidity and temperature sensors and output to a 12v solenoid (as well as have an LCD display with 4 buttons). It will snapshot these sensors every 10 mins (from hibernation) into an array to be forwarded to a remote php server on AWS. It will store all the latest snapshots every 10 mins in flash and do an update every 30 mins using a serial connection to an ESP8266.

The ESP8266 will be running stock firmware in order to operate through AT commands. So the Stellaris may as well have a library corresponding to the AT commands on the ESP8266 with which it can do php post messages to the AWS SQL database. During the 30 min update, the Stellaris will also check if a schedule counter variable (a2) has increased, if so the Stellaris will pull down the schedule array (4 variables), which basically sets the timer for the sprinkler solenoid (if moisture < a (value) at b (time), run sprinkler for c mins, and d, an end date for the schedule entry).

The Stellaris will keep the last 24 hours of measurements and average them (not deleting entries till flash is full, yeah right).

Once a successful wifi connection is established the Stellaris will pull time and date from a time server (at GMT +9:30), and set all previous unknown sensor reading times.

When triggered by a button press, the LCD display will show date, time, batt voltage, errors (no sensor reading, moisture after solenoid increase fail, wifi not updated since). Left, right, up down buttons will navigate LCD menu, with arrows on the screen showing options.

LCD menu map:

SQL

SQL will be running on a remote server that the IOT Garden can update

20 Sep 2015

I've been looking into the ESP8266 and options for firmware... there are a bunch of options which I don't fully understand. So here I've found a link to the ESP8266 firmware flasher, and here I've found a firmware which allows deepsleep to be set through a serial command. While this modified firmware does look nice (er than the stock whatever-ware), I cant really be bothered going through the source to understand it... who knows what kind of bugs it has... I may be able to simply use the stock firmware and AT commands to connect to the interwebs.. doesn't really look like this firmware makes TCP connections much easier anyway. In that case I could for eg use a transistor to power the ESP only when required to save battery...
I have found that the ESP will remember wifi settings after being powered back on, this is nice, although it will renew its DHCP lease.

I've downloaded the Arduino IDE code programmer and had a look at the ESP8266 example sketches.. looks like things like pulling the current time from a NTP server require about 80 lines of code... fun :⁄
So I guess I'll be working out how to interact with the web from the Stellaris using AT commands.. will be interesting using functions to do stuff like set time from a NTP server...

23 Sep 2015

So by following the link given by TI (on the PCB, on the box and the quick start guide), I got lead straight to something that actually makes sense about the TI Launchpad, explaining the different software development tools. I’m back to using the Energia IDE and have been looking through the included libraries.. some interesting stuff.. a UDP library, IP address library.. so these should prove useful for sure. Basically all I’ve done is download and extract Energia, changed the sketchbook folder and installed the ICDI usb drivers for the Stellaris.

I’ve successfully uploaded code to a board (yay) and am currently looking into an RTC library and using the hibernate function.. progress

24 Sep

Working with RTC lib I found. Got an understanding of its basic use through serial monitor examples, except that the RTC doesn't increment... Luckily the developer seems very responsive :)

I've more or less connected the ESP8266 to the Serial line of the LM4F, I'll duplicate the serial, so I can use the LM4F serial console to pass messages. Then I can look into a TCP library, and an ESP8266 library to handle AT commands better or something. This will be the bulk of the work for now

I need to figure out the hibernation function, getting hibernation to work, also for the ESP (possibly hard shutdown with a transistor), in both timer and GPIO interrupt mode.

Been trying unsuccessfully to get this RTC code to work. Possibly I can try one of the Tiva C series boards which I also have which may support 'Calendar Mode' for outputting RTC in readable format

I can get the SPI 2 line LCD connected.maybe this

Need to learn how to write to flash.

27 Sep

Got RTC working with the initial RTC library I found! Maybe I modified the eg sketch n stopped it from working?

29 Sep

Good day, got NTP pulled to the LCD.

NTP script for AT commands was on Arduino forum, which requires no libraries, simple function returning unix time variable. Got pointed towards code for using an I2C LCD on the LM4K120 and connected that with the original RTC/Hibernate Library I initially found

To Do:

7 Oct

Tested the solenoid, pretty annoyed to see it pulls 2A at 12v, but it works great. It's pretty-much a life diaphragm for the plants.
Test solenoid at range
Test ESP8266 in garden.

Electronics container:

12 Oct

To do:
-time zone for sql
Able to send variables to SQL using this code. Yet to pull variables from a web page.

15 Oct

26 Oct

still bamboozled by the hibernate module, light and temperature sensors have arrived, soldered them for testing today:

Light Sensor works

27 Oct

Have been able to get hibernate mode, not from using the hibernate module but 'Low Power mode', which I couldnt see referenced in the hibernate libaries or API reference. This allows sleep for a time period - sleepSeconds(15); - and a push button wake from a suspend state. Just tested that it can use the wake interrupt to wake from a sleep timer :D Now I can start to build up some code. I think possibly the temp sensor may not be working due to requiring an external pullup, so thats a job for tomorrow.

31 Oct

Temp sensor works with a 4k7 pullup, using this library, and this code

2 Nov

Made up a schematic for the parts... still need to figure out voltage measurement for the battery.

3 Nov

So apparently the 3v3 PSU in the TI board can do 400mA. I ran the current draw on the TI chip and came back with numbers today.

50mA with Backlight.

40 w.o backlight.

30 sleep mode.

With the ESP was getting upto 70mA when serial was connected but up to 120mA without.

Datasheet for the ESP claims up to 200mA, so I’ve tried running everything off the TI onboard PSU, except the LCD. This seemed fine, so I’m only using a 12-5v stepdown ebay board. I got weird numbers from my multimeter for the 3v3 PSU, which is a little concerning since it is the reference voltage for voltage measurement of the 12v SLA. I got a voltage divider working giving back around 2900 from an analog read of 12v, so that seems like good bandwidth.

Something like this for voltage measurement:

Function to check battery level. On boot initiate minutely checks with average of 10 measurements taken with 500ms delay. If 5 fail sequential minutes sleep for 1 hr, or until 7 am if after 8pm.

During regular use record 3 sets of voltage averages 1 min apart.

Light sensor and LCD work fine on the same bus.

Tested running the ESP on the TI 3v3 PSU which gave back up to 120mA, could go higher with LCD and backlight, still fine apparently. Didn’t actually check the datasheet for the 3v3 PSU. Found a new NPN transistor and wired its base through a ~1k resistor to a digital out to switch off the ESP when not required.

Calculated daily usage:
60mA*3.3v/1000 = .2W = 4.8Wh/day. This should be half since most time will be sleep with the ESP powered down.

solenoid = 24W, 10 mins per day = 4Wh per day.

add comment.