I have Python code on a Raspberry Pi running RetroPie. It instructs a GPIO pin to supply a MOSFET transistor with a signal to turn on/off LED lights. I have problems with the lights not staying on when I use a fading-up routine. After executing the code via RetroPie (automatically at boot, and manually via the RetroPie menu). I do not believe it has anything to do with the electronics; the signal seems to be dropped to the output pin.
More detailed description:
I have LED lights fade up with pulse width modulation (PWM), and then I attempt to set the pin to "on" following the ramp-up. It seems to have a problem after PWM. I set the pin HIGH, LOW, 0, 1 -- it just seems to do whatever it wants after the PWM, that is, either on or off whether it was told to be on or off. I've tried putting a pause after the modulation, and I currently have the whole pin re-initiated after the PWM loop (which I don't know why that isn't putting out an error). It seems to work fine from command line (but I have messed with this for so long, that I may not be correct on that). My program logic is that the pin is opened/initialized, faded up with PWM, and then set to "on" after the fade-up, but something goes regularly wrong.
During RetroPie boot, the Python code is run from ( /etc/rc.local):
...
python /home/pi/gameltsfade.py &
exit 0
Manually, the code can be operated from the RetroPie menu ( ~RetroPie/retropiemenu/Game lights ON.sh):
!#/bin/bash
python /home/pi/gameltsfade.py
My gameltsfade.py programming:
(I also have this manually operable through Kodi add-ons (separate code, running in RetroPie) with similar results - actually in Kodi, it never stays on (when pulse width modulation is used).
This is my first post, and I am new to Raspberry Pi, Python and this forum. I've tried to comply with forum policies as much as possible. The RetroPie forum is not willing to comment (as maybe not focused on Python and GPIO programming), and I hope this forum doesn't shy away from this being in the RetroPie environment. Thanks for reading.
Pi Model: 4B (2GB), 5.4.72-v7l+ firmware, 3A power supply
RetroPie v. 4.7.1
Emulation Station v. 2.9.6RP
Python 2.7.16
Linux Buster
More detailed description:
I have LED lights fade up with pulse width modulation (PWM), and then I attempt to set the pin to "on" following the ramp-up. It seems to have a problem after PWM. I set the pin HIGH, LOW, 0, 1 -- it just seems to do whatever it wants after the PWM, that is, either on or off whether it was told to be on or off. I've tried putting a pause after the modulation, and I currently have the whole pin re-initiated after the PWM loop (which I don't know why that isn't putting out an error). It seems to work fine from command line (but I have messed with this for so long, that I may not be correct on that). My program logic is that the pin is opened/initialized, faded up with PWM, and then set to "on" after the fade-up, but something goes regularly wrong.
During RetroPie boot, the Python code is run from ( /etc/rc.local):
...
python /home/pi/gameltsfade.py &
exit 0
Manually, the code can be operated from the RetroPie menu ( ~RetroPie/retropiemenu/Game lights ON.sh):
!#/bin/bash
python /home/pi/gameltsfade.py
My gameltsfade.py programming:
import RPi.GPIO as GPIO # Importing RPi library to use the GPIO pins from time import sleep # Importing sleep from time library GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) # set BOARD pin numbering system GPIO.setup(11, GPIO.OUT) # Declaring pin 11 as output pin pwm=GPIO.PWM(11,100) # Created a PWM object pwm.start(0) # Started PWM at 0% duty cycle for x in range(100): # loop for 200 times pwm.ChangeDutyCycle(x) # set duty cycle sleep(0.01) # Delay for 30mS in loop #pwm.stop() #GPIO.setup(11, GPIO.OUT, initial=GPIO.HIGH) #pwm.start(100) #pwm.ChangeDutyCycle(100) #print("end of loop") #sleep(2) #GPIO.output(11, 1)****** sleep(0.5) GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) # set BOARD pin numbering system GPIO.setup(11, GPIO.OUT) # Declaring pin 11 as output pin GPIO.output(11, GPIO.HIGH) #print("set at 1") #sleep(3)As it stands, it functions, although unreliable.
(I also have this manually operable through Kodi add-ons (separate code, running in RetroPie) with similar results - actually in Kodi, it never stays on (when pulse width modulation is used).
This is my first post, and I am new to Raspberry Pi, Python and this forum. I've tried to comply with forum policies as much as possible. The RetroPie forum is not willing to comment (as maybe not focused on Python and GPIO programming), and I hope this forum doesn't shy away from this being in the RetroPie environment. Thanks for reading.
Pi Model: 4B (2GB), 5.4.72-v7l+ firmware, 3A power supply
RetroPie v. 4.7.1
Emulation Station v. 2.9.6RP
Python 2.7.16
Linux Buster