Analog as Digital Help

Topics about the Hardware of Revolution Pi
Post Reply
Vickkram
Posts: 4
Joined: 23 Jan 2024, 17:08

Analog as Digital Help

Post by Vickkram »

Hello,

I have a RevPi Connect S with a MIO module attached.

I was following the steps outlined on this page: https://revolutionpi.com/en/tutorials/a ... gurieren-2 regarding configuring a analog output as a digital output.

I am trying to use the pasted code (code1) to use the pi to control a motor to lock and unlock an inlet. However I don't hear a response from the motor when I use a separate script to call the lockinlet function. I tested the inlet already and know that it is functional. I ran a separate script (code2), and had the pi set AnalogOutput_1 to high, (which as per my pictory config would send a 5V signal), but when I use a multimeter to measure the pin I do not see a change in the voltage.

I am really new to this device and pictory in general and would really appreciate some help. I have pasted my code below and attached my pictory configurations.

Looking forward to your response,
Vickkram


CODE 1: ----------------------------------------------------------------------------------------
import time
import revpimodio2

# Defining analog input channels
ANALOGINPUT_TEMP_PIN = "AnalogInput_1"
ANALOGINPUT_PP_PIN = "AnalogInput_2"
ANALOGINPUT_LCK_PIN = "AnalogInput_3"

# Defining digital output channels

ANALOGOUTPUT_LOCK_PIN_POS = "AnalogOutput_1"
ANALOGOUTPUT_LOCK_PIN_NEG = "AnalogOutput_2"

# Constants
VDD = 5
INLET_UNLOCKED = 0
INLET_LOCKED = 1

rpi = revpimodio2.RevPiModIO(autorefresh=True)

def getVoltage(pin):
return rpi.io[pin].value/1000

def getLCLState():
voltage = getVoltage(ANALOGINPUT_LCK_PIN)
current = (VDD - voltage)/1000
PTC_res = voltage/current
print(PTC_res)
print("Voltage of Lock State:" + str(voltage))
if(PTC_res>100 and PTC_res <2000):
return INLET_UNLOCKED
elif(PTC_res>10000):
return INLET_LOCKED
else:
return -1

def lockInlet(retry=0):

rpi.io[ANALOGOUTPUT_LOCK_PIN_POS].value = 1

time.sleep(.5)

rpi.io[ANALOGOUTPUT_LOCK_PIN_POS].value = 0

state = getLCLState()
if state == INLET_LOCKED:
print("Inlet Locked")
return 1
elif retry == 0:
print("problem with inlet locking - trying one more time")
return lockInlet(retry=1)
else:
print("locking error")
return -1

def unlockInlet(retry = 0):
rpi.io[ANALOGOUTPUT_LOCK_PIN_NEG].value = 1
time.sleep(.5)
rpi.io[ANALOGOUTPUT_LOCK_PIN_NEG].value = 0

state = getLCLState()
if state == INLET_UNLOCKED:
return 1
elif retry == 0:
time.sleep(.5)
return(unlockInlet(retry = 1))
else:
#TODO: ERROR OUT or try one more time then error out
return -1
---------------------------------------------------------------------------------------------

CODE 2: -----------------------------------------------------------------------------------

import revpimodio2
import time

rpi = revpimodio2.RevPiModIO(autorefresh=True)

ANALOG_INPUT = "AnalogInput_1"
DIGITAL_OUTPUT = "AnalogOutput_1"

try:
while True:
value = 1

rpi.io[DIGITAL_OUTPUT].value = value

print(f"Value: {value}")

time.sleep(1)
finally:
rpi.cleanup()

--------------------------------------------------------------------------------------------------------------
Attachments
pictoryconfigpart3.JPG
pictoryconfigpart2.JPG
pictoryconfigpart1.JPG
Vickkram
Posts: 4
Joined: 23 Jan 2024, 17:08

Re: Analog as Digital Help

Post by Vickkram »

I wanted to follow up on this thread with an update:

I realized that piTest -d showed "module is not present data is not available" I was hoping this might be the solution to my problem so I followed some previous forum inquiries, deleted the mio slot from pictory, put it back and reset the driver.

Now both devices are found but my connect module has a solid red light and my mio module has a flashing red light.

Attached is what piTest -d shows.

