Can't get data using Arduino through I2C bus

Hi All,
I am new here with a little question. Hope you guys can give me a little hint.

I try to hook up a senor with Arduino through I2C bus, but I can only get "0" value when I perform the code below:

#include "Wire.h"

#define address 0x10
//sensor slave address.
#define delayC 100

#define baudrate 9600

void setup()
{
Wire.begin();
Serial.begin(baudrate);
}

void loop()
{
int OpticalFlow;

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:

  1. 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.
  2. Pull-up resistors are needed on the I2C lines- the board does not include any
  3. 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.
  4. Perform an I2C read of a few bytes. The first byte returned should be 17, followed by a few zeros.
  5. 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.
  6. 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.

Wait for your help. Thx a million.

Wire.send("2 65");

That doesn't look right, I think it will send

0x32, 0x20, 0x36, 0x35

Is that the required data? I suspect not.

I haven't used the library so I looked at the documentation .

I would think

byte x[] = {2, 65};
Wire.send(x, 2);

would be closer


Rob

Here is the instruction from sensor userguide:

So have you done all that? What value of pull ups did you use. You are using analogue pins 4 & 5 for the I2C and not the digital ones.

Substitute Wire.send("2 65");

with (assuming those numbers are hex)

Wire.send(0x02);
Wire.send(0x65);

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.

Hi guys, thank you all.

I tried the code:
byte x[] = {2, 65};
Wire.send(x, 2);
It doesn't help.

I am sure I am using the analog 4 and 5, and I doublechecked whether I correctly connected them many times.

The sensor I used is AVR8 or CYE8, which is not widely used so far.

You can find the instruction from the link below:

http://code.google.com/p/centeye-8bit-sensor/downloads/list

You should post a link to the (datasheet for the) sensor that you are using, too.

Sending 65 and 0x65 are two very different things.

Are you sure that you are sending data to the right address?

thank you guys so far.

the datasheet is in the link below:(It is still misleading because the sensor I use is still in development)

http://code.google.com/p/centeye-8bit-sensor/downloads/detail?name=AVR8_v2_Firmware-Instructions_Application-Prototype-1_2010-08-18.pdf&can=2&q=

The first paragraph in section 7 says

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.

It looks to me that each packet needs 3 bytes, ADDR, CMD and PARM.

Also they seem pretty good at using 0x for HEX, so I'd say the 2 and 65 are decimal.


Rob