sho
I first found openPLC project some weeks ago, I tested it on Raspberry PI 4 (4gb) and 2 Arduino Mega, it was super easy to setup and get to run, including Modbus interface to my openHAB system, it looks to be working for my project of replacing a very old Siemens Step5 PLC, I then order a Unipi 1.1 to use as my base.
To my big surprise it did not work as expected, I could not get all the input to work, I then started from scratch without connecting Raspberry to Unipi
- Using most recent Raspbian from Raspberry PI website
- Run Update / Upgrade
- Upgrade GPIO version to 2.52
- Enable I2C in Raspberry setup
- Tested that GPIO was working, I could see status change in gpio readall
Connected Raspberry with Unipi, same result, looks like Raspberry and openPLC can only see 3 of 14 input.
Same result if using gpio readall or the Monitoring

None or the 14 input was activated for the screenshot, still it show that 9 of them was True
Only %IX0.1, %IX1.0 and %IX1.1 change status when activated
The LED on Unipi light up on all when activated, using internal power supply
Raspberry and Unipi has separated power supply

What is it that I'm missing?
Is it a setup or hardware issue?
openPLC.png
Reply 0 0
thiagoralves
Which driver are you using on OpenPLC hardware tab?
Reply 0 0
sho
I was using Raspberry PI for first test, after new start from scratch and attach to UniPi I'm using UniPi v1.1 driver on the hardware tab
Reply 0 0
thiagoralves
When you apply the UniPi v1.1 driver does it compile successfully? Are there any error messages? I don't have a UniPi board anymore to test, but it was running just fine on a Pi 3 + UniPi last time I checked.
Reply 0 0
sho
Yes, program compile without error message, I did some more testing, this time I removed the connection to UniPi and use the input direct on Raspberry, this seems to be working, I now more think it is hardware issue, I have written to UniPi support to hear what they think can be the issue 
Reply 0 0
sho
Hi Thiago
I got feedback from my support request to UniPi
*******************************************************''
Hi Steen,

the digital input relies on the SW pull up resistor, which you need to set during the initialization of the GPIO.

Our API called Evok does this automatically. Maybe it would be a better fit for the OpenPLC since it unifies the access to the IOs to a single REST/WebSocket API: https://github.com/UniPiTechnology/evok
**********************************************************'

Is the Evok needed to run openPLC ?

Reply 0 0
thiagoralves
OpenPLC UniPi driver is completely independent from Evok. In fact, if you have Evok installed it will interfere with OpenPLC and neither will work correctly. I wrote the UniPi driver in 2016, and at that time it was working perfectly. I don't know if they had updated the board revision since.

As for the SW pull up, OpenPLC driver is doing that:
for (int i = 0; i < MAX_INPUT; i++)
{
  if (pinNotPresent(ignored_bool_inputs, ARRAY_SIZE(ignored_bool_inputs), i))
  {
    pinMode(inputPinMask[i], INPUT);
    pullUpDnControl(inputPinMask[i], PUD_UP);
  }
}

As you can see, it activated PUD_UP for all input pins. If you want to run your own tests, the driver is located at OpenPLC_v3/webserver/core/hardware_layers/unipi.cpp
Reply 0 0
thiagoralves
It just occurred to me that perhaps the Raspberry Pi 4 is treating software pull ups differently. Do you have a Pi 3 around to check if the same problem is happening? I'm pretty sure that UniPi boards work with the Pi 3 and OpenPLC. If it doesn't work with yours, there is a big chance that your board is defective.
Reply 0 0
sho
I don't have any Pi 3, I will try to get one in the next days and test
Reply 0 0
sho
I got a Pi 3B from a friend close by, started from scratch and standard GPIO version 2.50
And it is working, all the input except %IX1.5 and %IX1.6 is working, according to documentation on UniPi they are wired to a separate pin header and wired to the 40 pin header on PI
Conclusion Raspberry PI 4B+ can not use the default driver to UniPi, maybe this should be mention
And thank you for your quick response    
Reply 0 0
thiagoralves
As I said, I don't have a UniPi board anymore to test, but after a quick check, there is no reason why it wouldn't work on the Pi 4, unless you have an outdated version of WiringPi. Have you really updated WiringPi to the latest version according to this:  http://wiringpi.com/wiringpi-updated-to-2-52-for-the-raspberry-pi-4b/ ?
Reply 0 0
sho
Yes, the Pi 4 was updated to version 2.52 following the description from the link and verified by gpio -v that confirm version 2.52
I'm fine with using the Pi 3
Reply 0 0
Reply