<?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>Get data from Lidar Lite V3 over I2C (Zephyr os)</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/95394/get-data-from-lidar-lite-v3-over-i2c-zephyr-os</link><description>Hi, 
 I am trying to get the data from the Lidar Lite V3 sensor via the I2C bus. However, I only receive a 0 back. So my question is the implementation generally correct? 
 Lidar V3 datasheet: https://static.garmin.com/pumac/LIDAR_Lite_v3_Operation_Manual_and_Technical_Specifications</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 11 Jan 2023 10:16:07 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/95394/get-data-from-lidar-lite-v3-over-i2c-zephyr-os" /><item><title>RE: Get data from Lidar Lite V3 over I2C (Zephyr os)</title><link>https://devzone.nordicsemi.com/thread/404265?ContentTypeID=1</link><pubDate>Wed, 11 Jan 2023 10:16:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eef08a79-ccbd-4d10-a7cf-cef4ea6f6823</guid><dc:creator>Menon</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Glad to hear it worked&amp;nbsp;&lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/263a.svg" title="Relaxed"&gt;&amp;#x263a;&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Kind Regards,&lt;/p&gt;
&lt;p&gt;Abhijith&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Get data from Lidar Lite V3 over I2C (Zephyr os)</title><link>https://devzone.nordicsemi.com/thread/404199?ContentTypeID=1</link><pubDate>Tue, 10 Jan 2023 21:11:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:857463b3-b41a-4789-8204-dc1f8ceebed7</guid><dc:creator>John Ivan Fox</dc:creator><description>&lt;p&gt;Thank for u help i got it now&amp;nbsp;&lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;For anyone who is interested in the solution. Is not very nice implements, but is works:)&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Overlay file:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;amp;i2c0 {
    status = &amp;quot;okay&amp;quot;;
    clock-frequency = &amp;lt;I2C_BITRATE_FAST&amp;gt;;
};&lt;/pre&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;main.c file:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;lt;zephyr/zephyr.h&amp;gt;
#include &amp;lt;zephyr/device.h&amp;gt;
#include &amp;lt;zephyr/drivers/i2c.h&amp;gt;

#define I2C_DEV_NAME DT_NODELABEL(i2c0)
#define LIDAR_LITE_V3_ADDRESS 0x62
#define REG_DISTANCE 0x8f
#define REG_READ 0x01

#define LIDAR_LITE_V3_ADDRESS 0x62

// Variable to store the distance measurement
uint16_t distance;
uint8_t register_value;

// Function to get the distance
void get_distance(struct device *i2c)
{
    uint8_t reg_distance = REG_DISTANCE;
    uint8_t data[2] = {0};

    // // Send the distance register address
    i2c_write(i2c, &amp;amp;reg_distance, 1, LIDAR_LITE_V3_ADDRESS);
    // Read the two bytes from the Lidar Lite V3 sensor
    i2c_read(i2c, &amp;amp;data, 2, LIDAR_LITE_V3_ADDRESS);

    // Combine the two bytes into a 16-bit distance value
    distance = (data[0] &amp;lt;&amp;lt; 8) | data[1];
}

void read_register(struct device *i2c)
{
    uint8_t reg = REG_READ;

    // set the register 0x01 to read.
    i2c_write(i2c, &amp;amp;reg, 1, LIDAR_LITE_V3_ADDRESS);
    // read the status od the register 0x01
    i2c_read(i2c, &amp;amp;register_value, 2, LIDAR_LITE_V3_ADDRESS);
}

