Hello everybody,
I would like to use the IO Expander PCF8575 to query the state of 16 switches,
only I need all 8 analog inputs from the arduino nano for other readings, which
is why I cannot have an I2C connection on pins A4 and A5. but I don't know
how else to communicate with the PCF8575 ...
(And yes, I've heard of the Libarys BitBang and / or SoftI2CMaster, but just don't
know how I use them with the PCF8575 libary)
can someone help me make an I2C connection to the PCF8575 using digital pins?
//selbsterklärend..
#include "Arduino.h"
#include <Wire.h>
#include "PCF8575.h"
PCF8575 pcf8575(0x20);
bool button[NUMBUTTONS];
void setup()
{
Serial.begin(9600);
for (int i = 0; i < 16; i++) {
pcf8575.pinMode(i, INPUT);
button[i] = false;
}
pcf8575.begin();
}
void loop()
{
readButtons();
}
void readButtons() {
//liest alle buttons aus
for (int i = 0; i < 16; i++) {
bool change = pcf8575.digitalRead(i);
if ( (i < 8 || i == 11) && i != 2 && i != 3) {
change = !change;
}
if (change && !button[i]) {
button[i] = true;
Serial.print(i);
Serial.print(",");
Serial.println("button");
}
else if (!change && button[i]) {
button[i] = false;
}
}
}
lynes:
Hello everybody,
I would like to use the IO Expander PCF8575 to query the state of 16 switches,
only I need all 8 analog inputs from the arduino nano for other readings, which
is why I cannot have an I2C connection on pins A4 and A5. but I don't know
how else to communicate with the PCF8575 ...
since you need 8 analog input, it might be worth you considering using something like a TCA9548A additionally as this would be a simpler solution IMHO.
That way A4 and A5 are freed and used for I2C connection!
sherzaad:
since you need 8 analog input, it might be worth you considering using something like a TCA9548A additionally as this would be a simpler solution IMHO.
That way A4 and A5 are freed and used for I2C connection!
hope that helps....
I have 2 problems with that, i already used adc1115 for an I2C analog reader, but since they have a 16bit resolution, the reading was to slow for me so i though about way to incries the speed, and noticed that i only need 8 nessery potis, so i could just use the ardunio nano directly which now has a latency of 2-5ms with all calc and interpretion from my side, so i think with another i2c reader my improved speed would be slow again...
Also due to covid.19 the shipping takes months, so buying a new thing would unnecessarily drag my project out again.