CM3-Panel-7-basic technical documentation Buy

How to set the CM3-Panel backlight brightness

The LCD backlight level is managed by a PWM signal sent to the GPIO 22 line. This article is explaided how to control it using

Set the brightness using the Pyhton RPi.GPIO library

This example set the ten level of brightness each 1 sec

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setup(22, GPIO.OUT)
pwm=GPIO.PWM(22, 100)
pwm.start(0)

for dc in range(0,110,10):
        print dc
        pwm.ChangeDutyCycle(100-dc)
        time.sleep(1)

pwm.stop()
GPIO.cleanup()

Set the brightness 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

Home page CM3-Panel-7-basic technical documentation Buy