0

Can you give me an idea on how to check the statuses of specific GPIO pins if it is HIGH or LOW? My project is all about checking the statuses of GPIO pins (6 GPIO pins). I want to check all of the pins at once and send a SMS message the statuses of the pins if it is HIGH or LOW. This the head start of my program.

If I send a message powerrefreshall it will trigger this:

SendSMS(ser,14)
print "Refresh ALL Relays"

this is my SendSMS method:

def SendSMS (ser,value):
  ser.write("AT\r")
  line = ser.read(size = 64)
  print line
  ser.write('AT+CMGS = "09073096***"\r')
  if (value == 14):
     if (GPIO.input(3) == 0):
        ser.write('lightbulbon')
     elif (GPIO.input(3) == 1):
        ser.write('lightbulboff')

I don't know how to check the 5 other pins all at once. I am lost.

1

To check the state of each gpio on the extension header you could use read_bank_1 from Python or gpioRead_Bits_0_31 from C.

To check the state of all the gpios you are interested in you could use a mask.

Mask off all but the gpios you want and then compare against the states in which you are interested.

e.g. suppose the gpio state is read by one of the above into variable gpio_state.

If you are interested in gpios 4 , 7, 9, 10 then construct a variable mask of (1<<4) | (1<<7) | (1<<9) | (1<<10). Then setting variable now_state to gpio_state & mask would isolate the gpios of interest.

If you wanted to check that

  • all the gpios are high check that now_state equals mask.
  • all the gpios are low check that now_state equals 0.
  • that gpios 4 and 10 are high the others low check that now_state equals (1<<4) | (1<<10).

etc. etc.

0

Why do you want to "check all of the pins at once"?

It is possible to read certain groups of pins by manipulating the BMC registers, but this is not usual, and I know of no existing code to do this.

You would be better to read the values of the pins of interest, then process the resultant values.

If you are concerned that some may change after the others have been read, you should be writing in c or assembler

  • I've been able to read all the GPIO pins all at once but unable to send the SMS the statuses of the pins one at a time. That is my problem now. Sending SMS messages every state of the pins. – Michael Vincent Montero Dec 29 '14 at 8:10
0

I have been able to check all the gpio pins individually..

if (value == 14):
   if (GPIO.input(5) == 0):
      ser.write('1')
   else:
      ser.write('0')
   if (GPIO.input(11) == 0):
      ser.write('1')
   else:
      ser.write('0')
   if (GPIO.input(7) == 0):
      ser.write('1')
   else:
      ser.write('0')
   if (GPIO.input(13) == 0):
      ser.write('1')
   else:
      ser.write('0')
   if (GPIO.input(3) == 0):
      ser.write('1')
   else:
      ser.write('0')
   if (GPIO.input(15) == 0):
      ser.write('1')
   else:
      ser.write('0')
ser.write(chr(26))
return

if the gpio pins states are LOW, the message that will be sent is 111111 if the gpio pins states are HIGH, the message that will be sent is 000000 if gpio pin 5 is LOW, the message that will be sent is 100000 and so on with 64 combinations... I am controlling an active-low relay

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.