Akash Nil
Akash Nil

Reputation: 703

Read status of GPIO pins of Raspberry pi and send it through serial port

I want to read status of GPIO pins of raspberry pi send the data through serial port. if GPIO1 is ture GPIO2 is false GPIO3 is true GPIO4 is false. then i want to send 1010. again if i get 1010 through serial port then i want to assign them to gpio pins. I am using python2.7.how to do that?

Upvotes: 0

Views: 1887

Answers (1)

Anup Sarkar
Anup Sarkar

Reputation: 335

import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(4,GPIO.OUT)
GPIO.setup(17,GPIO.OUT)
GPIO.setup(22,GPIO.OUT)
GPIO.setup(23,GPIO.OUT)
GPIO.output(4,1)
GPIO.output(17,0)
GPIO.output(22,1)
GPIO.output(23,0)
i=GPIO.input(4)
j=GPIO.input(17)
k=GPIO.input(22)
l=GPIO.input(23)
data=[i,j,k,l]
ser.write(data)

Upvotes: 1

Related Questions