<< return to Pixycam.com

question concerning analogue value for X and Y position of a single object

Hello,

First of all great project. I was to late to be a backer but I preordered a Pixy.

As a teacher electrical engineering I am very interested in the possibility of Pixy to output an analogue value for the X and Y position of a single object. For my students this is very easy to understand and very easy to hook Pixy up to a PLC (Programmable Logic Controller as we call it in Belgium).

When I read the wiki I am a little bit confused however. If you use the analogue values for positioning of one object I read the following:

  • analog/digital x - this will output the x value of the largest detected object as an analog value between 0 and 3.3V (pin 3). It also outputs whether an object is detected or not as a digital signal (pin 1 of the I/O connector).
  • analog/digital y - this will output the y value of the largest detected object as an analog value between 0 and 3.3V (pin 3). It also outputs whether an object is detected or not as a digital signal (pin 1 of the I/O connector).

I read that pin 3 is used for the X and y position of the object. Does this mean that Pixy can only send only one position (X or Y)? And thus is it not possible to have the X and Y position at the same time through two analogue values?

Thanks in advance for your answer,
Bart

Hi Bart,

Glad to hear you’re excited for Pixy! Unfortunately, we only have 1 analog output, so we have a mode for “output x to pin 3” and another mode for “output y to pin 3”, but not both. We may be able to do some more advanced methods to get both X and Y output at the same time (or close), but we haven’t experimented with anything yet.

Thanks!

Scott

Hello Scott,

Thanks for the reply. No problem, I’ll solve that with an arduino that communicates with Pixy and puts out two analogue voltages for the X and Y axis.

Looking forward to experimenting with Pixy,
Bart

Hello Scott,

I just realized that the arduino uno does not have analogue outputs, only PWM’s.

I assume that pixy is also compatible with the arduino due that has two true analogue outputs. Am I correct in this compatibility (pixy with the arduino due)?

Thanks in advance,
Bart

Hi Bart,

Just so I’m clear on this, are you saying you would receive the X and Y coordinates at the Arduino using the SPI interface, and then output them as analog from the Arduino?

I have not tested on an Arduino Due (only Duemilanove), although Rich may have, so I’ll ask him. I would assume it will work since our Arduino Pixy library uses the standard Arduino SPI library, which should have the same protocol for both boards. Hope this helps.

Scott

Hello Scott,

Indeed I would like to receive the X and Y coordinates at the Arduino using the SPI interface and then output them as analog from the Arduino due. And since the Due has two true analogue outputs it is easy to connect to a PLC (Programmable Logic Controller) for my students.

Should you be interested I have included two small programs to do this. I would really appreciate if you could look if these programs make any sense. I would like to show off pixy at my school on the openschoolday but I will only have five days between the arrival of pixy and the openschoolday itself. And I am sure pixy will have a big WOW-factor with the students :-). But since you are very busy I completely understand if you can’t find the time. Anyway below you can find a description of the programs.

The first program is “pixy_1_object.ino” for detection of one object. If pixy detects one object the arduino due lets the user know that an object is detected by making pin 22 HIGH and exporting two analogue values for positioning via DAC0 en DAC1.
If no object is detected pin 22 is LOW and the analogue values don’t have to be changed since they can be ignored (pin 22 is LOW). Then a delay follows of 50ms so I am sure that the PLC can follow the arduino (just to make sure)

The second program is “pixy_2_objects.ino” for detection of two objects.
If pixy detects the first object the arduino lets the user know that the first object is detected by making pin 22 HIGH (and pin 23 LOW) and exporting two analogue values for positioning via DAC0 en DAC1. Than a delay of 50ms follows to make sure the connected PLC can follow the arduino.
If pixy detects the second object the arduino lets the user know that the second object is detected by making pin 23 HIGH (and pin 22 LOW) and exporting two analogue values for positioning via DAC0 en DAC1. Then a delay of 50ms follows to make sure the connected PLC can follow the arduino.
If no object is detected pin 22 en pin 23 are LOW and the analogue values don’t have to be changed since they can be ignored (pin 22 and 23 are LOW). Then a delay again follows of 50ms so I am sure that the PLC can follow the arduino (just to make sure)

Thanks in advance,
Bart

Hi Bart,

I haven’t had a chance to actually run your programs, but here are some notes from looking at the code:

It looks like you have a slight misunderstanding of the SPI communication. The blocks sent over SPI aren’t necessarily different objects (although they COULD be). Depending on how well the training worked, a single object could be detected as a single block, or it could be split up in to multiple blocks. This means the first two blocks in the ‘blocks’ array could both be of the same object (but maybe different regions of that object).

If you want to ensure you’ve detected two separate objects, I’d suggest you train pixy on two different color models (i.e. a blue ball and a red ball). Then in your code look at the block ‘signature’ (aka model ID) to see which object this block pertains to. Then instead of checking “if (j==0)” you might do something like “if (blocks[j].signature==0)” to test for the first object.

Does this make sense? Hope this helps! Good luck!

Scott

Hello Scott,

For testpurpose I indeed wanted to use objects with one unique colour. So if I understand you correctly the programs should work but I’ll adapt them a little bit according to your advice and will post them soon for other users.

And if the camera works as well as your site shows I know there will be a lot of schools interested in de the camera. So be prepared for some more orders :slight_smile:

Greetings,
Bart

Cool project! You can also get analogue voltage from a pwm pin if you run it through a low pass filter with the pwm frequency turned up to 62.5khz. It would be much cheaper to use an arduino uno instead of the arduino due if you need lots. I personally can’t wait to get my pixy.

http://playground.arduino.cc/Main/TimerPWMCheatsheet#.UzFuAPVFDFo

If you are interested I could dig out some code and component values that worked well for me.

Hello Carl,

I now that is possible but I never tried it out. It woud be interesting to see the code and components you use to convert a pwm-signal to an analogue signal and indeed wat cheaper. I always think in function of what is easy for my students to understand and analogue values are far easier to work with.

So if you will please post your code and component values.

And for pixy, I think it will open a world for schools and amateurs. It’s easy and very cheap compared to professional vision systems. This is for instance a project of my class for next schoolyear:

Normally I would say it is to complex looking at the arduino code. But with pixy it will be much easier.

Greetings,
Bart

Hello Carl and Scott,

As attachment you can find the two adapted programs “pixy_1_object.ino” and “pixy_2_objects.ino”

In “pixy_1_object.ino” I assume pixy is trained to detect an object of one specific colour. And I also assume there is no more than one such object in the image. If such an object is detected the position is outputted as two analogue voltages from an arduino due (DAC0 and DAC1) Pin 22 also signals the detection of such an object.

In “pixy_2_objects.ino” I assume pixy is trained to detect an objects of two specific colours. And I also assume there are no more than two such objects in the image (one of each colour). If such an object is detected the position is outputted as two analogue voltages from an arduino due (DAC0 and DAC1) and a digital output (22 or 23) tells what object it is (what coloursignature).

I haven’t tried the program since my pixy hasn’t arrived yet. If anybody tries the program please let me know if it works.

Greetings,
Bart

Hello everybody,

For anybody who would be interested in the two programs “pixy_1_object.ino” and “pixy_2_objects.ino”, please look at this forum. There you can find a working version of the programs.

http://cmucam.org/boards/9/topics/3321

Greetings,
Bart