There is an IO expander PCA9534PW, Arduino UNO. I don’t really understand how I can manage this expander using UNO over I2C.
I found an example, but here is the reading mode.
What I need: Set the IO0 pin to exit mode, set the HIGH / LOW level to IO0.
In the datasheet, I just realized that to enter the settings mode - you need to write Wire.write(0x03). How can I do it?
-
1Hint: There is more or less always someone that has done this before you, and shared it. Please see, for instance, github.com/alotaiba/PCA9534.Mikael Patel– Mikael Patel2019年03月11日 10:15:24 +00:00Commented Mar 11, 2019 at 10:15
-
1Answer: Write to the configuration register to set the pin mode. See github.com/alotaiba/PCA9534/blob/master/src/PCA9534.cpp#L14.Mikael Patel– Mikael Patel2019年03月11日 10:17:27 +00:00Commented Mar 11, 2019 at 10:17
1 Answer 1
You set the pin mode by setting the configuration register.
Wire.beginTransmission(0x20);
Wire.write(0x03); // Configuration Register
Wire.write(0xfe); // IO7-IO1 Input, IO0 Output
Wire.endTransmission();
Then write the output port register with HIGH and LOW.
Wire.beginTransmission(0x20);
Wire.write(0x01); // Output Port Register
Wire.write(0x01); // IO0 HIGH
Wire.endTransmission();
delay(500);
Wire.beginTransmission(0x20);
Wire.write(0x01); // Output Port Register
Wire.write(0x00); // IO0 LOW
Wire.endTransmission();
But using a library is much easier. See, for instance, https://github.com/alotaiba/PCA9534.
-
Many thanks for the example! I have seen this library, but it does not compile under Arduino. github.com/alotaiba/PCA9534/issues/1Delta– Delta2019年03月13日 08:25:52 +00:00Commented Mar 13, 2019 at 8:25
-
It should be very easy to port from Particle. Have you tried to comment out this line, github.com/alotaiba/PCA9534/blob/master/src/PCA9534.h#L14, or just create an empty file with the name "Particle.h".Mikael Patel– Mikael Patel2019年03月13日 09:53:30 +00:00Commented Mar 13, 2019 at 9:53