I have the following Setup:
ESP32 WROOM 32 1x connected with Pin 21 as SDA and Pin 22 SCL to PCA9548A I2C Multiplexer, that is connected with SDA 0 and SCL 0 to scanner 1, SDA 1 and SCL 1 to scanner 2 and SDA 2 and SCL 2 to scanner 3.
The NFC scanners are PN532.
The Code for it is that I made is:
#include <Wire.h>
#include <Adafruit_PN532.h>
#define TCAADDR 0x70 // TCA9548A I2C Multiplexer
#define PN532_I2C_ADDRESS 0x24 // Standard PN532 Adresse
Adafruit_PN532 scanner1(&Wire);
Adafruit_PN532 scanner2(&Wire);
Adafruit_PN532 scanner3(&Wire);
// Multiplexer Kanalwahl
void tcaSelect(uint8_t channel) {
if (channel > 7) return;
Wire.beginTransmission(TCAADDR);
Wire.write(1 << channel); // Den Kanal aktivieren
Wire.endTransmission();
delay(10);
}
void setup() {
Serial.begin(115200);
Wire.begin(21, 22);
// Scanner initialisieren
tcaSelect(0);
if (!scanner1.begin()) {
Serial.println("Fehler: Scanner 1 konnte nicht initialisiert werden!");
} else {
Serial.println("Scanner 1 erfolgreich initialisiert.");
}
tcaSelect(1);
if (!scanner2.begin()) {
Serial.println("Fehler: Scanner 2 konnte nicht initialisiert werden!");
} else {
Serial.println("Scanner 2 erfolgreich initialisiert.");
}
tcaSelect(2);
if (!scanner3.begin()) {
Serial.println("Fehler: Scanner 3 konnte nicht initialisiert werden!");
} else {
Serial.println("Scanner 3 erfolgreich initialisiert.");
}
Serial.println("Setup abgeschlossen");
}
void readScanner(Adafruit_PN532 &scanner, uint8_t channel) {
tcaSelect(channel);
uint8_t success;
uint8_t uid[] = {0, 0, 0, 0, 0, 0, 0};
uint8_t uidLength;
success = scanner.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
if (success) {
Serial.println("Karte gefunden!");
Serial.print("UID Länge: "); Serial.print(uidLength, DEC); Serial.println(" bytes");
Serial.print("UID Wert: ");
for (uint8_t i = 0; i < uidLength; i++) {
Serial.print(" 0x"); Serial.print(uid[i], HEX);
}
Serial.println("");
delay(1000);
}
}
void loop() {
readScanner(scanner1, 0);
readScanner(scanner2, 1);
readScanner(scanner3, 2);
delay(1000);
}
The error Code is:
invalid conversion from "TwoWire*" to "uint8_t" {aka "unsigned char"} [-fpermissive]
I tried letting the scanner initialising like the following:
(Wire) (&Wire) (TwoWire) (&TwoWire) (21, 22)
nothing worked.
As much as I know, the problem is, that I try to initialize the scanners alone, but they all use the same I2C Address Bus. What I want to try, is to set the Modules over the Multiplexer as separate I2C addresses, I just don't know why.