Python Forum
Seemingly unstable GPIO output while executing from RetroPie
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Seemingly unstable GPIO output while executing from RetroPie
#1
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:
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
Reply


Messages In This Thread
Seemingly unstable GPIO output while executing from RetroPie - by LouF - Feb-17-2021, 07:00 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  why does VS want to install seemingly unrelated products? db042190 3 656 Jun-12-2023, 02:47 PM
Last Post: deanhystad
  function return boolean based on GPIO pin reading caslor 2 1,193 Feb-04-2023, 12:30 PM
Last Post: caslor
  class Update input (Gpio pin raspberry pi) caslor 2 807 Jan-30-2023, 08:05 PM
Last Post: caslor
  Webhook, post_data, GPIO partial changes DigitalID 2 999 Nov-10-2022, 09:50 PM
Last Post: deanhystad
  Pexpect timesout before executing whole output eagerissac 0 1,506 Jun-23-2021, 03:30 AM
Last Post: eagerissac
  Seemingly simple loop Weber585 7 3,530 Mar-21-2021, 07:19 PM
Last Post: jefsummers
  Picture changing triggered by GPIO q_nerk 2 2,595 Dec-14-2020, 03:32 PM
Last Post: DeaD_EyE
  GPIO high if network IP has good ping duckredbeard 3 2,352 Oct-12-2020, 10:41 PM
Last Post: bowlofred
  raspberry pi tank gpio help jatgm1 1 2,428 May-06-2020, 09:00 PM
Last Post: Larz60+
  Where should I place GPIO.cleanup() shallanq 2 2,181 Apr-11-2020, 05:02 AM
Last Post: shallanq

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020