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!