arduino-libraries / Arduino_MachineControl

GNU Lesser General Public License v2.1
38 stars 29 forks source link

IOExpander: digital_inputs.readAll() Out of sequence? #113

Closed mbatesole closed 10 months ago

mbatesole commented 11 months ago

When trying to read the digital inputs all at once on the Portenta Machine Control, the resulting bit order seems to be out of sequence in the output variable. I may have traced it down to this enum in ArduinoIOExpander.h:

https://github.com/arduino-libraries/Arduino_MachineControl/blob/ca7ff9b35c6837733d398649fd4db86f10d5b252/src/utility/ioexpander/ArduinoIOExpander.h#L74-L83

I would expect that the physical pins on the board would match the bit sequence in the output of readAll(). However the sequence on the board from LSB to MSB is:

DIN_READ_CH_PIN_05, DIN_READ_CH_PIN_04, DIN_READ_CH_PIN_03, DIN_READ_CH_PIN_02, DIN_READ_CH_PIN_01, DIN_READ_CH_PIN_07, DIN_READ_CH_PIN_06, DIN_READ_CH_PIN_00

This seems to match the pattern in the enum above.

Is it possible to return the readAll() in a sequence that matches the board layout?

Use case: I'm trying to input an 8-bit pattern to the DIs which I can translate to an integer and then use an index to an array. I'm a novice at all of this, so apologies if I'm just missing something simple.

leonardocavagnis commented 10 months ago

Hi @mbatesole, The pin pattern matches the DIN pins order of the TCA6424A component.

Screenshot 2023-12-22 alle 14 58 36

Page 18 of PMC schematics.

I suggest to see this example to understand how to manage the mapping.