Closed ITstreet1 closed 2 years ago
Hi @ITstreet1,
I will add a new example showing multiple PCAL9535A with different addresses soon, as this is a good question that the current examples don't currently cover.
I recently made a small change to the parameter the gpio.begin()
function takes to make sure that the wrong values can't be supplied.
The old syntax is what you've described, where the base address is 0x20 and begin()
could be called with an argument of 0
to 7
to set the address based on the devices A2, A1 & A0 pins.
I wanted to change this because any number could be entered in begin, including any invalid addresses, and it wouldn't be clear that this was causing undefined behaviour.
I've changed the begin()
function that it can now be called with a PCAL9535A::HardwareAddress
enum, which looks like the below examples:
gpio.begin(PCAL9535A::HardwareAddress::A000); // same as old code with 0
gpio.begin(PCAL9535A::HardwareAddress::A001); // same as old code with 1 <-- sounds like this is what you want to do
gpio.begin(PCAL9535A::HardwareAddress::A010); // same as old code with 2
gpio.begin(PCAL9535A::HardwareAddress::A011); // same as old code with 3
gpio.begin(PCAL9535A::HardwareAddress::A100); // same as old code with 4
gpio.begin(PCAL9535A::HardwareAddress::A101); // same as old code with 5
gpio.begin(PCAL9535A::HardwareAddress::A110); // same as old code with 6
gpio.begin(PCAL9535A::HardwareAddress::A111); // same as old code with 7
AXXX maps to the pins of the device, as described in the datasheet:
Everything works just fine.
Excellent, glad to hear it! Let me know if you need any other info.
Hi, How to use library with multiple ICs? Say I want to use toggle example on a 0x20, I can use this:
gpio.begin(); // use default address 0
to blink LED. But if I have an IC on a 0x21? How to select an IC on this address? If I remember correctly on earlier versions I could use this:
gpio.begin(0); // use default address 0
Where 0 is the address of the chip. Now it can not compile. Any light here, please.