RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login
    Please do not post a support request without first reading and following the advice in https://retropie.org.uk/forum/topic/3/read-this-first

    Seemingly unstable GPIO output while executing from RetroPie

    Scheduled Pinned Locked Moved Help and Support
    gpiopython script
    1 Posts 1 Posters 440 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • LouFL
      LouF
      last edited by LouF

      I have Python code that 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 after executing the code via RetroPie (automatically at boot, and manually vie 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.

      I have the LEDs 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'd, and then set to "on", but something goes regularly wrong.

      During boot, the Python code is run from ( /etc/rc.local):
      ...
      python /home/pi/gameltsfade.py &
      exit 0

      Manually, they can be operated from RetroPie menu ( ~RetroPie/retropiemenu/Game lights ON.sh):
      !#/bin/bash

      python /home/pi/gameltsfade.py

      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)

      (you can see commented-out troubleshooting lines. As it stands, it functions, although unreliable)

      (Note: Commented lines in this copy of the code are in parenthesis so the text does not go to a large size in this post.)

      (I also have this manually operable through Kodi add-ons (separate code) with similar results - actually in Kodi, it never stays on (when pulse width modulation is used).

      I hope this is an appropriate place for this post.
      Comments on the problem are appreciated.

      Pi#2: 4B-2Gb, 5.10.11-v7l+ firmware, 3A power supply
      RetroPie v. 4.7.1 pre-made SD image, transferred from Pi#1
      Emulation Station v. 2.9.6RP
      RetroArch 1.8.8
      Controller: Vilros SNES wireless USB
      WD easystore HDD - 1TB

      Pi#1: 4B-2Gb, 5.4.72-v7l+

      1 Reply Last reply Reply Quote 0
      • First post
        Last post

      Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.

      Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.