<< return to Pixycam.com

Pixy only updating data once per second to Arduino

Pixy is sending data to the Arduino once per second. It’s as if the Pixy is getting stuck even though I can see on PixyMon that the detected box is indeed moving around. (Yes, I have PixyMon in “Default Program” mode)

My setup:
PixyMon 1.0.2
Pixy R1.3
Arduino Uno R3
Pixy connected to Arduino with the supplied cable.
Arduino plugged into laptop via USB
Pixy plugged into same laptop via USB
PixyMon running in “Default Program” mode

When I run the “Hello World” program, the Arduino serial monitor updates about ONCE PER SECOND.
Here is a sample of the output:

Detected 1:
block 0: sig: 1 x: 94 y: 99 width: 53 height: 50 angle 0
Detected 1:
block 0: sig: 1 x: 92 y: 97 width: 52 height: 55 angle 0
Detected 1:
block 0: sig: 1 x: 91 y: 98 width: 52 height: 54 angle 0

How do I get 50Hz data as advertised?
I’d be happy with just 4Hz.

Thanks!

Solved!

It appears that for color blob detection, the first blob is BLOCK 1.
BUT… for Color Code detection, the first block is BLOCK 0.

Frustrating, but happy I found the solution.
-Brian

Hi Brian,

Glad you got it figured out. Let us know if you have any other questions!

Scott

I am having the same problem, my Arduino is reading out at about 1Hz as well. From reading the posts, it is not clear how Brian managed to fix this. Any help would be appreciated.

Jeff

The Pixy arduino example limits the rate with this line:

 
    // do this (print) every 50 frames because printing every
    // frame would bog down the Arduino
    if (i%50==0)

It’s there because if you printed every block for every frame, you’d bog down the Arduino and not get all 50 frames. So 1 Hz is the correct rate – it means you are getting 50 sets of results per second.

You can remove of course.

The pantilt example doesn’t have this line…

thanks!

I don’t understand yet -

1.) what is the frame thing for?
of course I want to get the whole amount of data as quick and as complete as possible!

I’m using a TFT screen additonally to display the blocks on it - which is admittedly rather slow (see code below!)

So what to do about this
if (i%50==0)
?
keep it or drop it?

2.) what to do in order to get the data of all the color codes if I trained 7 different ones?
what is the source code like for Arduino to get them?

// pixy-cam LCDTFT monitoring program
// pixyTFTSPI
// Pixy Cam connected by SPI
// version 0008

#include  
#include 
#include 

// UTFT myGLCD(Model,SDA,SCL,CS,RST,RS)
// adjust the model parameter to suit the display module!
UTFT     myGLCD(QD220A,43,42,41,0,40); 
extern   uint8_t   SmallFont[];
uint8_t    ScrRatio;


Pixy pixy;

void setup()
{

  myGLCD.InitLCD();
  myGLCD.setFont(SmallFont);
 
  pixy.init();
  //pixy.blocks[i].x The x location of the center of the detected object (0 to 319)
  //pixy.blocks[i].y The y location of the center of the detected object (0 to 199)
  // Pixy_maxSize/(GLCD_maxSize-frame)
  ScrRatio=max(320/(myGLCD.getDisplayXSize()-20), 200/(myGLCD.getDisplayYSize()-20) )+1;
 
  myGLCD.clrScr(); 
  Serial.begin(19200);
 
}

uint16_t sigcolor( uint8_t signature) {  // <<<<<<<<<<<<<<< customize !! <<<<<<<<<<
  uint16_t color;
  if(signature==1) color=VGA_RED;      // light red
  else
  if(signature==2) color=VGA_AQUA;     // light blue
  else
  if(signature==3) color=VGA_YELLOW;   // just yellow ;)
  else
  if(signature==4) color=VGA_LIME;     // light green
  else
  if(signature==5) color=VGA_FUCHSIA;  // light pink 
  else
  if(signature==6) color=VGA_BLUE;     // dark blue
  else
  if(signature==7) color=VGA_PURPLE;   // dark pink
  else
  color=VGA_WHITE;
  return color;
}
 

char sbuf[240];
#define maxblocks  64
uint8_t    blockS[maxblocks];
uint8_t    blockX[maxblocks];
uint8_t    blockY[maxblocks];
uint8_t    blockW[maxblocks];
uint8_t    blockH[maxblocks];

