<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Getting zeros from ISM330DHCX accelerometers</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/114204/getting-zeros-from-ism330dhcx-accelerometers</link><description>Hello, 
 
 I am trying to read ISM330DHCX accelerometer ( Adafruit product) data using nRF522832 but I am getting zeros all the time regardless whether the sensor is moved or not. I am following the I2C protocol. I can read the sensor on Arduino. The</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 29 Aug 2024 02:28:10 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/114204/getting-zeros-from-ism330dhcx-accelerometers" /><item><title>RE: Getting zeros from ISM330DHCX accelerometers</title><link>https://devzone.nordicsemi.com/thread/500316?ContentTypeID=1</link><pubDate>Thu, 29 Aug 2024 02:28:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:04c76de6-80ad-4c9a-838f-6abf364ae08a</guid><dc:creator>ahmed almaghasilah</dc:creator><description>&lt;p&gt;Hello Kazi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thank you so much for bring this to my attention.&amp;nbsp; I was not aware there was a driver for sensors from ST.&amp;nbsp; I was under the impression that Zephyr/nRF drivers is capable by itself in handling it.&amp;nbsp;&amp;nbsp;&lt;br /&gt;&lt;br /&gt;At first when I added&amp;nbsp;&lt;span&gt;CONFIG_ISM330DHCX=y in project configuration file (prj.conf), an error popped up and I was not sure.&amp;nbsp; The moment I built/flashed the kit, there was no error.&amp;nbsp; I finally made it work. Thank you so much Kazi!&lt;br /&gt;&lt;br /&gt;Here is my final code for others who might run into same issue or first time in nRF and ST sensors:&lt;br /&gt;&lt;br /&gt;main.c&lt;/span&gt;&lt;span&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;lt;zephyr/device.h&amp;gt;
#include &amp;lt;zephyr/drivers/i2c.h&amp;gt;
#include &amp;lt;zephyr/drivers/sensor.h&amp;gt;
#include &amp;lt;zephyr/sys/printk.h&amp;gt;
#include &amp;lt;zephyr/kernel.h&amp;gt;

#define ISM330DHCX_I2C_ADDR 0x6A

void main(void)
{
    const struct device *sensor = DEVICE_DT_GET_ONE(st_ism330dhcx);
    int ret;

    if (!device_is_ready(sensor)) {
        printk(&amp;quot;Sensor device not found\n&amp;quot;);
        return;
    }

    // Example setup for 104 Hz ODR, &amp;#177;4g full scale
    uint8_t config1[] = {0x10, 0x88}; // CTRL1_XL: ODR=104 Hz, FS=&amp;#177;4g
    struct i2c_dt_spec i2c_dev = I2C_DT_SPEC_GET(DT_NODELABEL(mysensor));
    ret = i2c_write_dt(&amp;amp;i2c_dev, config1, sizeof(config1));
    if (ret != 0) {
        printk(&amp;quot;Failed to configure ISM330DHCX CTRL1_XL (error: %d)\n&amp;quot;, ret);
        return;
    } else {
        printk(&amp;quot;ISM330DHCX configured successfully\n&amp;quot;);
    }

    uint8_t raw_data[6];
    struct sensor_value accel[3];

    while (1) {
        ret = sensor_sample_fetch(sensor);
        if (ret) {
            printk(&amp;quot;Sensor sample update error: %d\n&amp;quot;, ret);
            continue;
        }

        // Read raw accelerometer data registers directly
        ret = i2c_burst_read(i2c_dev.bus, ISM330DHCX_I2C_ADDR, 0x28, raw_data, sizeof(raw_data));
        if (ret == 0) {
            // printk(&amp;quot;Raw data: X_L=%02x X_H=%02x Y_L=%02x Y_H=%02x Z_L=%02x Z_H=%02x\n&amp;quot;,
            //     raw_data[0], raw_data[1],
            //     raw_data[2], raw_data[3],
            //     raw_data[4], raw_data[5]);

            // Interpret the raw data into signed 16-bit integers
            int16_t raw_x = (int16_t)(raw_data[1] &amp;lt;&amp;lt; 8 | raw_data[0]);
            int16_t raw_y = (int16_t)(raw_data[3] &amp;lt;&amp;lt; 8 | raw_data[2]);
            int16_t raw_z = (int16_t)(raw_data[5] &amp;lt;&amp;lt; 8 | raw_data[4]);

            // printk(&amp;quot;Raw interpreted data: X=%d, Y=%d, Z=%d\n&amp;quot;, raw_x, raw_y, raw_z);

            // Convert raw values to m/s^2 ( 1g = 9.80665 m/s^2)
            // const double scale = 9.80665 / 2050.0; // Convert from raw to m/s^2 - 16g
            const double scale = 9.80665 / 8197; // Convert from raw to m/s^2 - 4g
            double accel_x = raw_x * scale;
            double accel_y = raw_y * scale;
            double accel_z = raw_z * scale;

            printk(&amp;quot;Acceleration (m/s^2): X=%.6f, Y=%.6f, Z=%.6f\n&amp;quot;, accel_x, accel_y, accel_z);
        } else {
            printk(&amp;quot;Failed to read raw data\n&amp;quot;);
        }

        k_sleep(K_MSEC(300)); // Sleep for 500 milliseconds before reading again
    }
}&lt;/pre&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;nrf52dk_nrf522832.overlay&lt;/span&gt;&lt;span&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;amp;i2c0 {
    status = &amp;quot;okay&amp;quot;;
    mysensor: ism330dhcx@6a {
        compatible = &amp;quot;st,ism330dhcx&amp;quot;;
        reg = &amp;lt;0x6a&amp;gt;;
        label = &amp;quot;ISM330DHCX&amp;quot;;
    };
};&lt;/pre&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;prj.conf (I do not believe you need all in the list)&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048

