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
#3
This is a great example of why the comments should never duplicate the code. 100 steps instead of 200, sleep 10 ms instead of 30. Comments should be seldom and describe purpose, not implementation. If the implementation is unclear, change the code to make the implementation clear.

I think your problem is caused by not stopping PWM. Since PWM is toggling power on/off at some frequency/duty cycle I would expect this to override setting the GPIO output. What happens if you run this?
import RPi.GPIO as GPIO
from time import sleep

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.OUT)

# Using PWM ramp power from 0 to 100% 
pwm=GPIO.PWM(11,100)
pwm.start(0)
for x in range(100): 
    pwm.ChangeDutyCycle(x)
    sleep(0.01)

# Stop PWM and toggle LED on/off at 1 second intervals
pwm.stop()
for _ in range(10)
    GPIO.output(11, GPIO.HIGH)
    sleep(1)
    GPIO.output(11, GPIO.LOW)
    sleep(1)
LouF likes this post
Reply


Messages In This Thread
RE: Seemingly unstable GPIO output while executing from RetroPie - by deanhystad - Feb-17-2021, 10:34 AM

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