I want to check state of GPIO pin when I start, a porgram. For example I have another program which changing state of pin ( if is low change to hihg, and if is high change to low). And now I want to write program what will be read current state of pin. But when I'll do this:
import RPi.GPIO as GP
GP.setmode(GP.BOARD)
NRpin=40
GP.setup(NRpin,GP.OUT) #now GPIO state is set to default (0)
when I am doing
GP.setup(NRpin,GP.OUT)
current state is replacing default state (low).
The question is: If is there any way to check current state?
I know I can do like this:
import RPi.GPIO as GP
import subprocess as sub
a=sub.check_output(['sudo', 'gpio', '-g','read','21'])
print a
but what if I don't have installed wiringpi on my Raspberry Pi? (gpio command is in wiringpi package).
I suppose it can look like:
if GP.output(NRpin,1)==True:
print "HI"
elif GP.output(NRpin,0)==True:
print "LO"
but without:
GP.setup(NRpin,GP.OUT)
I cannot use that code.
Give me some advices, prease:)