How do I read from a correct address of LIDAR using Arduino in I2C?

  arduino, arduino-nano, c++, lidar

I need to read the distance data from a lidar in I2C using an Arduino Nano. Currently, this is the code I’ve written.

unsigned int readDistance()
{
  unsigned int dist = 0 ; // LiDAR actually measured distance value. static so we can return previous dist
  
  // step 1: instruct sensor to read echoes
  Wire.beginTransmission(0x10) ; // transmit to device 0x10
  Wire.write(2) ; // sets distance data address (addr)
  Wire.write(3) ; // sets distance data address (addr)
  Wire.endTransmission() ; // stop transmitting
  
  // step 2: wait for readings to happen
  delay(100) ; // datasheet suggests at least 100ms
  
  // step 3: request reading from sensor
  Wire.requestFrom(0x10, 2) ; // request 2 bytes (DIST_L, DIST_H) from slave device #0x10
  dist = Wire.read() ; dist += Wire.read() << 8; // calculate distance value, bit shift high distance
  return dist ; // return updated dist
}

But I have a feeling I’m requesting from the wrong data address’, since I’m not getting the results I expect (ie. varying distance data). Furthermore, I used an I2C scanner which 100% confirms the lidar is on the (default address) of 0x10.

Datasheet of (TF02 Pro): https://www.unmannedtechshop.co.uk/wp-content/uploads/2020/01/TF02-Pro-Product-Manual-Alpha.pdf

Question: am i reading from the right data address
Any help would be appreciated.

Source: Windows Questions C++

LEAVE A COMMENT