Pixy camera and arduino uno!!!

Talk about Arduino board, sheilds. Sharing Arduino projects, program, problems, solutions, suggestions..... many more, all are welcome.

Pixy camera and arduino uno!!!

Postby azril1109 » Tue Jan 12, 2016 6:14 pm

hye, i have project with pixy cmucam.. it was fantastic when see the robot move wisely.. but i have problem..
this coding detect 1 colour only.. i have try modify to 2 signiture but fail.. i need your opinion on how to detect 2 colour at once.. i give u example of coding. :D :D :D :D
CODE: SELECT_ALL_CODE
#include <SPI.h> 
#include <Pixy.h>

Pixy pixy;

int signature = 0;
int x = 0;                     
int y = 0;                     
unsigned int width = 0;         
unsigned int height = 0;       
unsigned int area = 0;
unsigned int newarea = 0;
int Xmin = 70;                 
int Xmax = 200;                 
int maxArea = 0;
int minArea = 0;
int motor1 = 4;                 
int enable1 = 5;               
int motor2 = 7;                 
int enable2 = 6;               
int Speed = 70;                 
static int i = 0;

void setup()
{
  pinMode(motor1, OUTPUT);
  pinMode(motor2, OUTPUT);
  pinMode(enable1, OUTPUT);
  pinMode(enable2, OUTPUT);
  Serial.begin(9600);
  Stop();
  pixy.init();
}

void loop()
{
  while(millis()<5000)
  {
    scan();
    area = width * height;
    maxArea = area + 1000;
    minArea = area - 1000;
  }

    scan();

  if(signature == 2)
  {
    newarea = width * height;
   
      if (x < Xmin)
      {     
       left();
      }
      else if (x > Xmax)
      {
       right();
      }
      else if(newarea < minArea)
      {
       forward();
      }
      else if(newarea > maxArea)
      {
       backward();
      }
     
      //else stop
      else
      {
        Stop();
      }
   }
   else
   {
    Stop();
     }
}

void backward()//backward
  {
  digitalWrite(motor1, LOW);
  digitalWrite(motor2, LOW);
  analogWrite(enable1, Speed);
  analogWrite(enable2, Speed);
  }

void forward()//forward
  {
  digitalWrite(motor1, HIGH);
  digitalWrite(motor2, HIGH);
  analogWrite(enable1, Speed);
  analogWrite(enable2, Speed);
  }

void right()//turn right
  {
  digitalWrite(motor1, HIGH);
  digitalWrite(motor2, LOW);
  analogWrite(enable1, Speed);
  analogWrite(enable2, Speed);
  }

void left()//turn left
  {
  digitalWrite(motor1, LOW);
  digitalWrite(motor2, HIGH);
  analogWrite(enable1, Speed);
  analogWrite(enable2, Speed);
  }

void Stop()//stop
  {
  digitalWrite(enable1, LOW);
  digitalWrite(enable2, LOW); 
  }
void scan()
  {
  uint16_t blocks;
  blocks = pixy.getBlocks();
  signature = pixy.blocks[i].signature;   
  x = pixy.blocks[i].x;                   
  y = pixy.blocks[i].y;                   
  width = pixy.blocks[i].width;           
  height = pixy.blocks[i].height;         
  }
azril1109
Freshie
 
Posts: 5
Joined: Tue Jan 12, 2016 6:01 pm

Re: Pixy camera and arduino uno!!!

Postby Apis210 » Thu Jan 14, 2016 8:48 am

Hi, try refer to this article.
Apis210
Apprentice
 
Posts: 32
Joined: Tue Dec 01, 2015 4:13 pm

Re: Pixy camera and arduino uno!!!

Postby azril1109 » Thu Jan 14, 2016 1:29 pm

thanks for u reply.. i have see the article that u give to me but its same.. my diy cannot seen or move according my statement.. if the statement can loop to another condition can be sure?for example, i put 2 signature and put 2 signature in difference condition.. 1 signiture ti forward and 1 signature tu reverse. but in this coding, they looping in 1 signature only.. they cannot run one per one condition..
azril1109
Freshie
 
Posts: 5
Joined: Tue Jan 12, 2016 6:01 pm

Re: Pixy camera and arduino uno!!!

Postby Apis210 » Thu Jan 14, 2016 3:26 pm

Have you teach your pixy camera to detect that object or colour?
Apis210
Apprentice
 
Posts: 32
Joined: Tue Dec 01, 2015 4:13 pm

