Raspberry Pi Asked on November 23, 2021
I am using Pi Zero W with latest Raspberry Pi OS.
I have a backlight of an LCD that I am trying to control via PWM.
If I use RPi.GPIO I get flicker at anything other that 100% (or 0%) duty cycle. As I understand, this is probably due to the timing of the software PWM being affected by other processes.
If I use pigpio, I get good dimming but as soon as I turn the backlight off and back on, it breaks the dimming and I only get full-on or off. Only a reboot fixes this.
The backlight goes off even if I set the DC to 1
(/255) not only to zero , which is also strange and in either case, as mentioned, it breaks the dimming until reboot.
The backlight also automatically comes on as I have it in an overlay for the screen, here is the extract from the dts file. If I comment out that fragment, then I get no dimming at all, just on/off from the start. Also, default-off
doesn’t change anything.
fragment@5 {
target-path = "/";
__overlay__ {
rpi_backlight: rpi_backlight {
compatible = "gpio-backlight";
gpios = <&gpio 18 0>;
default-on;
};
};
};
Ideally, I would remove that fragment and only control the backlight from Python and ideally without a daemon consuming resources.
How can I fix pigpio so that I can turn the backlight off and then get it dimming again (ideally without DTS fragment above or with it defaulting to off)?
pigpio daemon is going to continually use resources just for a backlight, is there a fix for RPi.GPIO so that I can use the hardware PWM (since I am using GPIO 18 which has that capability, as I understand) – also ideally without fragment@5
Edit:
This is the python script that dims the backlight up and down.
$ sudo pigpiod
$ python3
import pigpio
import time
gpio = pigpio.pi()
gpio.set_mode(18, pigpio.OUTPUT)
#gpio.set_mode(18, pigpio.ALT5) - behaves the same
def dim_up():
for x in range(2,200):
gpio.set_PWM_dutycycle(18, x)
print('level =', x)
time.sleep(0.01)
def dim_down():
for x in range(200,1,-1):
gpio.set_PWM_dutycycle(18, x)
print('level =', x)
time.sleep(0.01)
def cycle_dim():
while True:
dim_up()
dim_down()
cycle_dim()
This works fine and dims up and down smoothly until you change either range
to include 1
or 0
in the range. Then, the first time before it hits those numbers, it works fine, then after those numbers it is either full on or full off, no range in between.
This turned out to be an issue with the way PWM was interfacing with the Texas Instruments TPS61165 LED driver which made it switch control modes to EasyScale. As Joan kindly pointed out, increasing the PWM frequency to 1m stopped this from happening and provided reliable dimming.
Answered by Bassline Soup on November 23, 2021
The dtb fragment is irrelevant to pigpio. It makes no use of the fragment.
With pigpio you can use any expansion header GPIO to generate flicker free PWM suitable for LEDs. You can easily check by using the pigs
utility from the command line.
e.g. for GPIO 18 use e.g. pigs p 18 x
, for GPIO 5 use pigs p 5 x
etc. Where x is 0 for off, 255 for fully on, and intermediate values for settings between off and fully on.
RPi.GPIO currently has no support for hardware PWM.
If you have a problem with pigpio and Python a listing showing the problem will be useful.
Answered by joan on November 23, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP