I have a project going on and have been fighting the GPIO for 2 days now. I am using the Opto22 P1-40-P carrier board with the G4PB8H IO rack.https://documents.opto22.com/2199_Raspberry_Pi_Carrier_Board_Data_Sheet.pdfhttp://documents.opto22.com/0274_G4_Dig_I_O_Racks_Header_data_sheet.pdf
NOTE: Opto22 G4 Logic is "reverse" IE 0=TRUE, 1=FALSE as seen at the GPIO
It is populated as follows:
Pos 0 GPIO pin 40 GPIO 21 DC Output
Pos 1 GPIO pin 37 GPIO 26 DC Output
Pos 2 GPIO pin 38 GPIO 20 DC Output
Pos 3 GPIO pin 35 GPIO 19 DC Input
Pos 4 GPIO pin 36 GPIO 16 DC Input
Pos 5 GPIO pin 33 GPIO 13 DC Input
Pos 6 GPIO pin 31 GPIO 6 DC Input
Pos 7 GPIO pin 32 GPIO 12 DC Input
In my GPIO settings in Codesys (126.96.36.199 Runtime) I have my IO configured (GPIO Parameters) as follows:
GPIO 21 Output (NOTE: on all of these I cannot declare a "default value")
GPIO 26 Output
GPIO 20 Output
GPIO 19 Input
GPIO 16 Input
GPIO 13 Input
GPIO 6 Input
GPIO 12 Input
GPIO OTHER "Input" to prevent them from being in an unknown state
Lastly these are all mapped as follows:
Output0 Bit 21 %QX2.5
Output1 Bit 26 %QX3.2
Output2 Bit 20 %QX2.4
Input3 Bit 19 %IX2.3
Input4 Bit 16 %IX2.0
Input5 Bit 13 %IX1.5
Input6 Bit 6 %IX0.6
Input7 Bit 12 %IX1.4
Note that my inputs all "work as advertised" (TRUE if 0, FALSE if 1)
One last detail is that in my main scan (Task Cyclic 20mS), I have a call to "initialize the Outputs to off (Logic TRUE).
This is done by declaring a variable "ScanOne : BOOL := TRUE;" Scan 1 when TRUE calls a function ("FirstScan() ) where "Output0-2" are all set TRUE. "FirstScan()" then returns FALSE which is used to set the "ScanOne" bit FALSE. Note that FirstScan() is the first call of the main program.
Now for the main issue. If I do a power down, the outputs come back up "on" regardless of what the state is showing online in the GPIO. If I go back in and change my "FirstScan()" to FALSE, Run it by triggering "ScanOne", then change FirstScan() to toggle TRUE my Outputs behave as the should the rest of the time. If I "Reboot" (as opposed to power down) they remain in the correct state and operation.
Note that I do not beleive this to necessarily be a function of Debian. I have "disabled the (Codesys) application" and powered down and back up and the outputs remain off. Only when I have the Codesys application loaded and running does this issue come up. Its like the FirstScan() function is having no effect on the GPIO the first time around.
Does ANYBODY have any idea what this could be? I DESPERATELY need to find a solution as the OPTO22 IO is the most robust I can find that will work on 12 volt DC. Thing is I CANNOT have an output come up in a "cooked state" like this.