In this part we will discuss the boards that we used and the shield put on them
to read data from numerous sensors in the agricultural field and
send the data via LoRa to our gateway.
We used the STM32 Nucleo-64 boards because they are very flexibles and has
a good combination of performance and low consumption, in particular the STM32L0 Series.
For a better development we used the P-NUCLEO-LRWAN1. This is a dev board that include a STM32 Nucleo with a STM32 L0 series MCU and a LoRa expansion board. This last board contains the SX1272 transceiver developed and produced by Semtech.
Using Semtech’s patented LoRa modulation technique SX1272 can achieve a sensitivity of over -137dBm. It's a lot a features as: +20dBm at 100mW constant RF output vs. V supply, +14dBm high efficiency PA (programmable amplifier), programmable bit rate up to 300kbps ...
Transiver programming is done through the SPI interface and using the DIO pins for enabling various functions.
For the programming the STM32 MCU a first choice is to use the STM32Cube, which is STMicroelectronics’s original initiative to ease and accelerate the development cycle of embedded products. STM32Cube covers the STM32 portfolio of microcontrollers, it also include the he STM32Cube Hardware Abstraction Layer (HAL), an STM32 abstraction layer embedded software ensuring maximized portability across the STM32 microcontroller. The HAL is available for all the hardware peripherals.
Since that using HAL is not the most comfortable thing, especially if at an early stage of the project we used the STM32duino, a STM32 core support for Arduino.
In the STM32duino there is the STM32LowPower, an Arduino Low Power library for STM32. This allows us to use the low power features available from the microcontroller.
For the activation and configuration of the radio module we used the RadioLib, "Universal wireless communication library for Arduino". This library supports a lot of Wireless Modules and Protocols, in particular the SX127x series LoRa module.
This library makes it easy to set up and use the radio module. Using arduino ide you can use all the libraries that support arduino.
As you can see in the repository at the bottom of the page, we have imported the library:
Provide the pin setup to the library:
SX1272 radio = new Module(10, 2, 19, 3);Where:
NSS pin: 10
DIO0 pin: 2
RESET pin: 19
DIO1 pin: 3
LoRa modem initialization method:
int state = radio.begin(869.8, 125.0, 12);Where:
869.8 is the Carrier frequency in MHz.
125.0 is the LoRa link bandwidth in kHz.
12 is the LoRa link spreading factor.
We have discovered, through the datasheet of the dev bard of the radio module, that the PA_BOOST pin that was used in the library is not connected so to make the antenna work it is necessary to go through the RFO pin, using the function available from the Radiolib library setOutputPower(), thanks to which we have set the output transmission in this way:
14 is the Transmission output power in dBm.
true is to use the RFO pin
To send the packets through an encryption layer we have chosen to decode them according to the LoRaWAN standard, this is easy using the LoRaWanPacket library.
By setting a devAddr, nwkSKey and appSKey it is possible to send packets over the LoRaWAN standard. For a verification of the packets you can de-encode them via this website.
To use the lowpower features provided by the chosen dev board we used the STM32LowPower library, an Arduino library to support low power save primitives features of STM32 based boards.
With this we can set four hardware states:
- Idle: Memories and voltage supplies are retained. Minimal power saving mainly on the core itself.
- Sleep: Minimal power saving mainly on the core itself but higher than idle mode.
- Deep sleep: That used, Clocks are gated to reduced. Memories and voltage supplies are retained.
- Shutdown : Voltage supplies are cut except always-on domain, memory content are lost and system basically reboots.