<< return to Pixycam.com

Extending Pixy General Methods to Python

Hello all, sorry for the double thread, but I did not know if this was more appropriate as an addendum to my last, or an independent one.

After examining and experimenting with the Pixy2 python API, it looks as though the LED control did not make the cut.

I tried poking around, and adding it myself, but got a segmentation fault.

Here is what I tried…
I added the following code to …/python_demos/pixy.i

/*!
  @brief       Set upper and lower LEDs 
  @param[in]   upper  Turns on the upper LEDs
  @param[in]   lower  Makes all 3 lower LEDs run at full
*/
extern void set_lamp (int  upper, int  lower);

Then, when that got a name error on import, I poked around some more and added the following code to .
…/python_demos/pixy_python_interface.cpp

void set_lamp (int  upper, int  lower)
{
  pixy_instance.setLamp (upper, lower);
}

I do not really know C++ at all, and so I am sort of feeling my way around the dark, but I would like to get the LEDs working in python.

The C++ API lists it as this…

int8_t setLamp(uint8_t upper, uint8_t lower)
setLamp() turns on/off Pixy2's integrated light source. The upper argument controls the two white LEDs along the top edge of Pixy2's PCB. The lower argument sets the RGB LED, causing it to turn on all three color channels at full brightness, resulting in white light. Both arguments are binary, zero or non-zero. It returns an error value (<0) if it fails and 0 (PIXY_RESULT_OK) if it succeeds.

Does anyone have any idea what I am doing wrong?
Thanks,
R^2

MrRSquared,

I’m reviewing your software application programming interface request and will be getting back with you shortly.

Thank you,
Zero

1 Like

Thank you. I should add that, when I attempt to invoke the method pixy.setLamp() by adding it to one of the C++ demos, it works. I just cannot invoke it in python (in either python2, or python3).

For instance, I added the following…

 pixy.setLamp(1, 0); 

to one of the classes in get_blocks_ccc_demo.cpp, and it turns the top LEDs on as expected.

R^2

@edge can you help with this?

MrRSquared,

I am able to reproduce the issue. Let me investigate this and I’ll get back with you soon.

Thank you,
Zero

1 Like

MrRSquared,

Could you please try the Python set_lamp_demo? I just added this in the set_lamp_feature branch. If there are no problems, we can merge this into the master branch.

Thank you.
Zero

2 Likes

Thank you. That seemed to work for Python2. It did not seem to work in my Python 3 implementation, but I am pretty certain that has to do with how I implemented it (I just attempted to use the command line REPL). I will try again tomorrow and let you know how it goes.
~Mr. R^2
Edit: After a bit of further testing. This fix does seem to work with my Python 3 code as well. :smile:

1 Like