Coconut Catalogue
coconutc.com

5) Sensor Interfacing

GPIO

GPIO stands for General Purpose Input Output.
These ports can be programmed for Input or Ouptut as per the requirement.

Built in Functions

Calling pin x and GPIO x are both different. GPIOs have:

Pins Numbers
Total Pins 40
GPIOs 26
Ground 8
3.3V DC 2
5V DC 2
I2C ID 2

GPIO pins are random and are not in orderly fashion because of convenience of PCB design.

Interfacing LED

led
led.py
from gpiozero import LED
from time import sleep

led=LED(17)

while True:
	led.on()
	sleep(1)
	led.off()
	sleep(1)
			

Then simply execute the code in Linux Terminal.

Linux Terminal
pi@raspberry:~$
pi@raspberry:~$ ls Desktop
led.py
pi@raspberry:~$ python Desktop/led.py

			

Interfacing Button

button
button.py
from gpiozero import LED, Button
from signal import pause

led=LED(17)'''led positive terminal is
connected to GPIO 17'''
button=Button(2)'''Button's one terminal is
connected to GPIO 2'''

button.when_pressed = led.on
button.when_released = led.off
while True:
	button.wait_for_press()
			
Linux Terminal
pi@raspberry:~$
pi@raspberry:~$ ls Desktop
button.py
pi@raspberry:~$ python Desktop/button.py

			
button
button.py
from gpiozero import LED, Button
from time import sleep

led=LED(17)'''led positive terminal is
connected to GPIO 17'''
button=Button(2)'''Button's one terminal is
connected to GPIO 2'''

while True:
	button.wait_for_press()
	led.toggle()
			
Linux Terminal
pi@raspberry:~$
pi@raspberry:~$ ls Desktop
button.py
pi@raspberry:~$ python Desktop/button.py

			

×