According to this link I should be able to set the intensity of the LEDs by choosing an int between 0 and 255. In practice I can only get them to go on or off; any value >= 128 results in full-on, anything <= 127 sets them to off. Am I missing something? Attached is the simple scratch program my girls and I wrote to test it.
OK, I found this in GoPiGoScratch.py which is the magic that lives between Scratch and our robot:
elif msg[:4].lower()=="LEDL".lower(): if en_debug: print msg l_led_pow=int(msg[4:]) if en_gpg: if l_led_pow > 127: led_on(1) else: led_off(1) # Turn On or Off the Right LED elif msg[:4].lower()=="LEDR".lower(): if en_debug: print msg r_led_pow=int(msg[4:]) if en_gpg: if r_led_pow > 127: led_on(0) else: led_off(0)
So it is working exactly as programmed but that doesn’t match the documentation. I found a description of the led() command here which seems like it should solve my problem, so I modified the code in GoPiGoScratch.py to this:
elif msg[:4].lower()=="LEDL".lower(): if en_debug: print msg l_led_pow=int(msg[4:]) if en_gpg: led(1,l_led_pow) # Turn On or Off the Right LED elif msg[:4].lower()=="LEDR".lower(): if en_debug: print msg r_led_pow=int(msg[4:]) if en_gpg: led(0,r_led_pow)
That didn’t work. So I tried figuring it out at the command prompt:
pi@dex ~/Desktop/GoPiGo/Software/Scratch $ python Python 2.7.3 (default, Mar 18 2014, 05:13:23) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from gopigo import * >>> led(1,65) Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'led' is not defined
So, it turns out that led() is not actually defined in the gopigo module, which explains why it doesn’t work in my code and most likely explains why the Scratch commands were modified to simple on/off switches.
It seems either led() needs to be implemented and GoPiGoScratch.py modified to use it, or the documentation needs to be revised to reflect that LEDL and LEDR only turn on and off the lights, and the led() page removed.
Hope that is helpful to someone else out there!
Sorry for the frustration. We have updated the code on the GoPiGo but looks like we forgot to update the documentation. Thanks a lot for letting us know. We’ll updated it ASAP. For now you can either use the led_on() and led_off() to control the led or use analogWrite() to control the intensity of the LED. We’ll update the software asap so that there is an easy way to change the intensity of the led.
Hi Chris, can we ask what you’re doing with Scratch and the GoPiGo? Just curious.
Just playing so far Got the GoBox for my girls (7 and 10) and I for Christmas and we built it today. After seeing how the demo Scratch program worked we started creating our own to get a feel for controlling it. Since the docs said we could set the brightness we came up with the program I linked in the OP.
My older kid has been playing off and on with Scratch and the RPi for a couple of years now, but this is the youngest’s first exposure.
So, for now, just playing with it until the second mission becomes available!
No worries, Karan; it’s part of the learning process here. Was nice to walk my older kid through the process I used to figure out why our code wasn’t working.
So I tried making a function for changing the LED fade on the GoPiGo2 and found out that it is not supported in the newest GoPiGo2. We had to move around the pins on the GoPiGo to provide better control of the motors and one of the casualties of that was that the LED’s are digital only now, so you can only turn it on/off, which I had completely forgot about. Sorry for the confusion earlier.
Please update this documentation - http://www.dexterindustries.com/GoPiGo/programming/python-programming-for-the-raspberry-pi-gopigo/led/
I had to hunt all over to find out that it is not supported anymore.
@salvideoguy I’m sorry the documentation led you astray (led … groan, it wasn’t even intentional)
I’ve updated it. Thank you for pointing it out!
Absolutely no worries.
Any links to a good tut on how to connect a Bluetooth mic to a Raspi-3?
My voice control app needs a hands free mic to control GPG.
Using Google Cloud Speech successfully to implement the voice control.
Any pointers would be great.
Not off-hand, no, no tutorial comes to mind. Sorry. Maybe someone else?
I would suggest starting another thread though, as this one seems to be about LEDs.