Using pigpio to controll the CM3-Panel backlight

The LCD backlight level is managed by a PWM signal sent to the GPIO 22 line. This line is not an hardware PWM line so in this article is explaided how to control it in bitbanging using the pigpio utility

Pigpio is a library for the Raspberry Pi which allows control of the General Purpose Input Outputs (GPIO). The main features are:

  • hardware timed sampling and time-stamping of GPIO 0-31 every 5 us
  • hardware timed PWM on all of GPIO 0-31
  • hardware timed servo pulses on all of GPIO 0-31
  • callbacks on GPIO 0-31 level change (time accurate to a few us)
  • notifications via pipe on GPIO 0-31 level change
  • callbacks at timed intervals
  • reading/writing all of the GPIO in a bank (0-31, 32-53) as a single operation
  • GPIO reading, writing, modes, and internal pulls
  • socket and pipe interfaces for the bulk of the functionality
  • waveforms to generate GPIO level changes (time accurate to a few us)
  • software serial links using any user GPIO
  • rudimentary permission control through the socket and pipe interfaces
  • creating and running scripts on the pigpio daemon

To install the pigpio utility type:

sudo apt update
sudo apt install pigpio

To install the python-pigpio useful to test the PWM backlight in Python type:

sudo apt install python-pigpio

Run pigpiod

sudo pigpiod -

Try this code example in Python. It wil turn off the screen for 1 sec and the turn on

import pigpio
import time

port=pigpio.pi() 

port.write(22,1)
time.sleep(1)
port.write(22,0)

This second example set the brightness level each second

import pigpio
import time

port=pigpio.pi() 

port.set_PWM_range(22,100)

# Brightness  25%
port.set_PWM_dutycycle(22,100-25)
time.sleep(1)

# Brightness  50%
port.set_PWM_dutycycle(22,100-50)
time.sleep(1)

# Brightness  75%
port.set_PWM_dutycycle(22,100-75)
time.sleep(1)

# Brightness  100%
port.set_PWM_dutycycle(22,100-100)

Links

  • http://abyz.me.uk/rpi/pigpio/pigpiod.html
  • https://www.npmjs.com/package/node-red-node-pi-gpiod
  • https://www.tanzolab.it/pigpio
Bruna Mandolino