CONFIG_BT=y
CONFIG_LOG=y
CONFIG_BT_SMP=y
CONFIG_BT_SIGNING=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_DIS=y
CONFIG_BT_ATT_PREPARE_COUNT=5
CONFIG_BT_BAS=y
CONFIG_BT_HRS=y
CONFIG_BT_IAS=y
CONFIG_BT_PRIVACY=n
CONFIG_BT_DEVICE_NAME=&amp;quot;My_nRF52_Device&amp;quot;
CONFIG_BT_DEVICE_APPEARANCE=833
CONFIG_BT_DEVICE_NAME_DYNAMIC=y
CONFIG_BT_DEVICE_NAME_MAX=65

CONFIG_BT_KEYS_OVERWRITE_OLDEST=y
CONFIG_BT_SETTINGS=y
CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_MAP=y
CONFIG_NVS=y
CONFIG_SETTINGS=y

CONFIG_BT_PERIPHERAL_PREF_MIN_INT=96
CONFIG_BT_PERIPHERAL_PREF_MAX_INT=96

CONFIG_GPIO=y  # Add this line for GPIO support

CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048

CONFIG_I2C=y
CONFIG_I2C_NRFX=y
CONFIG_SENSOR=y

CONFIG_ISM330DHCX=y

CONFIG_LOG=y
CONFIG_PRINTK=y
CONFIG_CBPRINTF_FP_SUPPORT=y&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Getting zeros from ISM330DHCX accelerometers</title><link>https://devzone.nordicsemi.com/thread/499810?ContentTypeID=1</link><pubDate>Mon, 26 Aug 2024 15:20:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:255e75b4-5b33-4ad6-a98a-e043c54a6621</guid><dc:creator>Kazi Afroza Sultana</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;The default pin for i2C0 is SDA(26) and SCL (27) on nRf52832. Have you checked the pin set up?&lt;/p&gt;
&lt;p&gt;There is an existing a driver for this sensor&lt;/p&gt;
&lt;p&gt;&lt;a title="https://github.com/nrfconnect/sdk-zephyr/tree/main/drivers/sensor/st/ism330dhcx" href="https://github.com/nrfconnect/sdk-zephyr/tree/main/drivers/sensor/st/ism330dhcx" rel="noopener noreferrer" target="_blank"&gt;https://github.com/nrfconnect/sdk-zephyr/tree/main/drivers/sensor/st/ism330dhcx&lt;/a&gt;;&amp;nbsp;Is&amp;nbsp;&lt;span&gt;the sensor is correctly configured in your project&amp;#39;s configuration file. The ISM330DHCX sensor should be enabled with&amp;nbsp;&lt;/span&gt;&lt;code dir="ltr"&gt;CONFIG_ISM330DHCX=y.&lt;/code&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>