PWM control with RPi for Adafruit 5" 800x480 TFT HDMI Backpa

Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
Locked
User avatar
AmrasElensar
 
Posts: 3
Joined: Fri May 01, 2015 10:17 am

PWM control with RPi for Adafruit 5" 800x480 TFT HDMI Backpa

Post by AmrasElensar »

Hi all,

I recently bought some wonderful Adafruit products with Adafruit reseller exa-tech.de to make a portable RetroPie emulator.
Amongst those is a Adafruit 5" 800x480 TFT HDMI Backpack screen which works great btw.

I'm still fairly new at all this but i'm willing to learn so I already did some research:
I read it is possible to control the backlight with a pwm signal, I also know it is possible on the pi to use gpio 18 for a hardware pwm signal and other to use software pwm.
I've only seen small examples of controlling a led and basic servos, more as a proof of concept that a real world application.

This brings me to my question:
Would it be technically possible to implement 2 buttons to drive that backlight control?
I read an interesting bit here which talks about using interrupts to read button presses (to not use cpu power with 'while loops').

Code: Select all

http://raspi.tv/2013/how-to-use-interrupts-with-python-on-the-raspberry-pi-and-rpi-gpio-part-3
Could this technique be combined if I were to device some code - like the examples shown below - to be executed when a button press is 'sensed'.

Code: Select all

gpio -g mode 18 pwm
gpio -g pwm 18 1
gpio -g pwm 18 1000
gpio -g pwm 18 0
Preferably each button press (+ or -) would increment or decrease a preset value.

Also I was hoping if somebody could show me were exactly I would need to connect this signal on the screen.

I hope my explanation is some what clear, as I said I'm still learning how this all works. Feel free to correct me If I'm interpreting something wrong.
Thanks in advance for any help in steering my in the right direction.
Regards,
Maarten

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: PWM control with RPi for Adafruit 5" 800x480 TFT HDMI Ba

Post by adafruit_support_mike »

AmrasElensar wrote:Would it be technically possible to implement 2 buttons to drive that backlight control?
Yeah, that's doable.

GPIO 18 might not be the best option any more.. the RasPi IO system is going through an overhaul, moving away from the practice of using drivers that have to be compiled into the kernel and toward something called 'device tree overlays' that can be loaded dynamically (and changed on the fly). GPIO 18 was the kernel-module way of doing PWM, and newer versions of the OS use RPi.GPIO's software PWM.

Your basic idea is sound though.. you can PWM a pin and have it control the display's backlight, and you can use GPIO inputs to control the PWM level. You can also use interrupt-based GPIO to manage the pins rather than leaving a process busy-waiting forever.

I'd suggest you start by getting the RPi.GPIO module and taking a look at the documentation and examples:

https://pypi.python.org/pypi/RPi.GPIO
http://sourceforge.net/p/raspberry-gpio ... i/install/
http://sourceforge.net/p/raspberry-gpio ... /Examples/

As a tip, start by having the interrupt handlers write lines to a file and use `tail -f [filename]` to display the output. It's an easy and controllable way to get diagnostic information from a program running in the background.

Use that to get the count-up/count-down behavior you want, then use that to control the PWM. Connect the PWM pin to the pad labled 'Backlight' on the back of the display driver's PCB.

User avatar
AmrasElensar
 
Posts: 3
Joined: Fri May 01, 2015 10:17 am

Re: PWM control with RPi for Adafruit 5" 800x480 TFT HDMI Ba

Post by AmrasElensar »

Thanks Mike, those links pointed me in the right direction. Sorry it took a while to post back.
Haven't had much time for experimenting with it, but I did manage to make a small test script to check how the screen would react to the PWM signal.
It's very rudimentary, more a proof of concept than something practical. It just runs through some DutyCycles and then quits

Code: Select all

import RPi.GPIO as GPIO  
from time import sleep
  
GPIO.setmode(GPIO.BCM)  
  
GPIO.setup(2, GPIO.OUT)
GPIO.setup(9, GPIO.IN)
GPIO.setup(10, GPIO.IN)
  
backlight = GPIO.PWM(2, 1000)   
                     
backlight.start(100)               
                   
pause_time = 1.5                  
  
backlight.ChangeDutyCycle(20)   
sleep(pause_time)  
backlight.ChangeDutyCycle(30)    
sleep(pause_time)  
backlight.ChangeDutyCycle(40)    
sleep(pause_time)  
backlight.ChangeDutyCycle(50)    
sleep(pause_time)  
backlight.ChangeDutyCycle(60)    
sleep(pause_time)  
backlight.ChangeDutyCycle(70)    
sleep(pause_time)  
backlight.ChangeDutyCycle(80)    
sleep(pause_time)  
backlight.ChangeDutyCycle(90)    
sleep(pause_time)  
backlight.ChangeDutyCycle(100)
 
GPIO.cleanup()           
The above code works, but the screen emits a very annoying high pitched whine when dimmed.
If i use the 25mA pads at the back, there is no high frequency sound

Could you tell me if this is inherent to this screen type? Or would fiddling with some settings (refresh rate, pwm frequency...)
Otherwise PWM dimming on this monitor would be far from desirable.

Thanks

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: PWM control with RPi for Adafruit 5" 800x480 TFT HDMI Ba

Post by adafruit_support_mike »

The high-pitched noise is an unfortunate side-effect of how the LED backlight is made.

Surface-mount capacitors are slightly piezoelectric, so they can couple mechanical noise into a circuit (in extreme cases, they act like little microphones). The laws of physics are reversible though, so sudden changes in voltage can make them flex slightly. If that happens at a regular frequency, you get sound.

The best solution would be to use an external PWM controller like the PCA9685 or one of the TLC59* series:

https://www.adafruit.com/products/815
https://www.adafruit.com/products/1455
https://www.adafruit.com/products/1429

Those have their own internal clocks and don't have to do critical timing on the RasPi's GPIO. They're kind of overkill for a single LED though. It would be cheaper and easier to use a Trinket to generate the PWM signals.

User avatar
d0z3y
 
Posts: 1
Joined: Tue Jan 12, 2016 5:54 pm

Re: PWM control with RPi for Adafruit 5" 800x480 TFT HDMI Ba

Post by d0z3y »

Hi,
Why would the external PWM controller help with this if the noise is created by the capacitors on the backlight?
To prevent the noise, would the Trinket be hooked up to the backlight pad instead of the PI's GPIO PWM?

Are there any other pointers you can give me?

Thanks in advance.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: PWM control with RPi for Adafruit 5" 800x480 TFT HDMI Ba

Post by adafruit_support_mike »

d0z3y wrote:Why would the external PWM controller help with this if the noise is created by the capacitors on the backlight?
The capacitors always vibrate, but it becomes audible when the vibration hits a mechanical resonant frequency of the board. Those are hard to predict and harder to prevent.

Changing the PWM fequency (which is easy with an external controller) moves the vibration off the board's resonant frequency so you don't hear it any more.
d0z3y wrote:To prevent the noise, would the Trinket be hooked up to the backlight pad instead of the PI's GPIO PWM?
Yeah. You want the external PWM generator to be independent of the RasPi's signal timing.

Locked
Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/

Return to “Adafruit Raspberry Pi® accessories”