Avnet’s Azure Sphere starter kit features Microsoft’s MT3620 IoT module, along with several connectors and MikroE expansion slots. The board also contains the LSM6DSO, an IMU and temperature sensor, and an LPS22HH, a pressure sensor.
These two sensors are accessed via the I2C bus, but unlike the Arduino ecosystem, there aren’t any libraries to use with them yet.
However, Element14 has a great guide on using the onboard sensors as well, along with sample code to display sensor outputs.
The example program for displaying basic sensor data can be found here on GitHub.
In order to send commands and retrieve data from the onboard sensors, each chip’s respective datasheet must be read. The datasheet lists specifications, such as timings, data structures, and addresses. The datasheet for the LSM6DSO can be found here, and the datasheet for the LPS22HH can be found here.
The LSM6DSO houses the 3D accelerometer and gyroscope, along with the temperature sensor. Before any data can be collected, the sensor must be configured. These settings include polling rate, sample size, and operating mode. For this project, both the accelerometer and gyroscope will be active. The data rate is set to 12.5Hz by writing a value of 1 to the register CTRL1_XL (0x10) in bit 3. A scale of 4g is set by writing 0b10 to CTRL1_XL in bits 4 and 5.
Data is retrieved by accessing registers 0x28 through 0x2D. Since data is stored in a 16-bit format, but the registers are only 8-bit, the data must be reassembled from the two corresponding registers. For instance, register 0x28 stores the lower 8 bits for the X axis on the accelerometer, while register 0x29 stores the higher 8 bits. A simple bit-level manipulation is needed to combine the two, like so:
(Upper byte) 0b10101010 << 8 = 0b1010101000000000 ------------------------------- 0b1010101000000000 + 0b11111111 (Lower byte) = 0b1010101011111111
This gives the entire number. By performing this operation for each axis, acceleration values can be easily retrieved.
The gyroscope is very similar to the accelerometer in terms of configuration. To begin, a data rate of 12.5Hz is set by writing a value of 1 to the fourth bit of CTRL2_G. The scale of 2000dps is set by writing 1 to the fifth and sixth bits. To read gyroscope data, a 16-bit value gets read three times, once for each axis in a manner similar to the accelerometer. The register addresses span from 0x22 to 0x27.
The temperature sensor on the board is actually integrated with the IMU. Reading from it is very simple. Registers OUT_TEMP_H (0x21) and OUT_TEMP_L (0x20) both get read. The data is in two’s complement format.
To use them initially, simply git clone the example code to a directory and then open it up with Visual Studio.
Then run it by clicking “Remote GDB Debugger at the top to load the program onto the Azure Sphere device.
Here is some output from Element14’s example code:
This is a quick overview of the onboard sensors found on the Avnet Azure Sphere Starter Kit. For more information, visit the datasheets for the LSM6DSO and LPS22HH.