# GPIO using pigpiod

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

## 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 

* [pigpio library](http://abyz.me.uk/rpi/pigpio/python.html#set_mode)

<br/>
@include='adv_cmpanel' 

