Inputs not updating

Topics about the Software of Revolution Pi
Post Reply
ustc
Posts: 9
Joined: 15 Aug 2017, 16:22
Answers: 0

Inputs not updating

Post by ustc »

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()
User avatar
volker
Posts: 1046
Joined: 09 Nov 2016, 15:41
Answers: 1

Re: Inputs not updating

Post by volker »

Hi ustc (funny name...),
you need to forget the software and start analyzing your hardware. I fear the sensor might be a npn type sensor. Please provide us with more information (link to the datasheet or at least link to the manufacturer and exact type of sensor). If the sensor is npn then you will not get anything else but 0 at the input. You could also use a voltmeter to check this. For an npn type sensor you must add a pullup resistor to 24V like 4.7 kOhm (exact value depends on the sensor and your supply voltage, e.g. 24 V could work with 1/8 Watt 4.7 kOhm resistor. Better way is to use a pnp type sensor which is switching against plus and not against GND.
Hope this helps,
Volker.,
Unser RevPi Motto: Don't just claim it - make it!
User avatar
volker
Posts: 1046
Joined: 09 Nov 2016, 15:41
Answers: 1

Re: Inputs not updating

Post by volker »

Update: You are not talking about this device here, are you?
Unbenannt.jpg
Unbenannt.jpg (32.24 KiB) Viewed 4303 times
This device is definitely not able to drive an industrial standard PLC input. DIO inputs have EN61131-2 switch level of about 9V. Anthing under 9V is a zero for such an input. This device is 5V operated and thus can never give a high (1) level to an industrial grade PLC input. If you want to test your software simply take a wire and connect I1 to 24V. You will see your LED A on and piTest to report a 1 for the input.

There would be some kind of exotic chance to get this touch device switching your input: Do not connect the 5V powersupply's GND to the input GND but instead connect it to plus of a 4.5 V battery and connect the minus of the 4.5 V battery to input GND of the DIO. This will level shift your touch device's output to swict between 4.5V and 4.5V+5V = 9.5V which should trigger the input 1.

Good luck,
Volker.
Unser RevPi Motto: Don't just claim it - make it!
ustc
Posts: 9
Joined: 15 Aug 2017, 16:22
Answers: 0

Re: Inputs not updating

Post by ustc »

Thank you for your response. I am going to check if my sensor is a NPN type. If it is a NPN I will get a PNP type sensor and give that a try.

Yes the sensor is of that type. Thank you for your information that clears up a lot of my questions.
Post Reply