0

Backlight control of 2.8" capacitive screen not working
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Backlight control of 2.8" capacitive screen not working

by landshrk on Mon Aug 19, 2019 12:56 am

Hi, all. Just got my first Pi (model 3b+), and I made a PiHole. Figured a nice output of stats would be an alright thing to have, too, so I tacked an Adafruit 2.8" capacitive screen onto the order, to run PADD on.

So far, so good. Got PiHole up and running, and been having fun tweaking it and watching stats. Got PADD up and running, too, lookin' real nice.

However, I want to be able to put the screen backlight to sleep, either on a timer or on-demand.

Looking at the PADD docs, I saw that editing the crontab was a good way of scheduling this. So I
Code: Select all | TOGGLE FULL SIZE
sudo crontab -e
and notice that there's already an entry there, with midnight for off and 0800 for on. I edit it to change those to 2200 and 0600, save and exit. This is the current content of crontab:

Code: Select all | TOGGLE FULL SIZE
# Turn off the PiTFT+ at 2200
00 22 * * * sh -c 'echo "0" > /sys/class/backlight/soc\:backlight/brightness'
# Turn on the PiTFT+ at 0600
00 06 * * * sh -c 'echo "1" > /sys/class/backlight/soc\:backlight/brightness'
Great. Except it's not working. So, I run
Code: Select all | TOGGLE FULL SIZE
sudo sh -c 'echo "0" > /sys/class/backlight/soc\:backlight/brightness'
on its own, to see what happens. Here's the output:

Code: Select all | TOGGLE FULL SIZE
sudo sh -c 'echo "0" > /sys/class/backlight/soc\:backlight/brightness': Directory nonexistent
Huh. That's weird. Ok,
Code: Select all | TOGGLE FULL SIZE
cd /sys/class/backlight
ls
... nothing. There's nothing in there. Alright, let's do a full re-install, running through all the commands from the beginning.

Code: Select all | TOGGLE FULL SIZE
cd ~
wget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/adafruit-pitft.sh
chmod +x adafruit-pitft.sh
sudo ./adafruit-pitft.sh
Options picked were 3 for the 2.8 capacitive, and 1 for 90 deg landscape, as I know those work and display properly.

Run
Code: Select all | TOGGLE FULL SIZE
sudo sh -c 'echo "0" > /sys/class/backlight/soc\:backlight/brightness'
again, with the same result. Directory nonexistent.

Ok, how about this, then:
Code: Select all | TOGGLE FULL SIZE
sudo mkdir /sys/class/backlight/soc
Operation not permitted.

I fully admit to being beyond my typical comfort level now, and am totally at a loss. So, thoughts? Suggestions? Will this just be on forever so long as it's powered and booted up?

I read through this thread, and that's where I got the idea that maybe something was screwy in the original install, and why I tried a reinstall. While it worked for the OP there, no dice for me.

FWIW, the contents of os-release are as follows:

Code: Select all | TOGGLE FULL SIZE
pi@HackPi:~ $ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"


Thanks in advance for any help you all have. Let me know if you need more from me; I'll get it to you as soon as I can.

landshrk
 
Posts: 10
Joined: Mon Aug 19, 2019 12:17 am

Re: Backlight control of 2.8" capacitive screen not working

by adafruit_support_mike on Mon Aug 19, 2019 1:44 am

Some background information will probably help you get more comfortable working with this part of the system:

One of the core design principles of Unix-like operating systems is "everything is a file", meaning the OS and all programs use the same functions and data structures to talk to everything outside the CPU. It's not that much of a conceptual stretch, since reading and writing a file on a hard drive involves talking to device drivers that communicate with the low-level hardware. From the kernel's perspective, that looks like "talk to a piece of software using these messages, and expect these results." The "everything is a file" abstraction just generalizes the idea so all IO devices speak the same language.

The /dev file tree is set aside for what are called 'special files', which basically means "these 'files' talk to something other than the hard drive or SD card driver."

But once you have the term 'file' as generalized mental shorthand for "talk to another program using a well-defined interface", you can take away the hardware driver on the other side. When multiple programs have to share a large block of data, copying the data from back and forth between them is wasteful. If you sprinkle some "everything is a file" magic on a block of RAM, both programs can work with the same data at the same time. That's known as a 'memory-mapped file'.

From there, it's just a short conceptual hop to using memory-mapped files as a way for regular programs to communicate with the kernel.

That's what the /sys file tree is: an "everything is a file" abstraction that lets you talk to the OS. That whole section of the file tree is basically a program running behind the scenes, created and maintained by the kernel. And since that whole file tree is an illusion maintained by the kernel, the kernel gets to decide what's there and how it behaves.

