A different direction...

A project log for Share the Warmth

Warm-air distribution system (PIC/JALv2)

sbi.gaijinsbi.gaijin 06/05/2015 at 14:140 Comments

As mentioned (briefly) in a previous log, I was (note the use of the past tense there!) impressed with the new kid on the block, the ESP8266 and had hatched a cunning plan to use a bunch of them as remote temperature sensors and room thermostats for this project. However, as anyone who has touched an ESP will already know by now, these neat little devices also have an additional feature ...a built in worm-hole which sucks all of the time out of your life space and tunnels it into a black hole in a parallel universe (same place as all of those odd socks end up!). Trying to do anything with these modules can take the odd couple of centuries (and at the end of that time, you might just end up with someone else's odd sock, rather than a functioning ESP).

Recently I've been trying to get the I2C interface to work between an ESP and a DS3231 RTC module (the el-cheapo, middle kingdom version, with the AT24C32 memory chip on the same PCB). I have it on good authority that it works, as Richard Burton has spent a lot of time putting together libraries for both the DS3231 and the AT24C32 (and his blog is a pretty good read for anyone interested in the ESP). However, my attempts to get it to work ended with a pile of odd socks of unknown origin and nothing much else. <TL;DR> The short story is, if you want to use the I2C funtionality provided by the Espressif IoT SDK, you must call :-


...before doing anything else (and after having declared which GPIO pins you want to use as SDA and SCL). This call will set the GPIOs to "open drain" mode and then call the I2C initialize routine before returning. [The long, Hackaday-fail-of-the-week style story is here, if you're interested, BTW]

Okay, so finally I have I2C working and can talk to the DS3231. As I already mentioned in the main project description, the master microcontroller, the PIC18F27J53 already has a RTC (one of the reasons it was chosen for this project to begin with), so why would I need another? Well, the DS3231 has a couple of very neat properties. One is that it has an on-chip temperature sensor (to adjust the internal oscillator for ambient temperature variations) which is not only fairly accurate, but also easy to read (integer part of the temperature in one byte and the fractional part in two bits of the next byte). It (the DS3231) also has a very versatile alarm setting, allowing easy configuration of repeatable alarms for a wide range of time periods with (importantly) an open-drain output for the alarm output.

Additionally, the alarms and alarm output are both still available when the DS3231 is running from the back-up, coin-cell battery. What all of this means is that we can now use the combined ESP8266 + DS3231 module as a standalone, battery-powered temperature sensor or thermostat module, with the main battery only powering the ESP when woken by the alarm from the DS3231. This should, in theory anyway, get us past the main bugbear of the ESP, its fairly massive current consumption when active.

We have at least two options for this mode of operation. The first is to use the DS3231 alarm as an interrupt on the ESP reset pin (instead of connecting it to GPIO16 for normal deep-sleep interrupts) and the second. more interesting one, to use the DS3231 alarm line to control the gate of a small P-channel MOSFET to switch VCC to the ESP, for a very nearly zero current "sleep".

Stay tuned to find out which of these methods turns out to be the most effective (with the next update due in about, oh, three and a half odd socks).