Solar IOT Garden build blog

Jumping on the Internet Of Things bandwagon (or whatever) this project is basically a hardware and software project. I am designing a micro-controller 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…

block diagramIt 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

StellarisSMALLSo, 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.

esp8266The 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:

  • Advanced setting, reset wifi to AP mode for wifi config through web ui (much later).
  • Sensor Readings -> latest / average for last 24 hrs of sensor readings -> each sensor.
  • Run Solenoid -> 30 secs now/disable, (set disable end time) -> wait for pattern (6 keys) (return home if fail).
  • Turn off LCD after ~20 secs.
  • Clear readings -> pattern
  • Security would be preventing a malicious entry from a server putting the Stellaris into firmware upload mode. Ehh.
  • Software reset

SQL

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

  • Table with sensor readings, only fetches un-received readings.
  • php page allows schedule changes, some form of display for tables, look into php data to image scripts.

20 Sep 2015

boardsJumpredTogetherI’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

SAMSUNG
SAMSUNG

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:

  • Store wifi settings on Stellaris flash (Well Tiva C actually) and set ESP8266 if IP address returns 0.0.0.0
  • Send array variables on flash to SQL server
  • Recieve array variables from SQL server to flash
  • create analog voltage measurement circuit
  • Sort sleeping for ESP8266
  • Sort sleeping for TI Chip

7 Oct

tapsTested 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:

  • Strong white bucket with lid
  • Battery mount
  • Insulation on inside
  • Fan on edge
  • Air intake and outvent, facing down
  • Internal electronics: TI, charger, 5V PSU, 3v3 PSU, ESP8266, level shifters, fan electronics (transistor to connect to GPIO), solenoid relay, internal temperature.
  • Output connector: solar panel, moisture x 3, solenoid, humidity, light sensor.
  • Display perhaps in lid with cover flap, with 4 push buttons.

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

  • Found this library for the Humid/temp sensor which works.
  • Looking through the hibernate energia library, using this as a reference, so I can set the hibernate module to run an interrupt service routine based on rtc (easily linked to the existing DateTimeLibrary for RTC), or a hardware interrupt. The hibernate ISR will find if the interrupt came from the RTC or button press and set a global variable for each. For button press, this variable could be a time out for the LCD backlight, eg RTC epoch + 30 seconds. The RTC interrupt could set a variable to run in the main loop, perhaps once a minute. This variable could trigger code to update sensors to the internet, this could happen perhaps every 10 minutes (10 hibernate cycles, requires handling for low batt voltage, perhaps store sensor readings to non-volatile memory). The RTC interrupt variable can be set on a time corresponding to running the sprinklers (code takes RTC epoch and compares to sprinkler schedule)
  • Sprinkler schedule: pull variable from internet for schedule type ( run for mins at time per hours eg 5 mins at 6am (+maybe 1 min at 8pm) per 24/48 hrs), or more complex soil moisture config.

26 Oct

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

Light Sensor works
lux

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 😀 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 OcttempS

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

2 Novschematic

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.

Dec

Bought a domain name while I was away and created an animated intro

Leave a Reply

Your email address will not be published. Required fields are marked *