Sleep modes and Power consumption
A 2.4V Low Power OTAA Node
A KiCad PCB design
After building a cheap Atmega32 Arduino node as described in this story:
I decided to build a similar node based on the STM32F103C8T6 boards you can buy on Ebay and other sources for about $ 2.00.
for a board description.
The main advantages are:
- Much more space for your program (most boards have 128K flash even when advertised as 64K)
- 20K RAM
- High speed 32 bit ARM Cortex-M3 processor up to 72Mhz
The main disadvantages are higher power usage and a slightly larger board, but you can switch to lower speeds (8Mhz) and activate sleep modes to safe power when running on a battery or solar panel.
It will use only 70μA while sleeping if you remove the power led and 12μA without the regulator.
I used the same color of wiring as was done for the Atmega node, and attached the wires to the following STM32 board pins:
* Red 3.3V to 3.3V power
* DIO0 Brown to PB1
* DIO1 Grey to PB10
* DIO2 Green to PB11
* Reset Orange to PA8
* NSS Yellow to PB12
* SCK Blue to PB13
* MOSI White to PB15
* MISO Purple to PB14
* Black GND to GND
In this wiring I used the SPI-2 port to drive the LORA chip.
You can also use SPI-1 by defining USE_SPI as 1 in the example source.
The changed wires:
* DIO0 Brown to PA11
* DIO1 Grey to PA12
* DIO2 Green to PA15
* Reset Orange to PB0
* NSS Yellow to PA4
* SCK Blue to PA5
* MOSI White to PA7
* MISO Purple to PA6
It will look like this:
Access to the DIP switches and reset buttons is easier in this SPI-1 setup.
Low Power wiring
If you want to use minimal power then you should use the wiring and software as described in the 2.4V Low Power OTAA node section!
The Arduino sketch:
You can use the standard stm32duino software as described here: https://github.com/rogerclarkmelbourne/Arduino_STM32
but is is better to use my adapted version which adds 8/16 Mhz support and the C11 compilation flag which is needed for compiling the LMIC sources:
Finally you will need the Arduino LMIC library adapted for the STM32:
Note that this adapted library should still work for the Atmega, no need to have two copies.
The sketch sends 3 data values, a reading from ADC A0 (battery voltage read from a voltage divider of eg 100 kOhm/100 kOhm) and a fake temperature and pressure. These last two values can be read from e.g. a BMP085 chip.
Sleep modes and Power consumption
I removed the power led from the STM32F103C8T6 board. If you do not remove it you will have to add 2mA to the power usage numbers given here:
* Running at 72Mhz: 40mA
* Running at 8Mhz: 8mA; Sleep (wait for interrupt): 3mA
* STOP Sleeping (RAM preserved):
- 0.07mA: with all GPIO to INPUT_ANALOG
- 0.012mA: regulator removed and with sleeping LORA Chip
* STANDBY Deep Sleep (RAM lost and reboot at wakeup):
- 0.041mA: including regulator
- 0.003mA: regulator removed and without LORA Chip
The Deep Sleep mode saves the upstream sequence number in an RTC backup register. Note however, that Deep Sleep is not very usefull combined with the LORA chip, because the floating pins cause additional power consumption in the LORA chip. So use the normal Sleep (STOP) mode in this setup.
In addition I added a "NoWaitForDownstreamData" flag to the LMIC library for usage in the Sleep mode. Without this flag the LMIC library waits for 2s (Receive Window) + 3s (LMIC wait for another transmission) + random wait (0 - 2s) after transmitting the data.
So on average an additional time of 6s until the SENT event is delivered!
With the "NoWait" flag the CPU is only running for 250ms for each wakeup cycle!
The node is powered with a small 3.6V NiMH rechargable battery, the type often used in cordless home phones.
A small 5V solar panel is connected with a diode to the battery and (trickle) charges it. The diode is needed to prevent a reverse discharge current through the solar panel when it is dark. The type of diode is not critical, you can use e.g. a BAT85 Schottky type, but a regular 1N400x will also do the job.
You can also use regular NiMH penlite cells in a battery holder. It is best to use 3 cells (3.6V). A larger number of cells (eg 4: 4.8V) increases the chance of unbalanced charge in the individual cells. The solar panel should be at least 5V to charge a 3 cell battery or 4V to charge a 2 cell battery.
The size of the battery and the solar panel depends on the power consumption of your node and your location. If you're located about half way between a pole and the equator, e.g. in The Netherlands (52°N) you'll have to survive the two darkest winter months: december and january in the Northern hemisphere. Closer to a polar circle you'll need sufficient capacity in your battery for 4 dark months.
A node which consumes 0.25mA on average will do fine with a battery capacity of 600 mAh. This would in theory allow operation in the dark for 600 / 0.25 = 2400 hours, i.e. 100 days. This is optimistic, cheap phone batteries will be closer to 60 days, but high quality Eneloop cells will be quite close to the rated capacity. The Eneloop Lite cells are a good choice if you don't need the capacity of normal Eneloops. The Lite cells have a reduced capacity, but they are cheaper and lighter than the normal Eneloops and even more robust than normal Eneloops. They will tolerate continuous charging (which we will not do in our solar setup) and complete discharge and still be in good shape when you've already lost interest in your nodes for a long time :-)
There is no point in using Eneloop-Pro cells in these setups, you don't need the extra capacity and they are slightly less robust.
I suggest using a 100mA solar panel for a 2000mAh AA cell setup (when you're close to the polar circle or your node uses about 1mA) and a 30mA solar panel for a 600mAh AAA cell setup. This C/20 ratio will not overcharge the cells and be sufficient to keep the cells close to 100% charge during the spring/summer/autumn months and survive the winter months.
Note that 600 mAh for a 0.25mA node is an estimate on the safe side. This will work for solar cells at a bad location, e.g. on the shadow side of a building. A higher power consumption is in many situations no issue, but you'll have to wait for the winter months to verify your setup.
This method I've used in various projects for the last years. See the green (ESP8266 - 3 AA normal NiMH cells), dark orange (STM32 - 600mAh phone accu) and light blue (STM32 - 2 AAA Eneloop Lite cells) lines which show the battery voltages.
A 2.4V Low Power OTAA Node
I made a second node with two Eneloop Lite AAA cells and OTAA activation. It reads the STM32 unique chip ID to generate an identification.
The wiring was changed a little, I used SPI-1 and changed Yellow NSS to PB0 and Orange RST to PB1 to have less crossing wires. DIO 0 (brown) and 1 (grey) were changed to PA3 and PB5. DIO 2 (green) was disconnected because it is not needed for sending LORA packets. These changes were made because the 5V tolerant pins draw a lot of current in sleep mode.
The regulator was removed (it uses 0.04mA).
If you keep the regulator then you should just connect the 2.4V to the 5V input pin. This uses less power than directly connecting to the 3.3V pin and it is safer because it guards against over voltage.
In this setup the total usage when sleeping is 12µA (without regulator) or 71µA (with regulator) at 3.3V!
I added a 10KOhm NTC for temperature measurement and a yellow LED to blink the temperature.
The STM32 chip supply voltage (behind the regulator if you don't remove it) is read without additional wiring/components. It uses the STM32 internal ADC input and reference voltage. The onboard led flashes the measured voltage. 4 and 5 flashes means 2.45V. When the voltage is more than 3V it will flash 3 series: 3, 4, 1 signals 3.41V.
You can find the source here:
A KiCad PCB design
This combines the STM32 board, the RFM95 board and a small prototype area.
You should place only some of the headers shown in the image above (e.g. just the battery power pins) and add some additional components/sensors to the area in the upper right.
The board has a voltage divider for measuring the battery voltage.
You might skip the capacitors (these make the 3V3 power more stable), resistors (if you do not need the battery voltage measurement) and diode (if you don't plan to use a solar panel).
I have a small stock of PCB boards. If you want to experiment then I can mail you boards for 2€ a piece (total postage 3€).
A screendump of KiCad, a great program to adapt the PCB design to your own ideas. E.g. if you want a larger board or replace the prototype area with your favorite fixed sensors: