Lidar-Lite and Labjack : 2 bytes I2C read (follow-up) | LabJack
 

Lidar-Lite and Labjack : 2 bytes I2C read (follow-up)

2 posts / 0 new
Last post
francoisdt
francoisdt's picture
Lidar-Lite and Labjack : 2 bytes I2C read (follow-up)
Hi, I started this topic in the previous forum here : http://forums.labjack.com/index.php?showtopic=7168#entry24296 But it was close before I solved the problem. I repost the whole question : Hi, I'm trying to get the LidarLite laser range finder to work with my Labjack UE9. This range finder outputs the distance measurement on two bytes via an I2C bus. I'm therefore using the low level command for I2C read. As suggested in the LidarLite's documentation ( http://kb.pulsedligh...ick-start-guide ), I'm first sending a command contaning two data bytes : 0x00 and 0x04, the first being the register to write, and the second the value to write, corresponding to an request for a measurement cycle. Then, and it's where it gets tricky, I have to read the measured value. The guide suggests to either read the high byte in a first register (0x0f), and the low byte in an other register (0x10), or to perform a 2-byte read on register 0x8f. I successfully realized the first method, by sending a first I2C command containing a single byte (0x0f, the first register address), reading the response containing the high byte, then sending a second I2C command containing the second register address and reading the low byte in the response. Problem is, I can't do this to quickly to avoid overpolling the I2C bus, so I'd really like to use the second method, and read the 2 bytes in a single call. But, when I tried to build an I2C command asking to read 2 bytes, and containing only 0x8f as command byte, I only get the low byte of the measurement in return, and a second value that does'nt make sense. Is there a way to specify that I want a two byte read starting from a specific register? Because on Arduino, there is a dedicated function taking as argument the register to read from, and the number of bytes to read... So, in the meantime, I tried to perform a 2 bytes read from 0x0f, but I only get 0, 1, 15 or 255 as output. When I perform a two-bytes read on 0x8f, I get in the first received cell the measured distance in cm, with what seems to be a 255-modulo (correct distance if below 255cm, if above it seems to be the result of the modulo). And in the second cells, values oscillating between 179 and 185 most of the time.
LabJack Support
labjack support's picture
Sorry about your topic

Sorry about your topic getting closed. Probably related to out site being migrated.

Is there a way to specify that I want a two byte read starting from a specific register? Because on Arduino, there is a dedicated function taking as argument the register to read from, and the number of bytes to read...

Reading two bytes in succession is a common I2C operation. On the labjack it is as simple as writing one byte to specify the starting address, then reading two. You can set the options to specify the type of restart, restart is how I2C switches from write to read in the middle of a transaction.

If that does not help we will need an O-Scope or Logic Analyzer capture to figure out what is going on.