Sleep modes and Power consumption
A 2.4V OTAA Node
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)
- 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.
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.
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 330 kOhm/330 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
* Sleeping (RAM preserved):
- 0.07mA: with all GPIO to INPUT_ANALOG
- 0.021mA: regulator removed
* 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.
The RFM95 LORA chip uses 0.5mA in sleep mode. According to the specs this should be much less (0.2μA), but I can not get such a low figure.
In addition I added a "NoWaitForDownstreamData" flag to the LMIC library for usage in the DeepSleep 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.
I described the various options in an old blog entry: Solar Powering
This method I use in various projects, the green (ESP8266) and orange (STM32) lines show the battery voltages:
A 2.4V 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.
The regulator was removed (it uses 0.04mA), but this does not make much sense because I cannot get the RFM95 below 0.5mA usage. This should be much less (0.2µA!), so any hint on what might be wrong would be very much appreciated!
If you keep the regulator (which I advise as long as the RFM95 power usage riddle is not solved) 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.
I added a 10KOhm NTC for temperature measurement and a yellow LED to blink the temperature.
The STM32 chip supply voltage (after the regulator if you don't remove it) is read without additional wiring/components, it uses the STM32 internal ADC input and reference voltage.
You can find the source here: