Friday 2 March 2018

The STM32 LoRa Discovery kit: adding sensors

(Playing with the X-NUCLEO-IKS01A2)

So, now that the STM32 board is up and running, it's time to start doing something with it. Luckily for me, the friendly folks at the STMicro stand also put a sensor expansion board in my hands. This X-NUCLEO-IKS01A2 board (what's in a name) carries a number of sensors, as well as extension connectors and such:

Key Features (taken from the STMicro website)

  • LSM6DSL MEMS 3D accelerometer (±2/±4/±8/±16 g) and 3D gyroscope (±125/±245/±500/±1000/±2000 dps)
  • LSM303AGR MEMS 3D accelerometer (±2/±4/±8/±16 g) and MEMS3D magnetometer (±50 gauss)
  • LPS22HB MEMS pressure sensor, 260-1260 hPa absolute digital output barometer
  • HTS221: capacitive digital relative humidity and temperature
  • DIL24 socket for additional MEMS adapters and other sensors
  • Free comprehensive development firmware library and example for all sensors compatible with STM32Cube firmware
  • I²C sensor hub features on LSM6DSL available
  • Compatible with STM32 Nucleo boards
  • Equipped with Arduino UNO R3 connector
  • RoHS compliant 
The board communicates through I2C and libraries can of course be downloaded from the website.

Let's send some data!

 As with the LRWAN1 board, it really pays off to read at least part of the documentation included in the library. After setting up I2C and configuring the library to use the correct addresses, it is pretty easy to create a compact payload for LoRa transmission:

BSP_sensor_Read( &sensor_data );

temperature  = ( int16_t )( sensor_data.temperature * 100 );

pressure     = ( uint16_t )( sensor_data.pressure * 100 / 10 );
humidity     = ( uint8_t )( sensor_data.humidity );
batteryLevel = ( uint8_t )(HW_GetBatteryLevelInMilliVolts( ) / 100);
lightLevel   = ( uint8_t )(HW_GetLightLevelRaw( ));
soundLevel   = ( uint8_t )(HW_GetSoundLevelRaw( ));

(Full source code available on request)

The lightLevel and soundLevel values are not taken from the included sensors. Because the NUCLEO boards include Arduino-style headers, I decided to stick an Arduino breadboard on top, and included (analog) sensors for sound and light, which are read by two ADC channels. So now the whole contraption looks like this:

Now to find a use for the remaining accelerometer sensors... Any ideas? Please let me know!


  1. hi DutchMcGyver

    I'm doing the study for LoRaWan platform development on STM32 LoRa Discovery Kit with X-NUCLEO-IKS01A2 sensor board. May I request to get the Full source code for study? Email address: Thanks

  2. Hello.
    Can you send me full source code for study ? Email adress: Thank you.

    1. Hi, a link to the source code has been sent.

    2. I have not received any email. Can you send again ?

    3. Hi, the link has been resent.

    4. All works :) How you decode data?

    5. I was solve my problem.

  3. This comment has been removed by the author.

  4. Did you use GPS in STM32 LoRa board ?

    1. No, I did not. Should work though; there's lots of TTN mapper projects that use this.

  5. I have one problem. In transsmision Baterry Voltage is 0. Where is the problem ?

    1. Hi Szymon,
      This article is over 3 years old so I don't remember the specifics. However, I'd start by monitoring the DEBUG output (Lines 272 - 278 in my main method). Does that also read 0? If so, add a debug line to report on the actual HW_GetBatteryLevel value. This will give you an indication of where to look.
      You may also have to look at the actual hardware port configuration and add a connection to the battery itself.