<< return to Pixycam.com

I am unable to use pixy.setServos(pan,tilt) from Arduino as expected

Hello,

probably I am missing something very basic here, but I would appreciate any advice.

I am trying to control the pixy servos from Arduino nano R3, using very simple test code base on pixy.setServos(panPos,tiltPos), but I get no movement at all. here is the code:

#include <SPI.h>
#include <Pixy.h>

//pixy
#define X_CENTER 160L
#define Y_CENTER 100L
#define RCS_MIN_POS 0L
#define RCS_MAX_POS 1000L
#define RCS_CENTER_POS ((RCS_MAX_POS-RCS_MIN_POS)/2)

Pixy pixy;

void setup()
{
pixy.init();
}

void loop()
{
//move both pan and tilt to max position and hold for 2 sec
pixy.setServos(RCS_MAX_POS, RCS_MAX_POS);
delay(2000);

//move both pan and tilt to mid position and hold for 2 sec
pixy.setServos(500L, 500L);
delay(2000);

//move both pan and tilt to min position and hold for 2 sec
pixy.setServos(RCS_MIN_POS, RCS_MIN_POS);
delay(2000);
}

I am expecting this to work, as it would work on any servo. Please note that with the same wiring and power setup, I can run successfully the tiltpan demo from Arduino, I am also able to manually control the servos from pixyMon using rcs_setPos 0 1000, rcs_setPos 0 0,rcs_setPos 1 1000,rcs_setPos 1 0 and all is working fine. am I missing something here?

Appreciate any help

Thanks
Fahed

Ok, I got it to work.

It seems getBlocks function must be called repeatedly to get the servo values to update.

Hi Fahed,
Glad you got it working! Note, we’ll have a new version out this week that allows your first program to work.

thanks!

thanks Rich!

nice! will be trying the new version once announced! and update the thread with results for reference.

Since we are on this subject, I noticed a peculiar behavior, possibly being addressed in the newer version, or not yet reported, or even you might consider it expected behavior, I appreciate letting know what you think.

Context: I have my Pixy powering my Arduino (Nano Rev.3), both servos connected directly to pixy so I am using pixy.setServos(pan,tilt) to control the servos. Data communication is on SPI.

12v —Regulator—> 10v —> Pixy —|---> 5v —> Serov1 & Servo2
|—> 5v —> Arduino

I wrote a simple loop to pan Pixy from extreme right to extreme left, and loops this way.

Issue: panning is acting strangely. The servos stops randomly at some points, then jumps to positions, then again. I am never able to get a clean pan left then pan right. it is always glitchy. I first suspected that the servo is malfunctioning, so I made sure it has enough voltage (it does), then I checked on the oscilloscope the PWM from Pixy on the pan pin. to my surprise, the PWM from pixy is not stable. I mapped the values and time of Arduino sending the SetServos, with the Oscilloscope PWM out readings. the result is: Arduino is sending in timely manner the new positions for servo, but Pixy seems to spend 2.5 sec randomly to apply some of the setServo() calls.

I am wondering if this can be serial buffer issue between Pixy and Arduino, or something internal to Pixy handling the setServos(), or else, something I am doing wrong!

Let me know what type of info I can share to clarify more, is there a way to dump the stack of pixy during operation for example? I can post code and oscilloscope readings vs Arduino readings…

Merci!
Fahed

Hello Rich!

kindly any news about the new version, I am not sure if it already out there now, i checked the wiki but can’t find relevant updates.

Thanks

Hello Fahed,
I believe it is on schedule to post on Friday.

Edward

Hello Fahed,
The new build is posted (2.0.6 PixyMon, 2.0.8 firmware) as well as a new Arduino Library (0.1.7) that fixes this issue. The new Arduino library even has two more examples that just move the servos or just set the RGB bytes (like your example code). Download the PixyMon package which includes the new firmware. You’ll be asked if you want to upgrade your firmware when you run PixyMon.

When installing the new Arduino library, it’s recommended to go into your Documents\Arduino\libraries and remove the Pixy directory before installing the new Arduino library.

http://cmucam.org/projects/cmucam5/wiki/Latest_release

Let us know how it goes!

Thanks you so much Edward for the update.

I’ve tested both of my issues above (ability to move servos without calling getBlock, and Pixy skipping to move the servos randomly), and confirm that both are solved with latest build (2.0.6 pixmon/2.0.8 firmware/0.1.7 arduino lib)

;))

Great work guyz! thank you