1

I am trying to run an old Raspberry Pi 2011.12 as a server to control a RGB LED strip. To this I am using PIGPIO since this is the best solution (RPi.GPIO is software based, which creates flickering). However I have problems with a small delay, when trying to run the python script.

My code is as follows:

#!/usr/bin/env python

import time, sys, random

import pigpio

pi = pigpio.pi() # connect to local Pi

redcolor = 0
bluecolor = 0
greencolor = 0

pi.set_PWM_dutycycle(23, redcolor)
pi.set_PWM_dutycycle(24, greencolor)
pi.set_PWM_dutycycle(22, bluecolor)

pi.stop()

I have not tried to run the script on a new Raspberry Pi yet since I hope that somebody here could tell me if the delay sounds normal or if there is a way to reduce it. We are talking about approximately 2 seconds before the PWM signal turns on and light up the RGB LED strip.

I am running on Raspbian Buster (the newest version).

1 Answer 1

1

On a Pi Zero W it takes just less than half a second for that script to start PWM.

I'd guess that the bulk of the delay is due to the Python module imports.

To facilitate timing I changed the script to the following.

#!/usr/bin/env python

import time, sys, random

import pigpio

pi = pigpio.pi() # connect to local Pi

redcolor = 128
bluecolor = 128
greencolor = 128

pi.set_PWM_dutycycle(17, redcolor)
pi.set_PWM_dutycycle(18, greencolor)
pi.set_PWM_dutycycle(19, bluecolor)

time.sleep(0.5)

pi.set_PWM_dutycycle(17, 0)
pi.set_PWM_dutycycle(18, 0)
pi.set_PWM_dutycycle(19, 0)

pi.stop()

I timed it by running piscope then doing

gpio -g write 4 0; python led.py; gpio -g write 4 1

enter image description here

I can sort of confirm Python initialisation is the problem.

Using pigs the delay is about 20 milliseconds.

gpio -g write 4 0; pigs p 17 128 mils 500 p 17 0; gpio -g write 4 1

enter image description here

6
  • Hi Joan, thanks for your answer. So what would you suggest me to do? Should I instead run it on a Raspberry Zero? Or is there a way to increase the speed of my old Raspberry? I would like to use the old Raspberry since otherwise it's useless :-( Oct 8, 2019 at 17:47
  • Hi again, I saw that you used "python" instead of "python3" to run the script. This increase the performance running the script. Now the delay is max 1 second. Oct 8, 2019 at 17:52
  • Perhaps you could use pigs to set the default PWM and then launch the Python script?
    – joan
    Oct 8, 2019 at 19:46
  • How would that be done? Oct 9, 2019 at 20:02
  • @SchnitteKing pigs p 17 100 p 18 150 p 19 200 does the same as pi.set_PWM_dutycycle(17, 100); pi.set_PWM_dutycycle(18, 150); pi.set_PWM_dutycycle(19, 200)
    – joan
    Oct 9, 2019 at 21:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.