<< return to Pixycam.com

Pixy / Arduino

Colleagues:

I have just begun working with a Pixie. I am using it in a project with a student in which I would like to set Arduino pins HIGH or LOW depending on object location in the camera’s field of view (i.e., based on midpoint location of a detected object). I assume this could be done embedded IF statements. Can some one point me toward How-to pages, sample codes, or tutorials that would give me a hand in setting this up?

Thanks in advance,

Dr. P

Hello Frederick,
Are you using a microcontroller to talk to Pixy? Or do you wish to use Pixy stand-alone?

Using Pixy stand-alone might require you to modify the firmware. This is possible, but it’s more complicated that using Pixy with an Arduino, for example.

Edward

Edward:

Yes, an Arduino Uno, and Mega. My strength is neurobiology, and building the hardware. I am a novice at the software (to say the least). So, I need some guidance.

As a matter of fact, for my projects, I periodically need brief sketches to kick start what I am doing (which is mostly teaching). Hence, I am considering asking the community if there are individuals whom I could hire to write sketches for me on a contract basis when the need arises.

So, now I need to get a handle on how to write a sketch that says: IF an object has a center (average of the Y values, average if the X values) such that (0<X<2 && 0<Y<2), <set PIN_0 HIGH, delay (500), set PIN_0 LOW>. If the center falls within another range of X,Y values, set the next PIN HIGH for a set amount of time, and so on. Hence, the pins will be activated based on object center location. I assume that this is a simpler variant of the basic servo sketches.

Suggestions?

FRP

Hi Frederick,
It sounds like a pretty simple program. You could modify the hello_world sketch pretty easily, compare the x and y values of the returned block and then set an I/O on the Arduino accordingly.

Do you have any students and/or friends who can program an Arduino? It shouldn’t take them but a few minutes.

Hope this helps!

Edward

Edward:

If you have a moment, would you be kind enough to kick start the process for me by indicating a few lines of code that would be structured to say <If X && Y are certain values, then do this>? I am not clear on how to structure a command based solely on two values (the X and Y) that are components of the blocks that the program is recording.

Thank in advance.

FRP

Good morning.

I am running PixyMon (simultaneously) set to Max Blocks = 1 and Max Blocks per Signature = 1. I cannot constrain the Arduino PinHIGH command to a set of X values. (It flashes irrespective of the X location of the detected object.) Apparently, I am not seeing some error in the code.

Suggestion?

Thanks in advance!


#include 
#include 

Pixy pixy;// This is the main Pixy object

unsigned long tempo;

int centerX; // the name to be used for X value of object center
int centerY; // the name to be used for X value of object center

int Pin2 = 2;
int Pin3 = 3;
int Pin4 = 4;
int Pin5 = 5;

void setup()
{
  Serial.begin(9600);
  Serial.print("Starting...\n");
  pixy.init();

  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);

}

void loop()
{
  static int i = 0;
  int j;
  uint16_t blocks;
  char buf[32];

  blocks = pixy.getBlocks(); //grab blocks

  centerX = pixy.blocks[i].x; // unsure: correct location & syntax?
  centerY = pixy.blocks[i].y; // 

  if (centerX < 200) // when the object is here on the X axis
  {
    if (millis() - tempo <= 500) //
      digitalWrite(Pin4, HIGH); // LED on for 500 ms
  }
  else {
    tempo = millis();
  }
  digitalWrite(Pin4, LOW);
  // If there are detect blocks
  if (blocks)
  { i++;
    if (i % 50 == 0)
    {
      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();
      }

    }
  }

}
// end of if (blocks)

Hello Frederick,
Your program has lots of issues, so it’s hard to know where to start. :frowning: I can tell that you are struggling with C. Unfortunately, this is not really a forum to learn C programming (sorry). I’d try to solicit help from a friend who understands C.

Again, sorry…

Edward

Thanks anyway… I got it straightened out and working. I am now expanding it for a prototype on which I am working.