<?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>Interfacing IMU Sensor (LSM6DSL) with i2c</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/110780/interfacing-imu-sensor-lsm6dsl-with-i2c</link><description>hi ,I am using nrf52840dk- nrf52840 board to interface the IMU Sensor using I2C using nrf connect sdk for vs code. But I am facing error: 
 i&amp;#39;m using the code in ncs/samples/sensor/lsm6dso 
 here is prj.conf: 
 
 CONFIG_STDOUT_CONSOLE =y 
 CONFIG_I2C</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 31 Jul 2024 15:55:26 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/110780/interfacing-imu-sensor-lsm6dsl-with-i2c" /><item><title>RE: Interfacing IMU Sensor (LSM6DSL) with i2c</title><link>https://devzone.nordicsemi.com/thread/496448?ContentTypeID=1</link><pubDate>Wed, 31 Jul 2024 15:55:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6b062fb7-7f64-4887-a266-dde3653f5928</guid><dc:creator>Kazi Afroza Sultana</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Can you please open a new case for this roll and pitch angle calculation?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interfacing IMU Sensor (LSM6DSL) with i2c</title><link>https://devzone.nordicsemi.com/thread/483465?ContentTypeID=1</link><pubDate>Wed, 15 May 2024 10:56:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6ca73fc0-d1e5-470d-98a1-7eb5d3fa351d</guid><dc:creator>rania amara</dc:creator><description>&lt;p&gt;hi i solved the earlier issue by replacing the tigger code by the pooling code in the main.c.But now i&amp;#39;m trying to calculate the roll and pitch angles using accx,accy and accz ,here is main.c code:&lt;pre class="ui-code" data-mode="text"&gt;/*
 * Copyright (c) 2020 Yestin Sun
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;zephyr.h&amp;gt;
#include &amp;lt;device.h&amp;gt;
#include &amp;lt;drivers/sensor.h&amp;gt;
#include &amp;lt;math.h&amp;gt; // Include math library for trigonometric functions


#define LSM6DSO DT_INST(0, st_lsm6dso)

#if DT_NODE_HAS_STATUS(LSM6DSO, okay)
#define LSM6DSO_LABEL DT_LABEL(LSM6DSO)
#else
#error Your devicetree has no enabled nodes with compatible &amp;quot;st,lsm6dso&amp;quot;
#define LSM6DSO_LABEL &amp;quot;&amp;lt;none&amp;gt;&amp;quot;
#endif
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif


static inline float out_ev(struct sensor_value *val)
{
	return (val-&amp;gt;val1 + (float)val-&amp;gt;val2 / 1000000);
}

static void fetch_and_display(const struct device *dev)
{
	struct sensor_value x, y, z;
	static int trig_cnt;

	trig_cnt++;

	/* lsm6dso accel */
	sensor_sample_fetch_chan(dev, SENSOR_CHAN_ACCEL_XYZ);
	sensor_channel_get(dev, SENSOR_CHAN_ACCEL_X, &amp;amp;x);
	sensor_channel_get(dev, SENSOR_CHAN_ACCEL_Y, &amp;amp;y);
	sensor_channel_get(dev, SENSOR_CHAN_ACCEL_Z, &amp;amp;z);
	
	// Calculate Roll angle in degrees
    float AccX = out_ev(&amp;amp;x);
    float AccY = out_ev(&amp;amp;y);
    float AccZ = out_ev(&amp;amp;z);
	printf(&amp;quot;AccX = %.2f, AccY = %.2f, AccZ = %.2f\n&amp;quot;, AccX, AccY, AccZ);
    float Roll = atan2( AccY, sqrt(AccX * AccX + AccZ * AccZ)) * 180 / M_PI;

    // Calculate Pitch angle in degrees
    float Pitch = atan2(-AccX, sqrt(AccY * AccY + AccZ * AccZ)) * 180 / M_PI;

    printf(&amp;quot;Roll = %.2f degrees; Pitch = %.2f degrees\n&amp;quot;, Roll, Pitch);



	/* lsm6dso gyro */
	sensor_sample_fetch_chan(dev, SENSOR_CHAN_GYRO_XYZ);
	sensor_channel_get(dev, SENSOR_CHAN_GYRO_X, &amp;amp;x);
	sensor_channel_get(dev, SENSOR_CHAN_GYRO_Y, &amp;amp;y);
	sensor_channel_get(dev, SENSOR_CHAN_GYRO_Z, &amp;amp;z);

	printf(&amp;quot;gyro x:%f dps y:%f dps z:%f dps\n&amp;quot;,
			out_ev(&amp;amp;x), out_ev(&amp;amp;y), out_ev(&amp;amp;z));

	printf(&amp;quot;trig_cnt:%d\n\n&amp;quot;, trig_cnt);
}

static int set_sampling_freq(const struct device *dev)
{
	int ret = 0;
	struct sensor_value odr_attr;

	/* set accel/gyro sampling frequency to 12.5 Hz */
	odr_attr.val1 = 12.5;
	odr_attr.val2 = 0;

	ret = sensor_attr_set(dev, SENSOR_CHAN_ACCEL_XYZ,
			SENSOR_ATTR_SAMPLING_FREQUENCY, &amp;amp;odr_attr);
	if (ret != 0) {
		printf(&amp;quot;Cannot set sampling frequency for accelerometer.\n&amp;quot;);
		return ret;
	}

	ret = sensor_attr_set(dev, SENSOR_CHAN_GYRO_XYZ,
			SENSOR_ATTR_SAMPLING_FREQUENCY, &amp;amp;odr_attr);
	if (ret != 0) {
		printf(&amp;quot;Cannot set sampling frequency for gyro.\n&amp;quot;);
		return ret;
	}

	return 0;
}

