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 Use
try:
    your Code
finally:
construction and the GPIO.cleanup method.

Required Component connect  LED Raspberry Pi :

1.Raspberry pi
 
 
 
 
 

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 leads

Connecting an LED to a Raspberry Pi

Connecting 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,

If you want to know more about raspberry pie then click on the link below

RASPBERRY PI TUTORIALS FOR BEGINNERS

No comments

Theme images by Dizzo. Powered by Blogger.