<< return to Pixycam.com

Pixymon/Arduino: different number of blocks

Hi All,

I have a problem with the Arduino missing objects.

My Pixy is directed at a white panel with 4 colored squares, to which it has been trained. Pixymon shows 4 objects being tracked. My Uno Serial Monitor suggests 4 objects are being tracked on the first loop pass, then either 1 or 2 objects on subsequent passes.

Conspicuously, if there is only 1 block found, it is always the signature 1 block; 2 blocks are always signatures 1 and 2. This is true even if I set the signatures to different colors.

Any ideas what’s going on?

Thanks,
Tom

Code:
//
#include <SPI.h>
#include <Pixy.h>

Pixy pixy;

void setup()
{
Serial.begin(9600);
Serial.print(“Starting…\n”);
pixy.init();
}

void loop()
{
int i = 0;
uint16_t blocks;
blocks = pixy.getBlocks();

if (blocks>0)
{
Serial.print("\t blocks = “);
Serial.print(blocks);
for (i=0; i < blocks; i++) {
Serial.print(”\t signature[");
Serial.print(i);
Serial.print("] ");
Serial.print(pixy.blocks[i].signature);
}
Serial.println();
}
delay(100);
}
//

Hello Tom,
Be careful when printing debugging text from the Arduino. Printing to the serial console is really slow and takes significant time, especially if you try to print debugging text for every Pixy frame. Pixy block data will be lost. There are several ways around this. Probably the easiest is to print debugging text for every 25th or 50th frame, like in the hello_world example. Let me know how it goes.

Edward

Hi Edward,

Ah, I see. And by the same reasoning the delay(100) is bad.

I’m not sure how the data is lost. With delays longer than the frame rate of the camera, how come you don’t simply get a mixture of data from different frames? I figured with a static image it wouldn’t matter.

Anyway, thanks for the fix!

Tom

Hello Tom,
Regarding the lost data, if no one reads the data from Pixy, it’s lost. Pixy generates lots of data and it’s assumed that data from previous frames are not useful when new frame data is available, so old data is discarded.

Edward