#ifdef CONFIG_LSM6DSO_TRIGGER



	static void test_polling_mode(const struct device *dev)
{
	if (set_sampling_freq(dev) != 0)
		return;

	while (1) {
		fetch_and_display(dev);
		k_sleep(K_MSEC(1000));
	}
}


#else
static void trigger_handler(const struct device *dev,
			    const struct sensor_trigger *trig)
{
	fetch_and_display(dev);
}
static void test_trigger_mode(const struct device *dev)
{
	struct sensor_trigger trig;

	if (set_sampling_freq(dev) != 0)
		return;

	trig.type = SENSOR_TRIG_DATA_READY;
	trig.chan = SENSOR_CHAN_ACCEL_XYZ;

	if (sensor_trigger_set(dev, &amp;amp;trig, trigger_handler) != 0) {
		printf(&amp;quot;Could not set sensor type and channel\n&amp;quot;);
		return;
	}
#endif

void main(void)
{
	const struct device *dev = device_get_binding(LSM6DSO_LABEL);

	if (dev == NULL) {
		printf(&amp;quot;No device \&amp;quot;%s\&amp;quot; found.\n&amp;quot;, LSM6DSO_LABEL);
		return;
	}

#ifdef CONFIG_LSM6DSO_TRIGGER
printf(&amp;quot;Testing LSM6DSO sensor in polling mode.\n\n&amp;quot;);
	test_polling_mode(dev);
	
#else
	printf(&amp;quot;Testing LSM6DSO sensor in trigger mode.\n\n&amp;quot;);
	test_trigger_mode(dev);
#endif
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;and here is the prj.conf file&lt;/p&gt;
&lt;p&gt;:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_STDOUT_CONSOLE=y
CONFIG_I2C=y
CONFIG_SENSOR=y
CONFIG_LSM6DSO=y
CONFIG_LSM6DSO_TRIGGER_GLOBAL_THREAD=y
CONFIG_CBPRINTF_FP_SUPPORT=y
CONFIG_NEWLIB_LIBC=y&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;the probleme is when i run this code is not outputing the values :&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;

AccX = , AccY = , AccZ = 
Roll =  degrees; Pitch =  degrees
gyro x: dps y: dps z: dps
trig_cnt:9

AccX = , AccY = , AccZ = 
Roll =  degrees; Pitch =  degrees
gyro x: dps y: dps z: dps
trig_cnt:10
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;and when i searched about it i found out that i should includes proper settings for floating-point&amp;nbsp;&lt;span&gt;CONFIG_ARM_FPU=y&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;but when i do it&amp;#39; s unkown symbol so i guess&amp;nbsp;&lt;span&gt;Floating Point Unit) if available on your target device&amp;nbsp;&lt;/span&gt;&amp;nbsp;which is nrf52840dk&lt;/p&gt;
&lt;p&gt;.so i stuck in this problem&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interfacing IMU Sensor (LSM6DSL) with i2c</title><link>https://devzone.nordicsemi.com/thread/483331?ContentTypeID=1</link><pubDate>Tue, 14 May 2024 15:03:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f11f7816-9435-4ab3-82f2-fd36e31d17fd</guid><dc:creator>Kazi Afroza Sultana</dc:creator><description>&lt;p&gt;Hello Rania,&lt;/p&gt;
&lt;p&gt;Could you please share your project file so Ican look at the overlay file and the relevant code in the main.c file?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interfacing IMU Sensor (LSM6DSL) with i2c</title><link>https://devzone.nordicsemi.com/thread/482917?ContentTypeID=1</link><pubDate>Sun, 12 May 2024 18:40:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:579f2c01-5ab0-4e79-856b-dcc55aea82e2</guid><dc:creator>rania amara</dc:creator><description>&lt;p&gt;i don&amp;#39;t know&amp;nbsp; if i&amp;#39;m right but i think the probleme have to do with the interrupt pin ,but i don&amp;#39;t know how exactly&amp;nbsp; please correct me if i&amp;#39;m wrong&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interfacing IMU Sensor (LSM6DSL) with i2c</title><link>https://devzone.nordicsemi.com/thread/482582?ContentTypeID=1</link><pubDate>Wed, 08 May 2024 16:09:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f33d3616-5c85-4929-a9d8-490e41564463</guid><dc:creator>rania amara</dc:creator><description>&lt;p&gt;yes i&amp;#39;m sure that&amp;nbsp;&amp;nbsp;&lt;span&gt;I2C pins are working fine but still i&amp;#39;m&amp;nbsp;facing the same problem&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interfacing IMU Sensor (LSM6DSL) with i2c</title><link>https://devzone.nordicsemi.com/thread/481812?ContentTypeID=1</link><pubDate>Fri, 03 May 2024 13:32:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:643c2fea-607e-441c-a37f-efb5ef93d320</guid><dc:creator>Kazi Afroza Sultana</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Have you seen any activity on the I2C pins? Did you use any logic analyzer or oscilloscope to see any activity on the I2C pins?&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;You may try to use other I2C pin to check if that works?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>