Using some transistors, I connected LEDs to 3 GPIOs.
I wanted to dim them using GPIO.PWM, but I get irregular flickering from time to time.
Which frequencies are suitable to avoid flickering?
By GPIO.PWM do you mean the RPi.GPIO Python module?Jakob Staudinger wrote:Using some transistors, I connected LEDs to 3 GPIOs.
I wanted to dim them using GPIO.PWM, but I get irregular flickering from time to time.
Which frequencies are suitable to avoid flickering?
Even more flickering.joan wrote:RPIO.GPIO
Please share an example to get started quickly.Gert van Loo wrote:Use C-code.
I tried python for a LED matrix and had the same experience you described: flickering.
Going to C solved all my problems (At least 100x faster) .
Code: Select all
#!/usr/bin/env python
# import RPi.GPIO as GPIO, feedparser, time, sys, random, RPIO.PWM
import feedparser, time, sys, random
from RPIO import PWM
PWM.setup()
PWM.init_channel(0)
while True:
R = random.randrange(0, 255,1)
G = random.randrange(0, 255,1)
B = random.randrange(0, 255,1)
PWM.add_channel_pulse(0, 17, R, 255)
PWM.add_channel_pulse(0, 22, B, 255)
PWM.add_channel_pulse(0, 25, G, 255)
time.sleep(2)
# Shutdown all PWM and DMA activity
PWM.clear_channel_gpio(0, 17)
PWM.clear_channel_gpio(0, 22)
PWM.clear_channel_gpio(0, 25)
PWM.cleanup()Code: Select all
#!/usr/bin/env python
import time, sys, random
import pigpio
pi = pigpio.pi() # connect to local Pi
start_time = time.time()
while (time.time()-start_time) < 60:
R = random.randrange(0, 255, 1)
G = random.randrange(0, 255, 1)
B = random.randrange(0, 255, 1)
pi.set_PWM_dutycycle(17, R)
pi.set_PWM_dutycycle(22, B)
pi.set_PWM_dutycycle(25, G)
time.sleep(2)
pi.stop()