This shows you the differences between two versions of the page.
| — | comfilepi:controlling_the_lcd_backlight:index [2026/02/20 15:37] (current) – created - external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Controlling the LCD Backlight ====== | ||
| + | The ComfilePi' | ||
| + | |||
| + | ^ Backlight Control | ||
| + | | On/ | ||
| + | | Dimming | ||
| + | |||
| + | These GPIO pins can be controlled in multiple ways using file-based interfaces, command line interfaces, or via a programming language. | ||
| + | |||
| + | ===== File-Based Interface ===== | ||
| + | |||
| + | The backlight control file-based interface was introduced with the ComfilePi Bookworm OS release. | ||
| + | |||
| + | File-based interfaces are nice, because they can be utilized from a terminal or any programming language' | ||
| + | |||
| + | Write a ' | ||
| + | |||
| + | Write a ' | ||
| + | |||
| + | Write a value from ' | ||
| + | ===== Command Line Interface ===== | ||
| + | |||
| + | ==== CPi-A/B/S ==== | ||
| + | |||
| + | To turn off the backlight: | ||
| + | <code console> | ||
| + | # using Bookworm | ||
| + | pinctrl set 34 op | ||
| + | pinctrl set 34 dl | ||
| + | |||
| + | # using Bullseye | ||
| + | raspi-gpio set 34 op | ||
| + | raspi-gpio set 34 dl | ||
| + | |||
| + | # using Buster or prior OSes | ||
| + | gpio mode 34 output | ||
| + | gpio write 34 0 | ||
| + | </ | ||
| + | |||
| + | To turn on the backlight: | ||
| + | < | ||
| + | # using Bookworm | ||
| + | pinctrl set 34 op | ||
| + | pinctrl set 34 dh | ||
| + | |||
| + | # using Bullseye | ||
| + | raspi-gpio set 34 op | ||
| + | raspi-gpio set 34 dh | ||
| + | |||
| + | # using Buster or prior OSes | ||
| + | gpio mode 34 output | ||
| + | gpio write 34 1 | ||
| + | </ | ||
| + | |||
| + | |||
| + | ==== CPi-C ==== | ||
| + | |||
| + | To turn off the backlight: | ||
| + | <code console> | ||
| + | # using Bookworm | ||
| + | pinctrl set 44 op | ||
| + | pinctrl set 44 dl | ||
| + | |||
| + | # using Bullseye | ||
| + | raspi-gpio set 44 op | ||
| + | raspi-gpio set 44 dl | ||
| + | |||
| + | # using Buster or prior OSes | ||
| + | gpio mode 44 output | ||
| + | gpio write 44 0 | ||
| + | </ | ||
| + | |||
| + | To turn on the backlight: | ||
| + | < | ||
| + | # using Bookworm | ||
| + | pinctrl set 44 op | ||
| + | pinctrl set 44 dh | ||
| + | |||
| + | # using Bullseye | ||
| + | raspi-gpio set 44 op | ||
| + | raspi-gpio set 44 dh | ||
| + | |||
| + | # using Buster or prior OSes | ||
| + | gpio mode 44 output | ||
| + | gpio write 44 1 | ||
| + | </ | ||
| + | |||
| + | ===== Sample C Program ===== | ||
| + | The backlight can be controlled in the C programming language using the [[https:// | ||
| + | |||
| + | <code c> | ||
| + | #include < | ||
| + | |||
| + | #define PIN 34 // CPi-A/B/F/S | ||
| + | // #define PIN 44 // CPi-C | ||
| + | |||
| + | void backlight_on() | ||
| + | { | ||
| + | auto instance = pigpio_start(NULL, | ||
| + | |||
| + | set_mode(instance, | ||
| + | gpio_write(instance, | ||
| + | |||
| + | pigpio_stop(instance); | ||
| + | } | ||
| + | |||
| + | void backlight_off() | ||
| + | { | ||
| + | auto instance = pigpio_start(NULL, | ||
| + | |||
| + | set_mode(instance, | ||
| + | gpio_write(instance, | ||
| + | |||
| + | pigpio_stop(instance); | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ===== Adding Screensaver Functionality ===== | ||
| + | |||
| + | [[: | ||
| + | |||
| + | [[: | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ===== Dimming the Backlight ===== | ||
| + | |||
| + | Backlight dimming can be controlled using the PWM on GPIO31 on the CPi-A/B/S or GPIO26 on the CPi-C. | ||
| + | |||
| + | <code Cpp> | ||
| + | |||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | using namespace std; | ||
| + | |||
| + | #define PIN 31 // CPi-A/B/F/S | ||
| + | // #define PIN 26 // CPi-C | ||
| + | |||
| + | int main(int argc, char *argv[]) | ||
| + | { | ||
| + | int value = stoi(argv[1]); | ||
| + | |||
| + | auto instance = pigpio_start(NULL, | ||
| + | |||
| + | | ||
| + | |||
| + | | ||
| + | |||
| + | | ||
| + | |||
| + | | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | Compile and run: | ||
| + | < | ||
| + | g++ backlight.cpp -lpigpiod_if2 -lpthread -o backlight | ||
| + | |||
| + | ./backlight 0 # minimum brightness | ||
| + | ./backlight 128 # medium brightness | ||
| + | ./backlight 255 # maximum brightness | ||
| + | </ | ||
| + | ===== Hardware Revisions ===== | ||
| + | |||
| + | ==== v2.0+ ==== | ||
| + | |||
| + | CPi_A070WR (S/N : A01001-17-7-11 ~ A01001-17-11-91) | ||
| + | |||
| + | CPi_A102WR (S/N : A01003-17-7-1 ~ A01003-17-10-26) | ||
| + | |||
| + | The initial ComfilePi that was produced did not populate R33 on the main board' | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | To test which hardware revision you have, simply run the commands illustrated above and see if they work. | ||
| + | |||
| + | ==== v2.1+ (Refer to hardware version printed on sticker) ==== | ||
| + | |||
| + | Hardware revision v2.1 connects the backlight to GPIO 31 which supports PWM. See [[# | ||
| + | |||
| + | [[comfilepi: | ||