This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to add new i2c based sensor device to ncs\v1.3.0\zephyr\drivers\sensor

How to add new i2c based sensor device to ncs\v1.3.0\zephyr\drivers\sensor.

Can you suggest any tutorial to do so as i want to use sensor subsystem which in turn uses i2c driver.

Thanks

Chandra

Parents
  • I tried to look around but could not find any such guides. However I have provided an answer for this earlier, take a look at it here.

    Down below I've provided a short guide how to add a custom sensor to Zephyr

    • Start with a senor most similar to your sensor and use it as a reference
    • Create a binding in zephyr\dts\bindings\sensor\<compatible string>.yaml
      • E.g. copy zephyr\dts\bindings\sensor\adi,adxl362.yaml, change the name and modify it according to your sensor
    • Create the driver in zephyr\drivers\sensor
      • E.g. copy zephyr\drivers\sensor\adxl362, change the name and modify it according to your sensor
    • In \zephyr\drivers\sensor\CMakeLists.txt add the following line

      add_subdirectory_ifdef(CONFIG_<name of sensor> <sensor directory>)

      • In \zephyr\drivers\sensor\Kconfig add the following line

        source "drivers/sensor/<sensor directory>/Kconfig"

        • Create a sample in zephyr\samples\sensor, to test if it works as expected

        Best regards,

        Simon

      • Hi

        Thanks for the info and this is verymuch useful.

        I have followed all the steps.

        in  the sensor  c file, i have some like below:

        #if defined(DT_VENDOR_CHIPNAME_BUS_SPI)
            chip_spi_init(dev);
        #elif defined(DT_VENDOR_CHIPNAME_BUS_I2C)
            chip_i2c_init(dev);
        #else
            #error "BUS MACRO NOT DEFINED IN DTS"
        #endif

        These macros are not getting defined. This is some things to do with zephyr system, but any pointers that would greatly help to proceed.

      Reply
      • Hi

        Thanks for the info and this is verymuch useful.

        I have followed all the steps.

        in  the sensor  c file, i have some like below:

        #if defined(DT_VENDOR_CHIPNAME_BUS_SPI)
            chip_spi_init(dev);
        #elif defined(DT_VENDOR_CHIPNAME_BUS_I2C)
            chip_i2c_init(dev);
        #else
            #error "BUS MACRO NOT DEFINED IN DTS"
        #endif

        These macros are not getting defined. This is some things to do with zephyr system, but any pointers that would greatly help to proceed.

      Children
      Related