RFID 2 unit and I2C hub 1 to 6 expansion unit
-
Hello,
The RFID 2 unit works fine when connected directly to M5Core2.
Now, I connect the I2C hub to the M5Core 2 and connect the RFID 2 device to channel 0 of the I2C hub.
I run the following programs. I would assume that the RFID 2 device would show with address 0x28. But it does not, it only gives 0X70 which is the I2C device itself. What am i missing here?#include <M5Core2.h> #include "ClosedCube_TCA9548A.h" #define FRONT 2 #define X_LOCAL 100 #define Y_LOCAL 35 #define X_OFFSET 160 #define Y_OFFSET 34 #define PaHub_I2C_ADDRESS 0x70 ClosedCube::Wired::TCA9548A tca9548a; void setup() { M5.begin(); //M5.Power.begin(); //wire.begin(); tca9548a.address(PaHub_I2C_ADDRESS); // Set the I2C address. 设置I2C地址 M5.Lcd.setTextFont(4); M5.Lcd.setCursor(70, 0, 4); M5.Lcd.setTextColor(YELLOW, TFT_BLACK); M5.Lcd.println(("PaHUB Example")); M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK); } void loop() { uint8_t returnCode = 0; uint8_t address; for (uint8_t channel = 0; channel < TCA9548A_MAX_CHANNELS; channel++) { M5.Lcd.setCursor(X_LOCAL, Y_LOCAL + Y_OFFSET * channel, FRONT); M5.Lcd.printf( " "); M5.Lcd.setCursor(X_LOCAL, Y_LOCAL + Y_OFFSET * channel, FRONT); M5.Lcd.printf("CH%d : ", channel); returnCode = tca9548a.selectChannel(channel); if (returnCode == 0) { for (address = 0x01; address < 0x7F; address++) { Wire.beginTransmission(address); returnCode = Wire.endTransmission(); if (returnCode == 0) { Serial.print("I2C device = "); M5.Lcd.printf("0X%X ", address); } } } delay(200); } }
-
Hello @HappyUser
the code works for me using M5Core2v1.1 and the following modifications:
//#include <M5Core2.h> <-- replace this with below lines #include <M5Unified.h> #include <Wire.h>
M5.begin(); Wire.begin(); <--- add this after above line
Thanks
Felix -
@felmue Sorry for my late response, been a bit occupied. Tried exacltly the include code with the most recent version of M5Unified (0.2.1) and M5Stack board manager (version 2.1.2). Connect the RFID 2 unit to slot 0 of the TCA9548A module (boh M5Stack products.
It only lists for each channel 0x70 wire ping value. I would have expected for channel 0 to have a response on 0x28 (native wire address of the RFID 2 module). Maybe it is because the RFID module has not been inititated yet. But I do not know where to put the init of the RFID module. Tried at different place in the code , to no avail. I hope someone has an idea of where I am going wrong here.```
//#include <M5Core2.h>
#include <M5Unified.h>
#include <Wire.h>#include "ClosedCube_TCA9548A.h"
#define FRONT 2
#define X_LOCAL 100
#define Y_LOCAL 35
#define X_OFFSET 160
#define Y_OFFSET 34#define PaHub_I2C_ADDRESS 0x70
ClosedCube::Wired::TCA9548A tca9548a;
void setup() {
M5.begin();
Wire.begin();
tca9548a.address(PaHub_I2C_ADDRESS); // Set the I2C address. 设置I2C地址
M5.Lcd.setTextFont(4);
M5.Lcd.setCursor(70, 0, 4);
M5.Lcd.setTextColor(YELLOW, TFT_BLACK);
M5.Lcd.println(("PaHUB Example"));
M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK);
}void loop() {
uint8_t returnCode = 0;
uint8_t address;
for (uint8_t channel = 0; channel < TCA9548A_MAX_CHANNELS; channel++) {
M5.Lcd.setCursor(X_LOCAL, Y_LOCAL + Y_OFFSET * channel, FRONT);
M5.Lcd.printf(
" ");
M5.Lcd.setCursor(X_LOCAL, Y_LOCAL + Y_OFFSET * channel, FRONT);
M5.Lcd.printf("CH%d : ", channel);
returnCode = tca9548a.selectChannel(channel);
if (returnCode == 0) {
for (address = 0x01; address < 0x7F; address++) {
Wire.beginTransmission(address);
returnCode = Wire.endTransmission();
if (returnCode == 0) {
Serial.print("I2C device = ");
M5.Lcd.printf("0X%X ", address);
}
}
}
delay(200);
}
} -
Hello @HappyUser
have you tried to connect the RFID2 to another channel than 0? Does it show up then?
Do you have other I2C units which you could connect to any channel just to see if they get picked up?
For a scan an I2C device doesn't need to be initialized.
Thanks
Felix -
SOLVED : After remeniscing abount my life, and specifically what goes wrong here, i just realised : could it be that I am using an outdated library of ClosedCube. And yes, after using the version from 4 April 2023, everything works fine now.
@felmue In Dutch : Krijg nou wat?
I put the RFID 2 module in slot 1 of the TCA 9548A module and then in channel 0 (weird because i have placed it in channel 1) i see address 0x28 of the RFID popping up.Does this mean that channel 0 on the module is not usable?
ThanksIn follow_up , I have checked ClosedCube_TCA9548A.cpp and the selctChannel goes like this :
uint8_t ClosedCube::Wired::TCA9548A::selectChannel(uint8_t channel) { uint8_t result = 0xff; if (channel < TCA9548A_MAX_CHANNELS) { Wire.beginTransmission(_address); Wire.write(((uint8_t)1) << (channel)); _currentChannel = channel; result = Wire.endTransmission(); } return result; }
That seems to be correct if I read the documentation of the Texas Instrument module TCA9548A
I am really misunderstaning something or could it be that their is somekind of wire mixup in the module?
Btw, I also dont see a reset channel somewhere in the code.
Now i did another experiment using PCA9548AP (the newer version).
Plugging in the RFID in channel 0 gives no response.
Plugging in channel 1 : software tels me the device is in channel 0
Plugging in a second RFID in channel 2 :software tells met a I have another device in channel 1.I tried to increase the max number of channels to 8 (assuming that channel 0 is somehow connected to channel 7 of 8). Still no response when i attach a device physically on channel 0.
This is really weird behaviour. I hope someone is at least able to reproduce this behaviour.
-
Hey @HappyUser
I’m experiencing a similar issue with channel 0 on my PCA9548AP while using 6 Weight I2C Units.
When a Weight Unit is connected to channel 0, no response is detected.
However, when connected to any other channel, the device address is shown correctly.Were you able to find a solution for this issue? I haven’t been able to resolve it yet and would appreciate any insights.
Thanks in advance!
-
@laursena please check the version of ClosedCube.cpp and ClosedCube.h you are using. The one that is provided by M5stack is the newest.
(* In the examples of M5StickCPlus in the directory Unit/PaHub you may find these documents. *) -
@HappyUser Thank you very much! It has solved the problem.