I'm having a look into the file raspberrypi.cpp in the OpenPLC_v3 repository because I want to use both I2c as well as the PLC facilities.
Since OpenPLC also uses the I2c SDA and SCL line, they have to be excluded in the call to initializeHardware() so that they're not taken into account as PLC input bits. The check is done in the first for loop through the function pinNotPresent() which is taking 3 parameters as input. The first parameter is an array of integers, called ignored_bool_inputs, the second one is the size of the array and the third one is the pin number.
Therefor, the array ignored_bool_inputs[] located in custom_layer.h should be changed to { 8, 9} instead of the default { -1}. Those two numbers are the wiringPi numbers for GPIO 2 and GPIO 3 (or physical header pins 3 and 5. Correct me if I'm wrong.
However, when looking to the implementation of pinNotPresent() then the incoming array is iterated using a for loop. But inside the for loop there's a check to see if the incoming pin number is part of the given integer array, being ignored_bool_inputs in this case. And I think there's an issue here, since the caller in the method initializeHardware() uses simply the value of the counter as pin number, while - to me - that should be the pin number of the array inBufferPinMask located in raspberrypi.cpp.
So, instead of this:
//set pins as input
for (int i = 0; i < MAX_INPUT; i++)
{
if (pinNotPresent(ignored_bool_inputs, ARRAY_SIZE(ignored_bool_inputs), i))
{
pinMode(inBufferPinMask[i], INPUT);
if (i != 0 && i != 1) //pull down can't be enabled on the first two pins
{
pullUpDnControl(inBufferPinMask[i], PUD_DOWN); //pull down enabled
}
}
}
I think it should be
//set pins as input
for (int i = 0; i < MAX_INPUT; i++)
{
if (pinNotPresent(ignored_bool_inputs, ARRAY_SIZE(ignored_bool_inputs), inBufferPinMask[i]))
{
pinMode(inBufferPinMask[i], INPUT);
if (i != 0 && i != 1) //pull down can't be enabled on the first two pins
{
pullUpDnControl(inBufferPinMask[i], PUD_DOWN); //pull down enabled
}
}
}
That is, the 3rd parameter of the call to pinNotPresent() should be inBufferPinMask[i] instead of just i.
Is this correct?