Hello Scott,
thanks for your response!
Alright, This works to me:
uint16_t pixy_getWord(uint8_t adr)
{
uint16_t word = 0;
i2c_start(adr + I2C_READ);
word += i2c_readAck(); //msb
word += (uint16_t)(i2c_readNak()<<8); //lsb
i2c_stop();
return word;
}
But I don’t really understand how the protocol and especially the Arduino Pixy Library (that, unfortunately, has absolutely no ducumentation and comments…) works.
The arduino example program works well, but my implementation does not. I looked at the raw words from the pixy and printed them into the arduino serial monitor (and, with the same result, on my other, not working implementation). This is the result. The arduino program and PixyMon return me four detected blocks, but how is that possible, when there is always two times the “AA55” word? My library sees this as a new frame, just as the documentation says;
Hex output:
1D4 4 BD 5C 6A 4D *AA55 AA55* 1D6 4 BD 5C 6C 4D *AA55*
142 4 63 50 37 54 *AA55 AA55* 1D6 4 BD 5D 6A 4E AA55
AA55 1D4 4 BD 5D 6A 4C *AA55 AA55* 1D4 4 BD 5C 6A 4D
AA55 AA55 1D5 4 BD 5D 6A 4D *AA55 AA55* 1D4 4 BC 5C 6B
4D *AA55 AA55* 1D6 4 BC 5D 6B 4E *AA55 AA55* 1D4 4 BC 5C
6B 4D *AA55 AA55* 1D6 4 BD 5D 6A 4E *AA55 AA55* 1D5 4 BC
5D 6B 4D *AA55 AA55* 1D5 4 BC 5D 6B 4D *AA55 AA55* 1D6 4
BC 5D 6B 4E *AA55 AA55* 1D7 4 BD 5D 6B 4E *AA55 AA55* 1D4
4 BC 5D 6B 4C *AA55 AA55* 1D6 4 BD 5C 6C 4D *AA55 AA55* //and so on...
1D6 4 BD 5C 6C 4D AA55 AA55 1D4 4 BC 5C 6B 4D AA55
AA55 1D8 4 BD 5D 6C 4E AA55 AA55 1D4 4 BD 5C 6A 4D
AA55 AA55 1D4 4 BD 5D 6A 4C AA55 AA55 1D4 4 BD 5D 6A
4C AA55 AA55 1D5 4 BD 5C 6B 4D AA55 AA55 1D5 4 BD 5C
6B 4D AA55 AA55 1D5 4 BD 5C 6B 4D AA55 AA55 1D6 4 BC
5D 6B 4E AA55 AA55 1D4 4 BD 5D 6A 4C AA55 AA55 1D6 4
Shouldn’t it be like this for four objects?
AA55
x x x x x x AA55
x x x x x x AA55
AA55 //Start of new frame?
x x x x x x AA55
x x x x x x AA55
x x x x x x AA55
x x x x x x AA55
AA55
x x x x x x AA55
x x x x x x AA55
x x x x x x AA55
x x x x x x AA55
etc.
What do I understand wrong?
Thanks and regards
Jan
EDIT:
Ok, this is really strange. It seems like this has something to do with the timing. I think there may be a bug in the PixyCam Firmware!?
If I connect the cam with an Arduino and upload the I2C example, the amount of the detected outputs shrinks from 5 (there are 5 LED dots to track) to 1 with the following void loop:
void loop()
{
int j;
uint16_t blocks;
char buf[32];
blocks = pixy.getBlocks();
if (blocks)
{
sprintf(buf, "Detected %d:\n", blocks);
Serial.print(buf);
for (j=0; j<blocks; j++)
{
sprintf(buf, " block %d: ", j);
Serial.print(buf);
pixy.blocks[j].print();
}
for(uint8_t i = 0; i < blocks; i++) //Output the amount of detected objects via the led
{
digitalWrite(13, HIGH); delay(50);
digitalWrite(13, LOW); delay(200);
}
}
delay(1000);
}
Output:
Detected 5:
block 0: sig: 4 x: 98 y: 70 width: 44 height: 69
block 1: sig: 4 x: 163 y: 85 width: 45 height: 68
block 2: sig: 4 x: 218 y: 90 width: 44 height: 66
block 3: sig: 4 x: 35 y: 60 width: 31 height: 64
block 4: sig: 4 x: 7 y: 55 width: 12 height: 55
Detected 5:
block 0: sig: 4 x: 98 y: 70 width: 44 height: 69
block 1: sig: 4 x: 163 y: 85 width: 45 height: 68
block 2: sig: 4 x: 218 y: 89 width: 43 height: 67
block 3: sig: 4 x: 35 y: 60 width: 31 height: 66
block 4: sig: 4 x: 7 y: 55 width: 12 height: 55
Detected 4:
block 0: sig: 4 x: 98 y: 70 width: 44 height: 70
block 1: sig: 4 x: 163 y: 85 width: 45 height: 67
block 2: sig: 4 x: 218 y: 90 width: 44 height: 66
block 3: sig: 4 x: 35 y: 60 width: 31 height: 64
Detected 1:
block 0: sig: 4 x: 98 y: 70 width: 44 height: 69
Detected 1:
block 0: sig: 4 x: 97 y: 70 width: 43 height: 70
Detected 1:
block 0: sig: 4 x: 98 y: 70 width: 44 height: 69
Detected 1:
block 0: sig: 4 x: 98 y: 70 width: 44 height: 69
Detected 1:
block 0: sig: 4 x: 98 y: 70 width: 44 height: 69
Detected 1:
block 0: sig: 4 x: 98 y: 70 width: 44 height: 69
Detected 1:
block 0: sig: 4 x: 97 y: 70 width: 43 height: 68
Detected 1:
block 0: sig: 4 x: 98 y: 70 width: 44 height: 69
Detected 1:
block 0: sig: 4 x: 98 y: 70 width: 44 height: 69
What do you say?