communicate via avr i2c

Added by Mohammad Rgohani 4 months ago

hi,
recently i received my pixy and i want to hook it with my robot using atmega64 i2c communication.
but i have problem figuring out what to do.

this is my Getword function:(my pixy address is 0xD0)

int GetWord(){

unsigned char byte1=0;
unsigned char byte2;
int word;
i2c_start();
i2c_write(0xD1);
byte1=i2c_read(0);
byte2=i2c_read(0);
i2c_stop();
word= byte2*256 + byte1;
return word;

}

but it only returns 255

tanks for your help;


Replies (1)

RE: communicate via avr i2c - Added by Edward Getz 4 months ago

Hello Mohammad,
I don't know anything about your platform, but that looks like an odd set of calls to send/receive i2c data. What does the i2c_read argument do?

Other things to check -- you need to change the data out port to i2c and set the i2c address. Note that the i2c address on the configuration screen is for read and write, so the value is actually divided by 2 (0xD0/2 = 0x68). It looks like you are using a different i2c address convention where 0xD1 for write and 0xD0 for read. Try 0x68 for Pixy's address.

Also be sure you are in "default" mode (not cooked) when testing communications. This video does a good job of explaining:

https://youtu.be/EFPHThBUm2o

Hope this helps!

Edward

(1-1/1)