It would be lovely if the /sys file tree stayed the same from one version of Raspbian to the next, but the RasPi Foundation has a habit of changing things and letting everyone else adapt to it. To some degree that's necessary, and arguably a good practice in general, since maintaining back-compatibility requires a lot of time and effort. And since updating to the latest changes also takes time and effort, a lot of third-party developers won't update their code until you break it.

Raspbian recently did a version upgrade from the Stretch Linux kernel to Buster, with the usual breakage that goes with such a change.


Now.. in response to the specific issue you're dealing with:

Try stepping through the /sys file tree one layer at a time, using `ls` to find the current set of "I am an ordinary file" hooks at each level. How far can you get along a path that looks like /sys/class/backlight?

adafruit_support_mike
 
Posts: 58843
Joined: Thu Feb 11, 2010 2:51 pm

Re: Backlight control of 2.8" capacitive screen not working

by landshrk on Mon Aug 19, 2019 7:32 am

THAT was a fantastic explanation! Thank you! Definitely makes me feel better that I'm not fouling something up with this. I guess they've moved where the backlight controls are, then? Gonna hafta dig into that a bit more, maybe this evening, assuming no one chimes in with the updated info before then.

As for your question: /sys/class/backlight is still there, but the dir is empty. No output for "ls" when sitting in there. And, given the nature of the /sys area, I now understand why I couldn't just brute-force sudo mkdir in there. That operation is definitely not allowed!

Thank you, again, for the clear and concise explanation on the "what's going on" here. I've been mucking about in various Linux distros for a couple months, not really doing much, just using them as an alternative OS on a couple old laptops. There is still MUCH I have to learn.

landshrk
 
Posts: 10
Joined: Mon Aug 19, 2019 12:17 am

Re: Backlight control of 2.8" capacitive screen not working

by adafruit_support_mike on Mon Aug 19, 2019 10:36 pm

Start with `ls /sys`, find the contents, and move down one level at a time.

adafruit_support_mike
 
Posts: 58843
Joined: Thu Feb 11, 2010 2:51 pm

Re: Backlight control of 2.8" capacitive screen not working

by landshrk on Tue Aug 20, 2019 12:18 am

I did that when I was searching for the issue initially. I don't remember all the contents any more, but /sys/class contained the /backlight directory when I first made my way there. That directory, however, is and was empty.

If you'd like a listing of what's in /sys and /sys/class, I'll happily provide it, of course!

landshrk
 
Posts: 10
Joined: Mon Aug 19, 2019 12:17 am

Re: Backlight control of 2.8" capacitive screen not working

by adafruit_support_mike on Wed Aug 21, 2019 12:02 am

Please do.. let's see what else is there.

adafruit_support_mike
 
Posts: 58843
Joined: Thu Feb 11, 2010 2:51 pm

Re: Backlight control of 2.8" capacitive screen not working

by landshrk on Wed Aug 21, 2019 4:22 pm

Alright. Let's get a run-down, see if we can hunt anything down!

Code: Select all | TOGGLE FULL SIZE
ls of /
bin boot boot.bak dev etc home lib lost+found media mnt opt proc root run sbin soc srv sys tmp usr var

Code: Select all | TOGGLE FULL SIZE
ls of /sys/
block bus class dev devices firmware fs kernel module power

Code: Select all | TOGGLE FULL SIZE
ls of /sys/class/
backlight bluetooth graphics ieee80211 iscsi_iface mdio_bus power_supply rfkill sound tty vc-mem
bcm2708_vcio bsg hidraw input iscsi_session mem pwm rtc spidev uio vc-sm
bcm2835-gpiomem devcoredump hwmon iscsi_connection iscsi_transport misc raw scsi_device spi_master usbmisc video4linux
bdi dma i2c-adapter iscsi_endpoint leds mmc_host rc scsi_disk spi_slave vc vtconsole
block gpio i2c-dev iscsi_host lirc net regulator scsi_host thermal vchiq watchdog

Code: Select all | TOGGLE FULL SIZE
ls of /sys/class/backlight
*EMPTY*


Before I spend hours going through all these directories and files, you see anything that looks like it might be worth investigating?

I'm also going to take this info and see if anyone else out there has posted about getting the backlight controls to work in Buster. Maybe someone's already figured out where it is now. Maybe it doesn't exist natively anymore, and there's a bodge to get it to work again. Who knows? I'll post anything I find out here, though.

Edited to clean up code output.
Last edited by landshrk on Wed Aug 21, 2019 5:05 pm, edited 1 time in total.

