mendesgeo
Hello, I'm trying to implement a shifter register function in your arduino OpenPlc firmware, and appeared some doubts along the way:
  1. I just need to put more pins constants in the input/output structure vectors to control more pins (if available) of the arduino side code? The function sizeof that is used allow this behavior?.
  2. I Don't undertand the input and output structures, they are the same size even for Arduino Mega (char digital[2] and int analog[16] for the input structure for instance).
  3. There is max outputs limitation in the arduino host side alghoritm? (for instance, only 32bytes of outputs allowed). If there is, could i change some parameter in the host side code (hardware layer) to extend the limit?
Quote 0 0
thiagoralves
mendesgeo wrote:
I just need to put more pins constants in the input/output structure vectors to control more pins (if available) of the arduino side code? The function sizeof that is used allow this behavior?

If you put more pin numbers on the array, they will be read and written using the Arduino functions digitalRead and digitalWrite. If you are using I/O expanders (like a shift register), it won't work because the traditional Arduino functions can't reach the extra pins just by calling digitalRead or digitalWrite. You will have to change the updateInputs() and updateOutputs() function in order to properly read and write to your extra pins. The function sizeof automatically calculates the size of the OPLC_input and OPLC_output structures. If you need extra pins on an Arduino Mega, you will have to increase the size of these structures. One byte you increase on the digital will give you 8 extra I/O (because 1 byte = 8 bits).

mendesgeo wrote:
I Don't undertand the input and output structures, they are the same size even for Arduino Mega (char digital[2] and int analog[16] for the input structure for instance).

The size of the structure must match on the sender and on the receiver, or the memory map will go wrong. Since I didn't want to create two different drivers on the OpenPLC host side just because the Arduino UNO has less pins, I created a common structure that works for both. The Arduino UNO firmware just ignores the extra information it receives. The structure matches the size of inputs and outputs for the MEGA. That's why I said that if you want to add more pins on the MEGA you will need to increase the size of the structure on both sides (host and client). If you want to increase pins only on the UNO you will be able to use the extra space on the structure.

mendesgeo wrote:
There is max outputs limitation in the arduino host side alghoritm? (for instance, only 32bytes of outputs allowed). If there is, could i change some parameter in the host side code (hardware layer) to extend the limit?

As I said, the structure size must match on both sides. There is no limit for how big it can be, as long as you increase equally on both sides. However, increasing this structure too much will slow down the communication and can put the board out of sync with the host.
Quote 1 0