Register / Login  |  Desktop view  |  Jump to bottom of page

IoAbstraction & TaskManagerIO » Pin numbering in IOabstraction

Author: pryanic
28/03/2022 08:35:27
Hello, everyone!
I can't understand pin numbering using ioabstraction lib.
For example:
#include <IoAbstraction.h>
#include <IoAbstractionWire.h>

IoAbstractionRef ioExpander1;
IoAbstractionRef ioExpander2;

void setup() {
  ioExpander1 = ioFrom8574(0x27);
  ioExpander2 = ioFrom8574(0x28);
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:
}

I set io to input using pinDirection(). If I want to read value from pin there is no problem. I can use ioDeviceDigitalRead with unit ref and pin number. I want to addSwitch() function witch only have "pin" parameter. And now I can't understand...? For example I want to addswitch to pin 3 ioExpander1 and to pin 5 ioExpander2. What pin numbers I should print in addSwitch() function?



Author: davetcc
28/03/2022 09:26:30
For switches, you provide the IoAbstraction that it is going to use in the initialise call.

I would suggest that you use a MultiIoAbstraction that lets you group together many IO devices into a single abstraction (I think it allows up to 8 separate ones by default). See

https://www.thecoderscorner.com/ref-docs/ioabstraction/html/class_multi_io_abstraction.html

and

https://www.thecoderscorner.com/products/arduino-libraries/io-abstraction/arduino-pins-and-io-expanders-same-time/

Then you would pass that abstraction to the switches initialise call instead of whatever you're passing now.

Author: pryanic
28/03/2022 14:17:36
I'm stupid. With ioDeviceSync all OK
Yes, thanks. I think similar. But one more issue whitch I could understang.
I have very "stuped" code just for some trainig:

#include <IoAbstraction.h>
#include <IoAbstractionWire.h>
#include<TaskManagerIO.h>
#include <Wire.h>

MultiIoAbstractionRef multiIo = multiIoExpander(100);
void setup() {
Wire.begin();
Serial.begin(115200);
Serial.println("Multi IoExpander example");
multiIoAddExpander(multiIo, ioFrom8574(0x20), 10);
Serial.println("added an expander at pin 100 to 109");
// multiIoAddExpander(multiIo, ioFrom8574(0x21), 10);
//Serial.println("added an expander at pin 110 to 119");
//ioDevicePinMode(multiIo, 100, INPUT);
ioDevicePinMode(multiIo, 100, OUTPUT);
ioDevicePinMode(multiIo, 101, OUTPUT);
ioDevicePinMode(multiIo, 102, OUTPUT);
ioDevicePinMode(multiIo, 103, OUTPUT);
ioDevicePinMode(multiIo, 104, OUTPUT);
ioDevicePinMode(multiIo, 105, OUTPUT);
ioDevicePinMode(multiIo, 106, OUTPUT);
ioDevicePinMode(multiIo, 107, OUTPUT);
ioDevicePinMode(multiIo, LED_BUILTIN, OUTPUT);

ioDeviceDigitalWrite(multiIo, 100, LOW);
ioDeviceDigitalWrite(multiIo, 101, LOW);
ioDeviceDigitalWrite(multiIo, 102, HIGH);
ioDeviceDigitalWrite(multiIo, 103, HIGH);
ioDeviceDigitalWrite(multiIo, 104, HIGH);
ioDeviceDigitalWrite(multiIo, 105, HIGH);
ioDeviceDigitalWrite(multiIo, 106, HIGH);
ioDeviceDigitalWrite(multiIo, 107, HIGH);
ioDeviceDigitalWrite(multiIo, LED_BUILTIN, HIGH);
}

void loop() {
taskManager.runLoop();
}


But nothing happens on PCF outputs, builtin led is OK. I tryed this too but no result: https://www.thecoderscorner.com/products/arduino-libraries/io-abstraction/i2c8574-example-ioabstraction-library/
expander outputs always High. I2C scanner show right adress of 8574 boad.




Register / Login  |  Desktop view  |  Jump to top of page