I'm currently performing some work for our client who has just purchased a RevPi Connect 4 and a MIO, we are currently attempting to read an input voltage (AnalogInput_1) and based on that reading, turn an output (AnalogOutput_1) either on (10v) or off (0v).
So far I am successfully able to read the input without issue and have confirmed that the reading is correct, the problem I am now having is controlling our output. When i try to set AnalogOutput_1 to 10v nothing happens, however when i set a value of 0 the voltage increases to 10v and after this I am unable to alter the voltage. I have followed the tutorial and have set the following for AnalogOutput_1:
- AnalogOutputLogicLevel_1: 0
- AnalogOutput_1: 10000
- AnalogOutputMode_1: analogOutput
- OutputLogicLevelVoltage_1: 0
My code is below:
Code: Select all
import time
import revpimodio2
def loop(cycletools):
timestamp_milliseconds = int(round(time.time() * 1000))
#list = revpimodio2.io.IOList()
#print(revpimodio2.io["AnalogInput_1"])
analog_value1 = rpi.io.AnalogInput_1.value
#voltage stays at 0v
#rpi.io.AnalogOutput_1.value = 10000
#voltage goes to 10v and is stuck
#rpi.io.AnalogOutput_1.value = 0
#voltage goes to 10v and is stuck
#rpi.io.AnalogOutput_1.value = 1
#what we ideally need
if(analog_value1 > 1000):
#turn output to 10v
rpi.io.AnalogOutput_1.value = 10000
else:
#turn output off (0v)
rpi.io.AnalogOutput_1.value = 0
analog_value2 = rpi.io.AnalogOutput_1.value
print(timestamp_milliseconds, analog_value1,analog_value2)
# create new instance of revpimodio2
rpi = revpimodio2.RevPiModIO(autorefresh=True)
# catch SIGINT and handle proper release of all IOs
rpi.handlesignalend()
# start cycle loop, cycle time in milliseconds
rpi.cycleloop(loop, cycletime=2000)
I'm probably doing something wrong so apologies. We are C# developers, we don't work with Python and IOT devices typically, any help would be appreciated. If you need anymore information please let me know.
Thanks
Matt.