Adding a Sensor LSM9DS1

Lawrence King

I am trying to add a sensor to my project. I have already verified that it is electrically connected to the i2c bus correctly with a simple test program which reads the WHO_AM_I register using direct i2c_transfer calls:


struct i2c_msg msgs[1];


msgs[0].buf = data;

msgs[0].len = num_bytes;

msgs[0].flags = I2C_MSG_READ | I2C_MSG_STOP;


return i2c_transfer(i2c_dev, &msgs[0], 1, addr);


Now I want to enable the sensor subsystem, that seems easy enough, just add a few lines to the prj.conf file:






And finally since the drivers are already in the zephyrproject tree, I want to use the LSM9DS1 drivers that are in modules/hal/st/sensor/stmemsc/lsm9ds1_STdC/driver


Here is where I get stuck, I know I need to add a few things:

  1. A device tree entry under i2c0
  2. Descriptions of which interrupt pins from the sensor are connected to which gpios added to the device tree
  3. Convince west or cmake to bring in the source from modules and compile it into the build


‘ninja menuconfig’ doesn’t know anything about the external modules, although west build did put the name of the directory in build/zephyr_modules.txt


I couldn’t find any examples even for other sensors in the zephyr/samples directory, or in the zephyrproject documentation (although but I may have missed it).


Does someone have an example of the device tree entries, and the build process for an external sensor module?


Lawrence King

Principal Developer

Connected Transport Market Unit



1  2 - linkedin  3 - instagram  4 - youtube  6 - facebook  7


CONFIDENTIAL: This e-mail and any attachments are confidential and intended solely for the use of the individual(s) to whom it is addressed. It can contain proprietary confidential information and be subject to legal privilege and/or subject to a non-disclosure Agreement. Unauthorized use, disclosure or copying is strictly prohibited. If you are not the/an addressee and are in possession of this e-mail, please delete the message and notify us immediately. Please consider the environment before printing this e-mail. Thank you.