Wire.beginTransmission(address);
//start the transmission
Wire.send("2 65"); // that comes my problem. I was asked to send two command in one I2C packet, which I don't know how to achieve
Wire.endTransmission();
//end the transmission
Wire.requestFrom(address, 1);
// Firstly I just want to see whether I can get some useful values
OpticalFlow = Wire.receive();
Serial.println(OpticalFlow) ;
delay(delayC);
}
Here is the instruction from sensor userguide:
The primary interface will be with I2C. The sensor will serve as an I2C/TWI slave. Hook up the sensor to the host device that serves as the I2C/TWI master. The following four lines need to be connected: GND, PWR (preferably about 4.5V to 5V), SCL, and SDA. These four signals form a continuous line on the 0.1" array of holes.
Pull-up resistors are needed on the I2C lines- the board does not include any
The sensor's address is 7-bit 0x10 e.g. decimal 16. This means 0x20 is sent for write, and 0x21 is sent for read.
Perform an I2C read of a few bytes. The first byte returned should be 17, followed by a few zeros.
Send the following two bytes to the sensor: 2 and 65. Send these in one I2C/TWI send packet. This tells the sensor to output optical flow values.
Perform an I2C read of up to six bytes. Byte 1 = X optical flow, Byte 2 = Y optical flow, Byte 3 = X cumulative optical flow, Byte 4 = Y cumulative optical flow, Bytes 5 and 6 = running average optical flow X and Y.
My MAIN PROBLEM is how to send two byte in one I2C packet.
it would also help if you mentioned which sensor you are using. There are a few I2C devices that will not work with the current Wire library due to issues with mandatory repeated start bits.
Note that each "send"
or "receive" command or data set must be sent in its own I2C packet, and the I2C
address is not listed, i.e. if the sensor's address is 32 and the instructions below say
to send 2,65, then you must do start condition, send 32, send 2, send 65, and stop
condition.
No idea what "do start condition" and "do stop condition" mean, but it sure looks to me like sending 2 values is not sufficient.
Looks like the datasheet is using decimal format instead of hex. Instead of the two wire sends using 0x02 and 0x65 just try using 2 and 65 (no quotes).
I guess the instruction is not specific used for Arduino, maybe in other devices we need to generate a start signal.
When I looked at other similiar code, they just use the code " Wire.beginTransmission" to start up.
The I2C address is 0x10. It's listed in page 1. I also consulted to the company stuff, who told me the address is right.