top of page

Position detection with the ASM330LHHXG1 IMU sensor


In this demonstration, we delve into the versatile capabilities of SmartWave in tandem with our Python API to capture and visualise real-time data from the ASM330LHHXG1, a high-accuracy 6-axis automotive inertial measurement unit developed by STMicroelectronics. 

Interface Setup

To interface with SmartWave, we employ the STEVAL-MKI243A evaluation board. Additionally, we incorporate a PCF8575 IO expander from NXP into our setup. This IO expander serves to toggle LEDs, providing visual representation of the linear displacement of the IMU sensor along the X-axis and Y-axis. In a previous article, we extensively covered the process of interfacing with the IO expander via I2C.

STEVAL-SMKI243AA Evaluation Board courtesy of STMicroelectronics


Configuring the IMU sensor

The ASM330LHHXG1 supports register access through both I2C and SPI serial interfaces. For our demonstration, we opt for the I2C interface with the default device address set at 0x6A, for which the SDO/SA0 pin, has to be connected to GND. Covering the functionality of the I2C interface is beyond the scope of this article. However, readers are encouraged to refer to the I2C-bus specification user manual from NXP for comprehensive insights.

Verifying successful connection to the target device involves reading from the register address 0x0F, which houses the unique identifier of 0x6B. Before initiating measurements with the device, it's crucial to configure the accelerometer and gyroscope control registers. Activation of both sensors is achieved by setting the Output Data Rate (ODR) register field, which we maintain at 12.5Hz for low-power mode. Additionally, we keep the full-scale range settings at the default values of +/-2g for the accelerometer and +/-250 dps for the gyroscope. Detailed descriptions of the control register settings are available in the manufacturer’s datasheet.

Data Processing

The IMU sensor includes three pairs of 8-bit output registers for both the linear acceleration sensor (X, Y, and Z-axis) and the angular rate sensor (Roll, Pitch, Yaw). The data within these registers are expressed in two's complement format. To make use of this data, we need to combine the two 8-bit register values, shifting them to form a 16-bit value, and then compute its two's complement. This provides raw data that requires conversion before plotting. Referring to the datasheet, we can obtain the sensitivity rate for both the accelerometer and gyroscope, dependent on their full-scale range setting. To determine acceleration in m/s², we simply multiply the raw data by the sensitivity value and g (9.80665). Apply the same process to the gyroscope data, but multiplying it with its sensitivity value only.

Plotting the Data

Visualising the IMU sensor data is achieved using the standard Matplotlib library. Utilising its FuncAnimation method, it enables real-time data plotting by iteratively calling a function that retrieves sensor data and updates the plot accordingly.

Python API

Our python package is available on PyPi, and it can be installed by running the following command: pip install SmartWaveAPI. You can either run this from your preferred IDE or from CLI. This API facilitates seamless interaction with SmartWave and the target device, offering robust data acquisition and post-processing capabilities.

Python API


Both the IMU sensor and the IO expander were assembled on a prototype board alongside with the LEDs and passive components to create a functional demonstration setup for visualising the sensor data. The schematics and the hardware setup can be found below.

Demonstrator board schematic

Hardware setup

Running the IMU demo

All that remains is to connect SmartWave to your PC and execute the IMU demo script. Both the demo script and the configuration library have been included in our GitHub repository for easy access. Feel free to download and experiment with it yourself.

Please be aware that additional libraries are necessary to run this script, including Numpy, Matplotlib, and keyboard. If these libraries are not already installed on your PC, please ensure to install them using pip install before attempting to run the script. For your convenience, we have provided a requirements.txt file containing all the essential Python packages required to run our demos. Take a peek at this demo in the video below! Position detection.

IMU Data plot


In conclusion, this demonstration showcases the powerful synergy of SmartWave and our Python API in capturing and visualising real-time data. By seamlessly integrating SmartWave into your projects, you gain access to a powerful platform that simplifies interface setup, enables detailed sensor configuration, and facilitates efficient data processing.

For those eager to explore SmartWave's potential further, feel free to reach out to semify via email (  for additional information, product demonstrations, or tailored discussions about specific requirements. Explore more intriguing articles and demos featuring SmartWave through the provided links to unlock new possibilities in your projects.

Recent Posts

See All


bottom of page