Re: Pixy camera and arduino uno!!!

Postby azril1109 » Sat Jan 16, 2016 5:09 pm

i have teach but usefull.. they can teach one only..
CODE: SELECT_ALL_CODE
if(signature == 2)
{
newarea = width * height;

if (x < Xmin)
{
left();
}
else if (x > Xmax)
{
right();
}
else if(newarea < minArea)
{
forward();
}
else if(newarea > maxArea)
{
backward();
}

//else stop
else
{
Stop();
}
}
else
{
Stop();
}
}


this can detect one only.. but i double up the coding, the pixy cannot teach... why?
and on arduino library, 'for' stand what function?
azril1109
Freshie
 
Posts: 5
Joined: Tue Jan 12, 2016 6:01 pm

Re: Pixy camera and arduino uno!!!

Postby suadanwar » Mon Jan 18, 2016 10:37 am

Hi Azril1109,

Firstly, you have to teach the pixy camera the new signature colour. For example, red for signature 1 and then orange for signature 2. Please teach the pixy according to this tutorial http://tutorial.cytron.com.my/2015/08/28/colour-tracking-mobile-robot-pixy/ step by step. If you had teach it properly using the PixyMon software, you will see that the pixyCam can detect both colour. It will show red colour s=1 and orange s=2. If not, you are not teaching it properly and you cannot proceed with arduino programming.

Pixy can learn up to seven color signatures. Here are the signatures in order:
Red
Orange
Yellow
Green
Cyan (light blue)
Blue
Violet

Only this colour can be detected by the Pixy camera.

Next, you just have to make two condition for the Arduino Programming. For example:

CODE: SELECT_ALL_CODE
if(signature == 1)
{
newarea1 = width1 * height1;

if (x1 < Xmin1)
{
left();
}
else if (x1 > Xmax1)
{
right();
}
else if(newarea1 < minArea1)
{
forward();
}
else if(newarea1 > maxArea1)
{
backward();
}

//else stop
else
{
Stop();
}
}
else
{
Stop();
}
}

if(signature == 2)
{
newarea2 = width2 * height2;

if (x2 < Xmin2)
{
left();
}
else if (x2 > Xmax2)
{
right();
}
else if(newarea2 < minArea2)
{
forward();
}
else if(newarea2 > maxArea2)
{
backward();
}

//else stop
else
{
Stop();
}
}
else
{
Stop();
}
}

All the signature that you declare must have their own variable declaration. I think this should work for your programming. :)
suadanwar
Greenhorn
 
Posts: 3
Joined: Mon Aug 24, 2015 4:24 pm

Re: Pixy camera and arduino uno!!!

Postby azril1109 » Mon Jan 18, 2016 12:56 pm

Hi suadanwar, thanks for your poasting..

My another question, does pixy can read on arduino on another communication protocol like uart and i2c?
What difference the coding on spi,uart or i2c on communication pixy.

I beginning on programming so i lack on coding as well..
Thanks for your reply.
azril1109
Freshie
 
Posts: 5
Joined: Tue Jan 12, 2016 6:01 pm

Re: Pixy camera and arduino uno!!!

Postby suadanwar » Wed Jan 20, 2016 12:52 pm

Hi azril1109,

Based on your question "does pixy can read on arduino on another communication protocol like uart and i2c?", the answer is yes. This is based on the article that i found here: http://www.cmucam.org/projects/cmucam5/ ... ting_Guide . You may refer to this link for more information.
suadanwar
Greenhorn
 
Posts: 3
Joined: Mon Aug 24, 2015 4:24 pm

Re: Pixy camera and arduino uno!!!

Postby azril1109 » Wed Jan 20, 2016 11:31 pm

hi suadanwar, thanks for replying.

i have see their website. but i confusing what difference UART and SPi.. and the source code for UART on arduino cannot add on my arduino library..

thanks for replying.
azril1109
Freshie
 
Posts: 5
Joined: Tue Jan 12, 2016 6:01 pm

Re: Pixy camera and arduino uno!!!

Postby adam4667 » Tue Mar 08, 2016 10:36 pm

assalam azril.. boleh bagi no phone??? kita projek yang sama dekat puo tapi saya pelajar kss. tq
adam4667
Fledgling
 
Posts: 1
Joined: Sun Mar 06, 2016 3:00 pm

Next

Return to Arduino Based

Who is online

Users browsing this forum: No registered users and 22 guests