Inputs not updating
Posted: 15 Aug 2017, 16:27
I have 2 modules connected together a Rev Pi Core 3 and Rev Pi DIO modules. I have configured them using the PICtory tool as follows:
1) Rev Pi Core V1.2 5 input and 3 outputs
2) Rev PI DIO 34 input and 32 outputs.
I have connected a Sunfounder Metal Touch sensor to I_1 ( input I1) of the DIO module. The sensor should report a 0 when the sensor is not touched and 1 when the sensor is touched. Using the python examples for RevPI I found at https://revpimodio.org/en/homepage/ I wrote some python code to read the values coming from the sensor then set the color of the A1 led. The problem I am having is the Input I_1 always reads as 0 even if the sensor has been touched. It appears that I am not getting updates on the inputs. I have set the auto_refresh flag to true and even called the readprocimg method. However no matter what I do I cannot get the inputs to update. I have the sensor digital input wire connected to the I1 input on the DIO module. I have included my python code below. Would appreciate any help that you may be able to provide. Also I can get the metal touch sensor to work correctly using a regular raspberry pi 3.
I have also run the piTest –r I_1 to monitor the value of I_1. This also always reports I_1 as a 0. Thank you for any help you can provide.
import revpimodio
import RPi.GPIO as GPIO
import time
from time import sleep
class Sensor:
def loop(self):
#self.myrevpi.devices.readprocimg()
if self.myrevpi.devices["RevPi DIO"]["I_1"].value == 0:
print ('...led Green')
self.myrevpi.devices.core.A1 = revpimodio.GREEN
#GPIO.output(LedPin, GPIO.LOW) # led on
else:
print ('led Red...')
self.myrevpi.devices.core.A1 = revpimodio.RED
#GPIO.output(LedPin, GPIO.HIGH) # led off
def destroy(self):
#GPIO.output(LedPin, GPIO.HIGH) # led off
#GPIO.cleanup() # Release resource
self.myrevpi.devices.core.A1 = revpimodio.OFF
self.myrevpi.devices.core.A2 = revpimodio.OFF
def setup(self):
self.myrevpi.devices.core.A1 = revpimodio.OFF
self.myrevpi.devices.core.A2 = revpimodio.OFF
def __init__(self):
self.myrevpi = revpimodio.RevPiModIO(auto_refresh=True)
if __name__ == '__main__': # Program start from here
sensor = Sensor()
sensor.setup()
try:
while True:
sensor.loop()
sleep(1)
except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed.
sensor.destroy()
1) Rev Pi Core V1.2 5 input and 3 outputs
2) Rev PI DIO 34 input and 32 outputs.
I have connected a Sunfounder Metal Touch sensor to I_1 ( input I1) of the DIO module. The sensor should report a 0 when the sensor is not touched and 1 when the sensor is touched. Using the python examples for RevPI I found at https://revpimodio.org/en/homepage/ I wrote some python code to read the values coming from the sensor then set the color of the A1 led. The problem I am having is the Input I_1 always reads as 0 even if the sensor has been touched. It appears that I am not getting updates on the inputs. I have set the auto_refresh flag to true and even called the readprocimg method. However no matter what I do I cannot get the inputs to update. I have the sensor digital input wire connected to the I1 input on the DIO module. I have included my python code below. Would appreciate any help that you may be able to provide. Also I can get the metal touch sensor to work correctly using a regular raspberry pi 3.
I have also run the piTest –r I_1 to monitor the value of I_1. This also always reports I_1 as a 0. Thank you for any help you can provide.
import revpimodio
import RPi.GPIO as GPIO
import time
from time import sleep
class Sensor:
def loop(self):
#self.myrevpi.devices.readprocimg()
if self.myrevpi.devices["RevPi DIO"]["I_1"].value == 0:
print ('...led Green')
self.myrevpi.devices.core.A1 = revpimodio.GREEN
#GPIO.output(LedPin, GPIO.LOW) # led on
else:
print ('led Red...')
self.myrevpi.devices.core.A1 = revpimodio.RED
#GPIO.output(LedPin, GPIO.HIGH) # led off
def destroy(self):
#GPIO.output(LedPin, GPIO.HIGH) # led off
#GPIO.cleanup() # Release resource
self.myrevpi.devices.core.A1 = revpimodio.OFF
self.myrevpi.devices.core.A2 = revpimodio.OFF
def setup(self):
self.myrevpi.devices.core.A1 = revpimodio.OFF
self.myrevpi.devices.core.A2 = revpimodio.OFF
def __init__(self):
self.myrevpi = revpimodio.RevPiModIO(auto_refresh=True)
if __name__ == '__main__': # Program start from here
sensor = Sensor()
sensor.setup()
try:
while True:
sensor.loop()
sleep(1)
except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed.
sensor.destroy()