void loop()
{
  static int i = 0;
  int j;
  uint16_t   nblocks;
  uint8_t    x1,y1,x2,y2; 
 
 
  nblocks = pixy.getBlocks();
 
  if (nblocks)
  {
    i++;
   
    if (i % 10==0)
    {
      myGLCD.clrScr();
      sprintf(sbuf, "Detected %d:\n", nblocks);
      Serial.print(sbuf);
      for (j=0; j<min(nblocks,maxblocks); j++)
      {       
       
        sprintf(sbuf, "  block %d: ", j);
        Serial.print(sbuf);
        pixy.blocks[j].print();   
               
        blockS[j]= pixy.blocks[j].signature;
        blockX[j]= pixy.blocks[j].x;
        blockY[j]= pixy.blocks[j].y;
        blockW[j]= pixy.blocks[j].width;
        blockH[j]= pixy.blocks[j].height;
       
        myGLCD.setColor(sigcolor(blockS[j])); myGLCD.setBackColor(VGA_BLACK);
        x1=blockX[j]-blockW[j]/2;
        x2=blockX[j]+blockW[j]/2;
        y1=blockY[j]-blockH[j]/2;
        y2=blockY[j]+blockH[j]/2;
        myGLCD.drawRect(x1/ScrRatio, y1/ScrRatio, x2/ScrRatio, y2/ScrRatio );
       
        sprintf(sbuf, "%d", blockS[j]); 
        myGLCD.print(sbuf, (x1+10)/ScrRatio,(y1+10)/ScrRatio);
       
      }
    }
  } 
}


//
// begin Pixy cmucam license header
//
// This file is part of Pixy CMUcam5 or "Pixy" for short
//
// All Pixy source code is provided under the terms of the
// GNU General Public License v2 (http://www.gnu.org/licenses/gpl-2.0.html).
// Those wishing to use Pixy source code, software and/or
// technologies under different licensing terms should contact us at
// [email protected]. Such licensing terms are available for
// all portions of the Pixy codebase presented here.
//
// end license header
//

/*
   06.04.2014 v0.1.3 John Leimon
     + Now using pixy.init() to initialize Pixy in setup().
     
    The API consists of one call: getBlocks(), which returns the number of objects Pixy has detected.
    You can then look in the pixy.blocks[] array for information about each detected object
    (one array member for each detected object.)
    Each array member (i) contains the following fields:

    pixy.blocks[i].signature The signature number of the detected object (1-7)
    pixy.blocks[i].x The x location of the center of the detected object (0 to 319)
    pixy.blocks[i].y The y location of the center of the detected object (0 to 199)
    pixy.blocks[i].width The width of the detected object (1 to 320)
    pixy.blocks[i].height The height of the detected object (1 to 200)
    pixy.blocks[i].print() A member function that prints the detected object information to the serial port

*/


/* UTFT API (c) Henning Karlsen

// VGA color palette
#define VGA_BLACK      0x0000
#define VGA_WHITE      0xFFFF
#define VGA_RED         0xF800
#define VGA_GREEN      0x0400
#define VGA_BLUE      0x001F
#define VGA_SILVER      0xC618
#define VGA_GRAY      0x8410
#define VGA_MAROON      0x8000
#define VGA_YELLOW      0xFFE0
#define VGA_OLIVE      0x8400
#define VGA_LIME      0x07E0
#define VGA_AQUA      0x07FF
#define VGA_TEAL      0x0410
#define VGA_NAVY      0x0010
#define VGA_FUCHSIA      0xF81F
#define VGA_PURPLE      0x8010
#define VGA_TRANSPARENT   0xFFFFFFFF

UTFT();
UTFT(byte model, int RS, int WR,int CS, int RST, int SER=0);
void InitLCD(byte orientation=LANDSCAPE);
void clrScr();
void drawPixel(int x, int y);
void drawLine(int x1, int y1, int x2, int y2);
void fillScr(byte r, byte g, byte b);
void fillScr(word color);
void drawRect(int x1, int y1, int x2, int y2);
void drawRoundRect(int x1, int y1, int x2, int y2);
void fillRect(int x1, int y1, int x2, int y2);
void fillRoundRect(int x1, int y1, int x2, int y2);
void drawCircle(int x, int y, int radius);
void fillCircle(int x, int y, int radius);
void setColor(byte r, byte g, byte b);
void setColor(word color);
word getColor();
void setBackColor(byte r, byte g, byte b);
void setBackColor(uint32_t color);
word getBackColor();
void print(char *st, int x, int y, int deg=0);
void print(String st, int x, int y, int deg=0);
void printNumI(long num, int x, int y, int length=0, char filler=' ');
void printNumF(double num, byte dec, int x, int y, char divider='.', int length=0, char filler=' ');
void setFont(uint8_t* font);
uint8_t* getFont();
uint8_t getFontXsize();
uint8_t getFontYsize();
void drawBitmap(int x, int y, int sx, int sy, bitmapdatatype data, int scale=1);
void drawBitmap(int x, int y, int sx, int sy, bitmapdatatype data, int deg, int rox, int roy);
void lcdOff();
void lcdOn();
void setContrast(char c);
int  getDisplayXSize();
int  getDisplayYSize();

*/

Hi,

Thanks for the reply. I would like to read out the positions (in my case there are only four blobs to track) at the full 50 Hz rate. If this is not possible, then how can I at least get access to the 50 different positions recorded over the one second interval? If the device is processing at 50 Hz, then there should be a way to output this information, right?

Jeff

Hi Jeff,
You can get 50 frames per second! :slight_smile:

Just remove the line (described above)

if (i%50==0)

We put it in there because printing all of the detected blocks (there may be 20 or more) 50 times a second from the Arduino’s serial port would really bog things down. (the arduino’s serial port is only 9600 baud) It’s only for printing/debugging. The data is still being sent 50 times per second.

thanks!