Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dimming / backlight control on/off #8

Open
kokosowy opened this issue Dec 30, 2020 · 11 comments
Open

Dimming / backlight control on/off #8

kokosowy opened this issue Dec 30, 2020 · 11 comments

Comments

@kokosowy
Copy link

Hey!

I'm using pirate audio and it's fun! I have a question, is it possible to allow dimming on this display or turning of backlight completely?

Thanks for letting know!
K

@Sebwap
Copy link

Sebwap commented Nov 2, 2021

No return on this since nearly one year ?
I'm asking myself the same question for the new display hat mini which is driven by the same library.
For me, you can shutdown backlight by pulling down the GPIO used for backlight.

Howerver, I don't know if it is possible to do some dimming.

@tomtastic
Copy link

tomtastic commented Jan 20, 2022

There's a method to set the backlight on/off :

def set_backlight(self, value):

Though I've yet to try it, and there appears no current way to adjust the level or dimming of the backlight, but with some code changes, I think it should be possible to set the backlight GPIO pin to PWM mode (https://sourceforge.net/p/raspberry-gpio-python/wiki/PWM/) and change the duty cycle accordingly to vary the brightness.

Caveat: I've no idea what impact this would have as far as the current being passed and may fry things?!

@tomtastic
Copy link

From a quick look at the ST7789 datasheet, it seems there might even be functions to vary brightness that just aren't implemented in the current driver here : https://www.rhydolabz.com/documents/33/ST7789.pdf

0x51 = Write display brightness
0x52 = Read display brightness value

image

@Gadgetoid
Copy link
Member

For all of our display boards, the backlight pin can be PWM'd for brightness control. Any "brightness" registers in the display driver itself will probably do something but since they can't vary the intensity of the backlight they wont have the intended effect.

PWM from Python (RPi.GPIO) is... dicey... I haven't tried it for a while, but it wasn't traditionally stable enough for a display backlight. You might see some flicker, which isn't great on a display. Might be worth looking into again to see if the results are acceptable but since Linux is moving toward Libgpio (slow-ish) and the Pi is moving away from traditional register bitbanging (fast) it's probably going to break even more in future anyway.

Any other method of PWM is unfortunately outside the scope of this library.

The most correct approach is to bring up the pwm-backlight kernel module with the appropriate config. Though since the Pi's PWM slices are often used for analogue audio there are tradeoffs even here. Some instructions on how to do this- pending figuring out how to do it again- might not go amiss in this repository.

TLDR: It's complicated.

@tomtastic
Copy link

tomtastic commented Jan 20, 2022

I had a look at RPi.GPIO for the PWM details, it's still software based, but an overlay for the device tree to allow hardware PWM (via sysfs - https://jumpnowtek.com/rpi/Using-the-Raspberry-Pi-Hardware-PWM-timers.html) looks straightforward enough and would at least avoid burning user cycles and would hopefully equate to less flicker during garbage collection, etc.

@ThecaTTony
Copy link

This is a good example of dimming:

https://github.com/pimoroni/pirate-audio/blob/master/examples/backlight-pwm.py

@Wikinaut
Copy link

Wikinaut commented Mar 3, 2023

I use the PWM method but noticed annoying flickering - where does it stem from? How can this be overcome?

@Wikinaut
Copy link

Wikinaut commented Mar 3, 2023

Using pigpioworks perfectly.

I will publish test script using this method later here.

@bjohas
Copy link

bjohas commented Apr 25, 2023

@Wikinaut - would love to see the example!

@Wikinaut
Copy link

Wikinaut commented Apr 26, 2023

@bjohas
Hi, here is the updated code using pigpio. Make sure to run pigpiod with -t 0 option, otherwise you cannot play audio.

Testscript PWM without Audio:

Testscript PWM plus Audio:

@bjohas
Copy link

bjohas commented Apr 26, 2023

Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants