CM Panel technical documentation Buy

GPIO management with pigpiod

This article explains how to use the GPIO lines available on EXP1 and EXP2 connector of CM-Panel using Python3 and pigpio library

Install pigpiod

sudo apt update
sudo apt install pigpiod
sudo apt install python3-pigpio

Launch the pigpiod daemon at startup by editing rc.local:

sudo nano /etc/rc.local

Add this line

/usr/bin/pgpiod
exit 0

Examples

Simple gpio input

import pigpio

gpio=pigpio.pi()

gpio.set_mode(28,pigpio.INPUT)
gpio.set_mode(29,pigpio.INPUT)


gpio.set_pull_up_down(28, pigpio.PUD_UP)
gpio.set_pull_up_down(29, pigpio.PUD_UP)

print(gpio.read(28))
print(gpio.read(29))

Simple gpio output

This example works well with the GPIO lines:

  • 25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41

and not with:

  • 22 works but change the LCD backlight state
  • 23 works but is used also for the led of Raspicam
  • 24 works but is used also for shutdown line of Raspicam
  • 42 used by the int line of touch screen
  • 43 used by the reset line of display
  • 44 and 45 are used for the I2C bus used by the touch screen and Raspicam

Example

import pigpio
import time

LED=27

gpio=pigpio.pi()
gpio.set_mode(LED,pigpio.OUTPUT)

while True:
    gpio.write(LED,0)
    time.sleep(1)
    gpio.write(LED,1)
    time.sleep(1)

Callback function on GPIO changes with steady filter

import pigpio
import time

def gpio_28(gpio, level, tick):
    print("GPIO 28 low")
    print(gpio, level, tick)
    return  

def gpio_29(gpio, level, tick):
    print("GPIO 29 low")
    print(gpio, level, tick)
    return  

gpio=pigpio.pi()

gpio.set_mode(28,pigpio.INPUT)
gpio.set_mode(29,pigpio.INPUT)


gpio.set_glitch_filter(28,50000)
gpio.set_glitch_filter(29,50000)

gpio.set_pull_up_down(28, pigpio.PUD_UP)
gpio.set_pull_up_down(29, pigpio.PUD_UP)

gpio.callback(28,pigpio.FALLING_EDGE,gpio_28)
gpio.callback(29,pigpio.FALLING_EDGE,gpio_29)

while True:
    time.sleep(1)
    print("Loop")

Links


Products related

CM-Panel-Basic

Features Index Buy

All-in-one 7 inch touch WiFi terminal powered by Raspberry Pi CM4S
  • 7 inch TFT display 800x480
  • Capacitive touch
  • MIPI Camera connector
  • WiFi @ 2.4 GHz
CM-Panel-POE

Features Index Buy

All-in-one 7 inch touch POE terminal powered by Raspberry Pi CM4S
  • 7 inch TFT display 800x480 pixel
  • Capacitive touch
  • Embedded micro UPS for safe shutdown
  • Power Over Ethernet @ 10/100 Mbit
  • Hi-resolution audio up to 384KHz@32bit
  • Real Time Clock with backup battery
  • 3 USB Host port
  • 1 RS485/422/RS232 port
  • 1 Relay
  • MIPI Camera connector
  • WiFi @ 2.4 GHz (optional)
CM-Home

Features Index Buy

Home Automation board powered by Raspberry Pi CM4S lite module
  • Power-in @ 12 to 24VDC
  • Double opto-isolated RS-485 ports
  • 2 relays
  • 2 USB 2.0 host port
  • Ethernet port at 10/100Mbit
  • MIPI Camera connector
  • Stereo audio out on 3.5 mm jack

Home page CM Panel technical documentation Buy