How to Safe on GPIO Pin in raspberry pi
You want all the GPIO pins to be set to inputs whenever your program exits so that there is less of a chance of an accidental short on the GPIO header, which could damage your Raspberry Pi. Today I Show you How How Safe GPIO Pin in raspberry pi in easy Process you just use Usetry:
your Code
finally:
construction and the GPIO.cleanup method.
Required Component connect LED Raspberry Pi :
1.Raspberry pi 5. 5mm LED
This book will help you to gain more knowledge of Raspberry pi Software and Hardware Problems and Solutions
Raspberry Pi Cookbook
Circuit diagram :
shows how you can wire this LED using a solderless breadboard and male-to-female jumper leadsConnecting an LED to a Raspberry Pi4
Code Safe GPIO Pin in raspberry pi:import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
try:
while (True):
GPIO.output(18, True)
time.sleep(0.5)
GPIO.output(18, False)
time.sleep(0.5)
finally:
print("Cleaning Up!")
GPIO.cleanup()
when you start wiring up a new project, unaware of this problem, your new circuit might accidentally short a GPIO output to one of the supply rails or another GPIO pin in the opposite state. A typical scenario where this might happen would be if you were to connect a push switch, connecting a GPIO pin that you had configured as an output and HIGH to GND,

No comments