void main(void)
{
    struct device *i2c;
    int ret;

    // Initialize the I2C bus
    i2c = DEVICE_DT_GET(I2C_DEV_NAME);
    if (!i2c)
    {
        printf(&amp;quot;I2C: Device not found.\n&amp;quot;);
        return;
    }
    // initiate sensor
    // for Lidar Lite V3 we have to send 0x04 to the command register before reading distance data
    uint8_t data0[2] = {0x00, 0x04};
    i2c_write(i2c, &amp;amp;data0, 2, LIDAR_LITE_V3_ADDRESS);
    if (ret != 0)
    {
        printf(&amp;quot;I2C: Error while writing to command register.\n&amp;quot;);
        return;
    }

    // configurie the Lidar Sensor
    uint8_t data[2] = {0x02, 0x80};
    // Write the register address and the desired value to the device
    i2c_write(i2c, &amp;amp;data, 2, LIDAR_LITE_V3_ADDRESS);
    // configurie the Lidar Sensor
    uint8_t data1[2] = {0x04, 0x08};
    // Write the register address and the desired value to the device
    i2c_write(i2c, &amp;amp;data1, 2, LIDAR_LITE_V3_ADDRESS);
    // configurie the Lidar Sensor
    uint8_t data2[2] = {0x1c, 0x00};
    // Write the register address and the desired value to the device
    i2c_write(i2c, &amp;amp;data2, 2, LIDAR_LITE_V3_ADDRESS);

    while (1)
    {
        // Read the register 0x01 and check the value of the LSB
        read_register(i2c);
        if (register_value &amp;amp; 0x01)
        {
            printf(&amp;quot;LSB is high\n&amp;quot;);
        }
        else
        {
            printf(&amp;quot;LSB is low\n&amp;quot;);
            // Get the distance measurement from the Lidar Lite V3 sensor
            get_distance(i2c);
            // Print the distance measurement
            printf(&amp;quot;Distance: %d cm\n&amp;quot;, distance);
        }

        // for Lidar Lite V3 we have to send 0x04 to the command register 0x00 before reading distance data
        i2c_write(i2c, &amp;amp;data0, 2, LIDAR_LITE_V3_ADDRESS);

        k_sleep(K_MSEC(100));
    }
}&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Get data from Lidar Lite V3 over I2C (Zephyr os)</title><link>https://devzone.nordicsemi.com/thread/404083?ContentTypeID=1</link><pubDate>Tue, 10 Jan 2023 12:29:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b6ee6ee3-88e3-4d91-97fd-e3db49512a5f</guid><dc:creator>Menon</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;First of all I am not familiar with this sensor. But the registers you mentioned in the program looks okay for&amp;nbsp; me from the data sheet. In the overlay file you need to mention the sensor as child node to the i2c controller (depending on which i2c you have used). You need to add something like below in the overlay file.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;amp;i2c0 {        // depending on your i2c controller
    
    lidar: lidar@62{
        compatible = &amp;quot;i2c-device&amp;quot;;
        reg = &amp;lt; 0x62 &amp;gt;;
        label = &amp;quot;LIDAR&amp;quot;;
    };
};

// This is just a reference&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Take a look at this &lt;a href="https://academy.nordicsemi.com/lessons/lesson-6-serial-com-i2c/"&gt;tutorial from Nordic&lt;/a&gt; which explains the interfacing of a digital temperature sensor via I2c. In this they mention how you can edit and update the overlay and prj config.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Kind Regards,&lt;/p&gt;
&lt;p&gt;Abhijith&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Get data from Lidar Lite V3 over I2C (Zephyr os)</title><link>https://devzone.nordicsemi.com/thread/403640?ContentTypeID=1</link><pubDate>Fri, 06 Jan 2023 15:54:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b05da1fd-1237-4d93-8ed2-6d0711bd2412</guid><dc:creator>John Ivan Fox</dc:creator><description>&lt;p&gt;Sure :)&lt;/p&gt;
&lt;p&gt;I use the board nRF52840 DK and the nRF Connect SDK v2.2.0&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Get data from Lidar Lite V3 over I2C (Zephyr os)</title><link>https://devzone.nordicsemi.com/thread/403623?ContentTypeID=1</link><pubDate>Fri, 06 Jan 2023 14:53:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ecb004da-11e8-40d5-957a-922cc14f0d6a</guid><dc:creator>Menon</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Letting you know I have been assigned to this case.&lt;/p&gt;
&lt;p&gt;Could you please share the DK and SDK version you are trying with.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Kind Regards,&lt;/p&gt;
&lt;p&gt;Abhijith&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>