banner



How To Change Brightness On Raspberry Pi 7 Inch Screen

Automatic effulgence control for the Raspberry Pi

Among the accessories bachelor for the Raspberry Pi, the TFT affect display is quite interesting. Past combining it with a defended enclosure, i gets a tiny all-in-one computer, well suited to monitor various sensors. Nosotros like information technology even more since our YoctoVisualization app now runs on Linux :-) At that place is merely one minor effect with information technology: brightness command...

Can we have the display brightness auto-adapt to ambiant light ?
Can nosotros have the brandish effulgence auto-adapt to ambiant low-cal ?

When you install this brandish in a room, y'all volition soon notice that during the night, the backlight is strong plenty to radiate a freaky light halo. So we wondered if it wouldn't be possible to modify this brandish so that the effulgence automatically adjusts to ambiant light. That would require calculation a low-cal sensor, simply luckily, we accept plenty of them at Yoctopuce.

Hardware

We could leave the low-cal sensor hanging on a brusk USB cable, but to make it nice-looking we wanted to have it embedded directly into the display. And so the trickiest part of this project is to make a pocket-sized opening in the forepart panel of the display. This front end console is made of transparent plastic, with the back side painted in black. So our idea is to remove just a bit of black pigment in gild to brand a tiny circular window for the sensor. In order to do so, we have glued a small round piece of sand paper on a spiral caput, put the spiral into a drill and used that tool to strip the black paint. A perfect effect was obtained in a matter of seconds.

Home-made tool to strip paintNo fear
Express pigment stripping


Note that the the drill must turn very slowly to prevent the plastic from melting. After this operation, a tiny blackness dot may remain at the center of the circle, only yous can remove information technology easily past scratching it advisedly using the tip of a Ten-Acto knife .

A good looking round
A good looking round


In club to measure ambiant lite, we chose to use a Yocto-Light-V2 considering information technology is more sensitive in very low lite environments than the Yocto-Light-V3. We take split it in 2 parts, because there is just plenty space for the sensor function on the side of the display. To make the build cleaner, we have glued with epoxy resin two pieces of acrylic glass with threaded inserts: 1 on the side of the display but in front of the round window, and one in the heart of the display PCB. This way, both parts of the light sensors tin be mounted with standard spiral.

Fixation systemRaspberry Pi connection
The electronic part
With the sensor mounted


We have connected the sensor to the Raspberry Pi by soldering the wires of a 1.27-i.27-11 cable direct nether one of the USB terminal block. The respective USB socket has been voided using a 3D-printed fake USB dongle. Eventually, we had to cutting off 2 of the enclosure reinforcement bracings in social club to close it.

We have removed two reinforcement bracingsEverything fits in
We had to slightly adapt the enclosure


In one case completed, this little hack fabricated in less than ii hours looks pleasantly. 1 can barely guess that there is an added light sensor.

A Raspberry Pi display with built-in light sensor
A Raspberry Pi display with built-in light sensor

Software

The display effulgence can exist changed simply by writing an integer between 0 and 255 into the file /sys/form/backlight/rpi_backlight/brightness. By default you lot must be root to write to that file, so we added a line to authorize this into /etc/udev/rules.d/51-yoctopuce.rules which already authorize any user to work with Yoctopuce devices.

# udev rule to permit write access to all users for Yoctopuce USB devices SUBSYSTEM=="usb", ATTR{idVendor}=="24e0", Manner="0666" # udev rules to allow write access to all users for RaspberryPi 7" Touch Display SUBSYSTEM=="backlight",RUN+="/bin/chmod 666 /sys/form/backlight/%k/effulgence"

We have installed Yoctopuce VirtualHub on the Raspberry Pi and made certain that it starts on startup, using to system-D

And so we have written a small-scale script that looks for any light sensor, and registers a callback to recompute the desired brightness based on ambiant light. To make certain the brandish will not flash each time someone moves in front of the display, brightness changes are merely applied past increments of 1 every 5 ms.

#!/usr/bin/python
# -*- coding: utf-8 -*-

# import Yoctopuce Python library (installed from PyPI)
from yoctopuce.yocto_api import *
from yoctopuce.yocto_lightsensor import *

target= 128
current = 128

def lightChange(sensor,value):
global target
target = int ( float (value) )
if target> 255: target= 255
if target< 10:  target= 10

errmsg = YRefParam ( )
if YAPI.RegisterHub ( "127.0.0.i" , errmsg) != YAPI.SUCCESS:
sys.exit ( "RegisterHub error" + str (errmsg) )

sensor = YLightSensor.FirstLightSensor ( )
if sensor == None:
sys.exit ( "No light sensor available." ) ;

sensor.registerValueCallback (lightChange)

while True:
YAPI.Sleep ( v ,errmsg)
if (target!=current):
if (current<target):
current = electric current+1
else:
current = current-one
file = open ( "/sys/class/backlight/rpi_backlight/brightness" , "w" )
file.write ( str (current) )
file.close ( )

Final remarks

These Raspberry Pi displays are delivered with a protective sail stuck to the front. Proceed it in place until your DIY work is completed, to avert making scratches on the display while you work on it.

You may have noticed that nosotros communicate with the Yocto-Light-V2 through the VirtualHub. This is to avoid locking USB access for any other Yoctopuce applications.

Past default, the Raspberry Pi display turns off automatically after a few minutes. Evidently the simplest and well-nigh reliable fashion to disable this behavior is to install a screensaver:

sudo apt-get install xscreensaver


... then to disable it.

Source: http://www.yoctopuce.com/EN/article/automated-brightness-control-for-the-raspberry-pi

Posted by: holtvared1955.blogspot.com

0 Response to "How To Change Brightness On Raspberry Pi 7 Inch Screen"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel