RevPi DIO output control
I am trying to trigger pwm pulses with a frequency of 2.5Hz but just found that on pictory it is only possible for a certain number of frequency values (40Hz being the lowest possible value).
Then I wrote a simple python script in order to switch the output pins ON and OFF with certain time sleep.
However after doing so, I have no error message but I don't get any output at the output pin.
Any input on how to solve it is much appreciated.
Best regards,
Then I wrote a simple python script in order to switch the output pins ON and OFF with certain time sleep.
However after doing so, I have no error message but I don't get any output at the output pin.
Any input on how to solve it is much appreciated.
Best regards,
HI,
it's somehow difficult to help without having your code. There are about 1000 possible coding errors, so please show at least your code in order to enable us to find the problem. Please also send a screen shot of your configuration and the value editor with the parameters for the output section. Please also run piTest -d on the command line and please post the system response to this command.
B.t.w., 2,5 HZ PWM is a quite low frequency. Are you trying to reduce the power for a heating device with that PWM output?
Here is the math for this scenario: Assuming you are using a single DIO on a RevPi Core 3 without any other modules connected to the PiBridge you will get a 3 to 4 ms cycle time. That means you are able to switch any IO off or on every 4 ms but with no faster intervall. A 2,5 Hz PWM would mean a period time of 400 ms. This would result in a PWM resolution of 1% (you could increase the on time in steps of 4 ms from 0 to 400 ms) which is pretty fine.
So yes, if you do use a python script and a timer you should be able to realize your sw PWM output.
it's somehow difficult to help without having your code. There are about 1000 possible coding errors, so please show at least your code in order to enable us to find the problem. Please also send a screen shot of your configuration and the value editor with the parameters for the output section. Please also run piTest -d on the command line and please post the system response to this command.
B.t.w., 2,5 HZ PWM is a quite low frequency. Are you trying to reduce the power for a heating device with that PWM output?
Here is the math for this scenario: Assuming you are using a single DIO on a RevPi Core 3 without any other modules connected to the PiBridge you will get a 3 to 4 ms cycle time. That means you are able to switch any IO off or on every 4 ms but with no faster intervall. A 2,5 Hz PWM would mean a period time of 400 ms. This would result in a PWM resolution of 1% (you could increase the on time in steps of 4 ms from 0 to 400 ms) which is pretty fine.
So yes, if you do use a python script and a timer you should be able to realize your sw PWM output.
Unser RevPi Motto: Don't just claim it - make it!
Hi,
Thanks for your reply!
I am using a RevPi Core with a single DIO module. I am trying to generate PWM-like pulses which will be used by another device for decoding specific commands.
The first time I logged into Pictory there was no module in it, but a blank "0" space where I dragged the Base module into (RevPi Core). Then 2 spaces appeared automatically on the left and right of the base module. Having only the DIO module, I dragged it into the right side of the Base Module.
I configured the Outpin pins 1 and 2 as PWM at 40Hz. But since it is not the frequency I want I tried to control the output pin 3.
Here is the Python script:
import time
import revpimodio2
myrevpi = revpimodio2.RevPiModIO(autorefresh=True) # Instantiate RevPiModIO. This will read the piCtory configuration automatically.
while True:
myrevpi.io.O_3.value=True
time.sleep(.025)
myrevpi.io.O_3.value=False
time.sleep(.375)
And here comes the response at the terminal:
pi@RevPi5038:~ $ piTest -d
Found 3 devices:
Address: 0 module type: 95 (0x5f) RevPi Core V1.2
Module is present, but NOT CONFIGURED!!!
input offset: 0 length: 6
output offset: 6 length: 5
Address: 32 module type: 96 (0x60) RevPi DIO V1.3
Module is present
input offset: 2 length: 70
output offset: 72 length: 18
Address: 0 module type: 32863 (0x805f) RevPi Core V0.0
Module is NOT present, data is NOT available!!!
input offset: 0 length: 1
output offset: 1 length: 1
Below are attached the screen shots of the output configurations and the scope response:
https://drive.google.com/drive/folders/ ... sp=sharing
Thanks for your reply!
I am using a RevPi Core with a single DIO module. I am trying to generate PWM-like pulses which will be used by another device for decoding specific commands.
The first time I logged into Pictory there was no module in it, but a blank "0" space where I dragged the Base module into (RevPi Core). Then 2 spaces appeared automatically on the left and right of the base module. Having only the DIO module, I dragged it into the right side of the Base Module.
I configured the Outpin pins 1 and 2 as PWM at 40Hz. But since it is not the frequency I want I tried to control the output pin 3.
Here is the Python script:
import time
import revpimodio2
myrevpi = revpimodio2.RevPiModIO(autorefresh=True) # Instantiate RevPiModIO. This will read the piCtory configuration automatically.
while True:
myrevpi.io.O_3.value=True
time.sleep(.025)
myrevpi.io.O_3.value=False
time.sleep(.375)
And here comes the response at the terminal:
pi@RevPi5038:~ $ piTest -d
Found 3 devices:
Address: 0 module type: 95 (0x5f) RevPi Core V1.2
Module is present, but NOT CONFIGURED!!!
input offset: 0 length: 6
output offset: 6 length: 5
Address: 32 module type: 96 (0x60) RevPi DIO V1.3
Module is present
input offset: 2 length: 70
output offset: 72 length: 18
Address: 0 module type: 32863 (0x805f) RevPi Core V0.0
Module is NOT present, data is NOT available!!!
input offset: 0 length: 1
output offset: 1 length: 1
Below are attached the screen shots of the output configurations and the scope response:
https://drive.google.com/drive/folders/ ... sp=sharing
- Attachments
-
- PictoConf.PNG (85.16 KiB) Viewed 16920 times
Hi,
you use the wrong verison of RevPi Core in your pictory configuration. Please use V1.2. You can just drag V1.2 from the list on the left and drop it on the Core in the main window.
When you call piTest -d only 2 devices should be displayed. Both with status 'Module is present'.
you use the wrong verison of RevPi Core in your pictory configuration. Please use V1.2. You can just drag V1.2 from the list on the left and drop it on the Core in the main window.
When you call piTest -d only 2 devices should be displayed. Both with status 'Module is present'.
Hi,
thanks for the hint. I have the following response:
pi@RevPi5038:~ $ piTest -d
Found 2 devices:
Address: 0 module type: 95 (0x5f) RevPi Core V1.2
Module is present
input offset: 0 length: 6
output offset: 6 length: 5
Address: 32 module type: 96 (0x60) RevPi DIO V1.3
Module is present
input offset: 11 length: 70
output offset: 81 length: 18
Both devices are now well configured, but I still cannot turn ON the output pin for 25ms. The scope behavior is still the same.
From my script after 25ms, the output should be turned OFF but it is not the case, the pin remains always ON for 50ms. I tried changing the output pins but the result is always the same.
thanks for the hint. I have the following response:
pi@RevPi5038:~ $ piTest -d
Found 2 devices:
Address: 0 module type: 95 (0x5f) RevPi Core V1.2
Module is present
input offset: 0 length: 6
output offset: 6 length: 5
Address: 32 module type: 96 (0x60) RevPi DIO V1.3
Module is present
input offset: 11 length: 70
output offset: 81 length: 18
Both devices are now well configured, but I still cannot turn ON the output pin for 25ms. The scope behavior is still the same.
From my script after 25ms, the output should be turned OFF but it is not the case, the pin remains always ON for 50ms. I tried changing the output pins but the result is always the same.
okay, now I understand your problem: You want 25 ms but you get 50 ms, right?
So please do not use the library from Sven to get such a critical timing or do post this problem in his forum (viewforum.php?f=41&sid=33e693c40a4f8e44 ... 8170dc82c ) to aks if his cycle time could be adopted to your needs...
You could instead directly work with piControl the way we have shown in the video tutorial #16. So if your configuration is always the same you could e.g. go to piCtory and get the offset of your output (let's call it "offs" with a value of 81) using the export function. Then use this simple code (I asume you are toggling the bit 4 which has the value 8) and you will get what you want, includinig the predicted jitter of about 4 ms :
So please do not use the library from Sven to get such a critical timing or do post this problem in his forum (viewforum.php?f=41&sid=33e693c40a4f8e44 ... 8170dc82c ) to aks if his cycle time could be adopted to your needs...
You could instead directly work with piControl the way we have shown in the video tutorial #16. So if your configuration is always the same you could e.g. go to piCtory and get the offset of your output (let's call it "offs" with a value of 81) using the export function. Then use this simple code (I asume you are toggling the bit 4 which has the value 8) and you will get what you want, includinig the predicted jitter of about 4 ms :
Code: Select all
import time
f=open("/dev/piControl0","wb+",0)
offs=81
while True:
f.seek(offs)
state=f.read(1)
bits = state[0]
bits |= 0b00001000
f.seek(offs)
f.write(bytearray([bits]))
time.sleep(0.025)
f.seek(offs)
state=f.read(1)
bits = state[0]
bits &= 0b11110111
f.seek(offs)
f.write(bytearray([bits]))
time.sleep(0.375)
Unser RevPi Motto: Don't just claim it - make it!
Hi,
thanks for the helpful information. I'll check the piControl Tutorial and try it again.
Thanks!
Best regards,
Marcelin
thanks for the helpful information. I'll check the piControl Tutorial and try it again.
Thanks!
Best regards,
Marcelin
Hello,
Regarding my previous question I got it to work as I wished, thanks. Now I would like to ask another question regarding the input pins from Pictory.
I'm trying to trigger some commands on Python based on the state of the input pins. In GPIO of normal raspberry pi this is easily done by just identifying a pin as input and by applying a certain voltage to it, the pin can be seen as high or low.
I would like to reproduce a similar scenario with my RevPi DIO.
On the hardware side, I connected at X2 the inputs and outputs both with 24V.
My question is how can I observe a change of a certain input pin value. On default, I guess all the pins level are zero.
Below is a simple script of what I am trying to execute:
import time
import struct
import fcntl
f=open("/dev/piControl0","wb+",0)
offs=81 # Output pin 4 configuration
offs1=11 # Offset of Input pin from configuration
f.seek(offs1)
state=f.read(1) #Read curent input pin state
bits_in=state[0]
if (bits_in == 0b00001000): # if input pin_4 is High
f.seek(offs)
state=f.read(1)
bits = state[0]
bits |= 0b00001000
f.seek(offs)
f.write(bytearray([bits]))
time.sleep(0.975)
f.seek(offs)
state=f.read(1)
bits = state[0]
bits &= 0b11110111
f.seek(offs)
f.write(bytearray([bits]))
time.sleep(0.025)
else:
print('No input at pin4')
And here comes the output pins configurations on Pictory:
//SYS_PROJECT_TS:20180717135357
GLOBALS hardwareConfig
VAR_GLOBAL
RevPiStatus AT %IB1.0: BYTE := 0; //
RevPiIOCycle AT %IB1.1: BYTE := 0; //
RevPiLED AT %QB1.6: BYTE := 0; //
I_1 AT %IX1.11.0: BOOL := 0; //
I_2 AT %IX1.11.1: BOOL := 0; //
I_3 AT %IX1.11.2: BOOL := 0; //
I_4 AT %IX1.11.3: BOOL := 0; //
I_5 AT %IX1.11.4: BOOL := 0; //
I_6 AT %IX1.11.5: BOOL := 0; //
I_7 AT %IX1.11.6: BOOL := 0; //
I_8 AT %IX1.11.7: BOOL := 0; //
I_9 AT %IX1.11.8: BOOL := 0; //
I_10 AT %IX1.11.9: BOOL := 0; //
I_11 AT %IX1.11.10: BOOL := 0; //
I_12 AT %IX1.11.11: BOOL := 0; //
I_13 AT %IX1.11.12: BOOL := 0; //
I_14 AT %IX1.11.13: BOOL := 0; //
I_15 AT %IX1.11.14: BOOL := 0; //
I_16 AT %IX1.11.15: BOOL := 0; //
O_1 AT %QX1.81.0: BOOL := 0; //
O_2 AT %QX1.81.1: BOOL := 0; //
O_3 AT %QX1.81.2: BOOL := 0; //
O_4 AT %QX1.81.3: BOOL := 0; //
O_5 AT %QX1.81.4: BOOL := 0; //
O_6 AT %QX1.81.5: BOOL := 0; //
O_7 AT %QX1.81.6: BOOL := 0; //
O_8 AT %QX1.81.7: BOOL := 0; //
O_9 AT %QX1.81.8: BOOL := 0; //
O_10 AT %QX1.81.9: BOOL := 0; //
O_11 AT %QX1.81.10: BOOL := 0; //
O_12 AT %QX1.81.11: BOOL := 0; //
O_13 AT %QX1.81.12: BOOL := 0; //
O_14 AT %QX1.81.13: BOOL := 0; //
O_15 AT %QX1.81.14: BOOL := 0; //
O_16 AT %QX1.81.15: BOOL := 0; //
END_VAR
END_GLOBALS
Thanks!
Best regards!
Regarding my previous question I got it to work as I wished, thanks. Now I would like to ask another question regarding the input pins from Pictory.
I'm trying to trigger some commands on Python based on the state of the input pins. In GPIO of normal raspberry pi this is easily done by just identifying a pin as input and by applying a certain voltage to it, the pin can be seen as high or low.
I would like to reproduce a similar scenario with my RevPi DIO.
On the hardware side, I connected at X2 the inputs and outputs both with 24V.
My question is how can I observe a change of a certain input pin value. On default, I guess all the pins level are zero.
Below is a simple script of what I am trying to execute:
import time
import struct
import fcntl
f=open("/dev/piControl0","wb+",0)
offs=81 # Output pin 4 configuration
offs1=11 # Offset of Input pin from configuration
f.seek(offs1)
state=f.read(1) #Read curent input pin state
bits_in=state[0]
if (bits_in == 0b00001000): # if input pin_4 is High
f.seek(offs)
state=f.read(1)
bits = state[0]
bits |= 0b00001000
f.seek(offs)
f.write(bytearray([bits]))
time.sleep(0.975)
f.seek(offs)
state=f.read(1)
bits = state[0]
bits &= 0b11110111
f.seek(offs)
f.write(bytearray([bits]))
time.sleep(0.025)
else:
print('No input at pin4')
And here comes the output pins configurations on Pictory:
//SYS_PROJECT_TS:20180717135357
GLOBALS hardwareConfig
VAR_GLOBAL
RevPiStatus AT %IB1.0: BYTE := 0; //
RevPiIOCycle AT %IB1.1: BYTE := 0; //
RevPiLED AT %QB1.6: BYTE := 0; //
I_1 AT %IX1.11.0: BOOL := 0; //
I_2 AT %IX1.11.1: BOOL := 0; //
I_3 AT %IX1.11.2: BOOL := 0; //
I_4 AT %IX1.11.3: BOOL := 0; //
I_5 AT %IX1.11.4: BOOL := 0; //
I_6 AT %IX1.11.5: BOOL := 0; //
I_7 AT %IX1.11.6: BOOL := 0; //
I_8 AT %IX1.11.7: BOOL := 0; //
I_9 AT %IX1.11.8: BOOL := 0; //
I_10 AT %IX1.11.9: BOOL := 0; //
I_11 AT %IX1.11.10: BOOL := 0; //
I_12 AT %IX1.11.11: BOOL := 0; //
I_13 AT %IX1.11.12: BOOL := 0; //
I_14 AT %IX1.11.13: BOOL := 0; //
I_15 AT %IX1.11.14: BOOL := 0; //
I_16 AT %IX1.11.15: BOOL := 0; //
O_1 AT %QX1.81.0: BOOL := 0; //
O_2 AT %QX1.81.1: BOOL := 0; //
O_3 AT %QX1.81.2: BOOL := 0; //
O_4 AT %QX1.81.3: BOOL := 0; //
O_5 AT %QX1.81.4: BOOL := 0; //
O_6 AT %QX1.81.5: BOOL := 0; //
O_7 AT %QX1.81.6: BOOL := 0; //
O_8 AT %QX1.81.7: BOOL := 0; //
O_9 AT %QX1.81.8: BOOL := 0; //
O_10 AT %QX1.81.9: BOOL := 0; //
O_11 AT %QX1.81.10: BOOL := 0; //
O_12 AT %QX1.81.11: BOOL := 0; //
O_13 AT %QX1.81.12: BOOL := 0; //
O_14 AT %QX1.81.13: BOOL := 0; //
O_15 AT %QX1.81.14: BOOL := 0; //
O_16 AT %QX1.81.15: BOOL := 0; //
END_VAR
END_GLOBALS
Thanks!
Best regards!
looks fine, what is the problem?
The inputs are high whenever you aply a voltage greater then about 9 to 10 V. If you leave them open they are low by definition. The input voltage must be referenced to the 0 V pin for IN at X2.
The inputs are high whenever you aply a voltage greater then about 9 to 10 V. If you leave them open they are low by definition. The input voltage must be referenced to the 0 V pin for IN at X2.
Unser RevPi Motto: Don't just claim it - make it!
From the python, when input pin_4 is connected to power supply I expect the output pin_4 to be triggered and generate pulses, but it does not work so, the code runs down to the 'else condition'
Here is here the picture my hardware connection and the power supply to input pin_4.
Is there any presetting to be done for the input on Pictory to get the input reading?
Thanks!
https://drive.google.com/drive/folders/ ... g?ogsrc=32
Here is here the picture my hardware connection and the power supply to input pin_4.
Is there any presetting to be done for the input on Pictory to get the input reading?
Thanks!
https://drive.google.com/drive/folders/ ... g?ogsrc=32