It is my first time to use Arduino IDE, I have some C and C++ experiences, however I have 20 years LabVIEW experience., which might helps me to understand IDE quickly. Currently I am working on a Sparkfun RedBoard Qwiic, which is compatible with Arduino IDE. The board uses ATmega328P chip. I have a I2C sensor device, so I just need to use I2C to get data from the sensor device via the Redboard.
The Wire library is a major tool for I2C communication. There is a sample code, SRFRange finder, preloaded in the IDE. It is not clear in reading data from data register. For example, the SRF10 device address is 112 (0x70), the data address is 2 (0x02) for high bit and 3 (0x03) for low bit, total of 16-bit data. the sample code does not specify the data address 0x02 and 0x03 (see the attached full code), how can it read data from the right data registers via the device address 112?
// step 4: request reading from sensor
Wire.requestFrom(112, 2); // request 2 bytes from slave device #112
// step 5: receive reading from sensor
if (2 <= Wire.available()) { // if two bytes were received
reading = Wire.read(); // receive high byte (overwrites previous reading)
reading = reading << 8; // shift high byte to be high 8 bits
reading |= Wire.read(); // receive low byte as lower 8 bits
Serial.println(reading); // print the reading
For my sensor, there are 4 channels, each channel uses 2 of 16-bit registers, making a high resolution 32-bit data. so I need to specify which registers to be read for a channel.
Could some one tell me how to code for reading CH2 from register 0x02 and 0x03 using device register 0x2A (decimal 42)?
Thank you
SRF10Range finder.txt (2.03 KB)
SRF10 Ultra sonic range finder.pdf (245 KB)