landshrk
 
Posts: 10
Joined: Mon Aug 19, 2019 12:17 am

Re: Backlight control of 2.8" capacitive screen not working

by landshrk on Wed Aug 21, 2019 4:48 pm

So, doing a little digging, it looks like one option might be to allow GPIO 18 to control backlight output. While I'm all for tweaking things to make them work, and am fully on-board with this, assuming I can then use
Code: Select all | TOGGLE FULL SIZE
    gpio -g mode 18 pwm
    gpio -g pwm 18 100
    gpio -g pwm 18 1000
    gpio -g pwm 18 0
as a method of controlling it automatically.

Any thoughts on this method? Like I said above, I'd like to explore less permanent options first, if they're available, as I'm not certain this Pi+HAT combo will stay a PiHole forever. Girlfriend is already asking me to make her a weather station, so who knows how long this'll last here!

And just so you're aware, there was a decently large update I just received. Even after a reboot, no dice on the original
Code: Select all | TOGGLE FULL SIZE
sudo sh -c 'echo "0" > /sys/class/backlight/soc\:backlight/brightness'

landshrk
 
Posts: 10
Joined: Mon Aug 19, 2019 12:17 am

Re: Backlight control of 2.8" capacitive screen not working

by landshrk on Wed Aug 21, 2019 4:59 pm

I also found this little program from Jakeh12, useful to control backlight power. However, it also relied on there being... well, something in /sys/class/backlight.

Cloned, installed, made, and granted permissions according to instructions anyway. Unsurprisingly, it did not work. Here's the output of rpi-backlight min:
Code: Select all | TOGGLE FULL SIZE
ERROR: '/sys/class/backlight/rpi_backlight/bl_power' does not exist/insufficient permissions.
Like I said, no real surprise there.

landshrk
 
Posts: 10
Joined: Mon Aug 19, 2019 12:17 am

Re: Backlight control of 2.8" capacitive screen not working

by landshrk on Wed Aug 21, 2019 5:34 pm

Huh. Well. Ok. Here's a thing.

Messing around with nothing to lose, I decided to run

Code: Select all | TOGGLE FULL SIZE
gpio -g mode 18 pwm
gpio pwmc 1000
gpio -g pwm 18 10
and guess what? It works.

I did this because of this article mentioning that this is the older way of controlling the backlight, when the backlight object did not exist. I figured "well, the backlight object doesn't exist for me, let's see what happens."

Now, let's see if I can get it to work in crontab!

I'll report back with any findings.

landshrk
 
Posts: 10
Joined: Mon Aug 19, 2019 12:17 am

Re: Backlight control of 2.8" capacitive screen not working

by adafruit_support_mike on Thu Aug 22, 2019 1:20 am

One more thing: try the command `ls -l /sys/class/backlight`

It's possible that they folded the whole control interface into the item named 'backlight'. If so, it will probably appear as a file instead of a directory.

adafruit_support_mike
 
Posts: 58843
Joined: Thu Feb 11, 2010 2:51 pm

Re: Backlight control of 2.8" capacitive screen not working

by landshrk on Fri Aug 23, 2019 3:55 pm

Alright. I'll give that a try this evening when I get home, and post the results here. Thanks for all the help; maybe we'll figure out where they stuck the dang thing now!

landshrk
 
Posts: 10
Joined: Mon Aug 19, 2019 12:17 am

Re: Backlight control of 2.8" capacitive screen not working

by landshrk on Fri Aug 23, 2019 7:32 pm

Code: Select all | TOGGLE FULL SIZE
total 0


So yep, nothin' in there!

landshrk
 
Posts: 10
Joined: Mon Aug 19, 2019 12:17 am

Re: Backlight control of 2.8" capacitive screen not working

by adafruit_support_mike on Sat Aug 24, 2019 12:06 am

And that output means the system sees it as a directory.

It will probably be easier if you stick with the command to control GPIO #18 directly. The /sys/class/backlight interface is just another way to do that, and it looks like Buster has made using it harder than doing things the 'hard' way.

adafruit_support_mike
 
Posts: 58843
Joined: Thu Feb 11, 2010 2:51 pm

Re: Backlight control of 2.8" capacitive screen not working

by landshrk on Sat Aug 24, 2019 12:33 am

And that output means the system sees it as a directory.


That's very handy information. I'll keep that in my toolbox for future use.

Thank you for helping me through all this. I know I've learned a bit, and hopefully my problem brought something to light for you, too.

landshrk
 
Posts: 10
Joined: Mon Aug 19, 2019 12:17 am

Please be positive and constructive with your questions and comments.