I hope this helps. Please get back to me as soon as you can
Attachments
moduleinfo.png
u.biakoup
KUNBUS
Posts: 183
Joined: 14 Apr 2022, 13:04

Re: Analog as Digital Help

Post by u.biakoup »

Hello Vickkram,
I tried to reproduce your issue with Revpi Connect 4 and revpi MIO. Your configuration appears to be okay, but it seems like you are using the wrong variable. In tested your code 2 with the following code and I was able to get 5V to the analogue output1 by setting the bit for the variable "AnalogOutputLogicLevel_1" to 1.

Notice: use the variable "WAnalogOutputLogicLevel_1" instead of "AnalogOutput_1"

Code: Select all

import revpimodio2
import time

rpi = revpimodio2.RevPiModIO(autorefresh=True)

ANALOG_INPUT = "AnalogInput_1"
DIGITAL_OUTPUT = "AnalogOutputLogicLevel_1"

try:
    while True:
        value = 1

        rpi.io[DIGITAL_OUTPUT].value = value

        print(f"Value: {value}")

        time.sleep(1)
finally:
    rpi.cleanup()
u.biakoup
KUNBUS
Posts: 183
Joined: 14 Apr 2022, 13:04

Re: Analog as Digital Help

Post by u.biakoup »

Vickkram wrote: 09 Feb 2024, 23:28 I wanted to follow up on this thread with an update:

I realized that piTest -d showed "module is not present data is not available" I was hoping this might be the solution to my problem so I followed some previous forum inquiries, deleted the mio slot from pictory, put it back and reset the driver.

Now both devices are found but my connect module has a solid red light and my mio module has a flashing red light.

Attached is what piTest -d shows.

I hope this helps. Please get back to me as soon as you can
Which LED flashes on both the Modules?
For more detailed information about the Status LEDs of MIO have a look here
For connect S have a look here

Best Regards

Ulrich Kouatang Biakoup | Technical Support
Vickkram
Posts: 4
Joined: 23 Jan 2024, 17:08

Re: Analog as Digital Help

Post by Vickkram »

Hello Ulrich,

Thank you so much for your response. I have tried the switching the variable and I still don't see the 5V signal when I hold a multimeter to the output.

The IN light on the MIO module is flashing red. The documentation suggested that this happens when one of the input pins is being given a voltage higher than the allowed 10V, but this is flashing even when I have all inputs disconnected. The PWR led is also a solid red on the Connect S module. I have checked all of the cables and it is hooked up to a 24V power supply. When measuring the voltage on a multimeter I can see both the connect s module and the mio module are receiving about 21V. The PE is connected to the ground of the power supply.

Let me know if you have any suggestions as to what I should try? All of my inputs before being disconnected were around 4.9V, nothing close to 10V to warrant the flashing.

Looking forward to your response,
Vickkram
u.biakoup
KUNBUS
Posts: 183
Joined: 14 Apr 2022, 13:04

Re: Analog as Digital Help

Post by u.biakoup »

Hello Vickram,

It appears that the RevPi MIO device may be faulty. If the device is still under warranty, you can file a claim with the seller for a replacement. please complete the defective form enclosed in this ticket. and write a messagewhen you are done

Best regards
Vickkram
Posts: 4
Joined: 23 Jan 2024, 17:08

Re: Analog as Digital Help

Post by Vickkram »

Hello Ulrich,

I replaced the MIO module with another one that I had in stock. Now the connect S module lights are all green, and the IN on the MIO module is no longer flashing. But the Power led on the MIO module is a solid red. I have checked the power supply connections and it is currently being given around 21V and all connections seem to be in good condition.

When I do piTest -d it says the module is not present and data is not available. When I go into pictory and press save as start config and do sudo reboot all the lights on the MIO module are green, but the power led on the connect s module is red. When I do save as start config and then press reset driver, the connect s module leds turn green but the solid red power led on the mio module comes back.

Do you know what I am doing wrong? I think something in the configuration is just incorrect?

Thank you,
Vickkram
u.biakoup
KUNBUS
Posts: 183
Joined: 14 Apr 2022, 13:04

Re: Analog as Digital Help

Post by u.biakoup »

Hello Vikram,
could you post here the output of the command

Code: Select all

cat/proc/version
?

If you can log in to the device, you can provide me a SOS-Report and send me that through the Tickets you opened
Best Regards

Ulrich Kouatang Biakoup | Technical Support
Post Reply