Last night, I did a small amount of work on two projects.
I applied some Wood Bondo to a couple of bad defects in my garden bench project. I hadn’t used it in a while, and forgot what a pleasure it was. Sanding should be finished up shortly and I’ll definitely have it painted and finished this weekend.
The other thing I worked on was trying to prototype the main control loop of my IoT sensor project. Since I got the basic radio hookup done last night, I thought I would work on a slightly different issue.
My recent musing have been concentrating around reducing the power consumption of these boards. The way that is normally achieved is by putting the processor to sleep, effectively telling it to halt the main processor for a predefined amount of time. Then, either in response to a timer event or an external interrupt, the processor can wake up, read all its sensors, and log it to a local SD card or transmit the measurement wirelessly before going back to sleep.
Some microcontrollers have elaborate timing modules that can run while the main processor, but that is not the case for the Arduino. It just has a single “watchdog” timer that can serve to wake the processor back up, and it is relatively inflexible: it can only be set for a small set of intervals, the maximum length of which is eight seconds. It’s also not particularly accurate, since it is clocked by an RC based internal oscillator that operates at 128Khz. You definitely can try track time this way, but it seems a bit complicated and a little messy
As it happens, I have a fair number of DS3231 clock modules lying around. The specifications have an accuracy of ±2ppm from 0°C to +40°C , which translates to an accuracy of about one minute per year. I could live with that.
The DS3231 also includes an alarm module. This enables you to program two alarm registers with times that will trigger the alarm when matched. There are two registers (ALARM_1 and ALARM_2) and you can query whether either has been triggered, or you can configure the the chip to toggle the SQW output pin low when the alarm goes off. I found this primer to be pretty helpful. What was not helpful was that my cat Bailey kept on jumping into my lap while I was trying to concentrate, so while I managed to get the basic “polling” based code to work, I couldn’t quite wrap my head around getting the sleep mode and interrupt stuff to work. I think that tonight I’ll pull out my oscilloscope to ensure that the proper signals are being generated by the board, and then at least narrow my confusion to where I can hopefully eliminate it.
In the mean time, I’ve been spending some of my spare time reading all the tons of useful information on The Cave Pearl Project website, including this awesome collection showing how build their Pro Mini Data Logger. The accompanying video play list shows lots of tiny bits of cleverness in how they prep the various boards and attach them together in a clever way to build a nifty little datalogger for less than $10 in parts. Well worth your time to watch.