M5Dial's External Port A I2C Capability or Lack Thereof
-
maybe use UART functionality to communicate with another controller/computer
-
-
@robski Not a bad idea but UART is located on pins G43 and G44 which are not broken out (Port B is G1 and G2). I might be able to use the USB C port but that's just a hassle and a half as far as prototyping, debugging, and expansion is concerned.
-
@felmue Yes, I did hit an issue. I looked at your code but it seems to be looking at what's on the bus but the bus is not experiencing any real data traffic because the peripherals are not being used. I'm not really sure that it can be used as a true test of both internal and external bus capabilities.
Below is some code I modified using M5stack's RFID example and added I2C communication.// Libraries to include #include "M5Dial.h" // Set up and initialize constants and variables const byte MY_ADDRESS = 0x12; const byte SLAVE_ADDRESS = 0x13; String uid = ""; String oldUid = ""; void setup() { // Initialize dial rfid and screen auto cfg = M5.config(); M5Dial.begin(cfg, false, true); M5Dial.Display.setTextColor(GREEN); M5Dial.Display.setTextDatum(middle_center); M5Dial.Display.setTextFont(&fonts::Orbitron_Light_32); M5Dial.Display.setTextSize(1); M5Dial.Display.drawString("RFID Card", M5Dial.Display.width() / 2, M5Dial.Display.height() / 2); // Set up I2C address and recieve transmission event handling Wire.begin (MY_ADDRESS); Wire.onReceive (receiveEvent); } void loop() { // Find out if a card is available for reading if(M5Dial.Rfid.PICC_IsNewCardPresent() && M5Dial.Rfid.PICC_ReadCardSerial()) { uint8_t piccType = M5Dial.Rfid.PICC_GetType(M5Dial.Rfid.uid.sak); // Check to see if PICC is Classic MIFARE type if(piccType != MFRC522::PICC_TYPE_MIFARE_MINI && piccType != MFRC522::PICC_TYPE_MIFARE_1K && piccType != MFRC522::PICC_TYPE_MIFARE_4K) { M5Dial.Display.clear(); M5Dial.Display.drawString("no support", M5Dial.Display.width() / 2, M5Dial.Display.height() / 2); return; // bad card - loop done } // else get UID data uid = ""; for(byte i = 0; i < M5Dial.Rfid.uid.size; i++) { uid += String(M5Dial.Rfid.uid.uidByte[i], HEX); } // And output stored UID data to the screen if its a different card from the card scanned previously. if(uid != oldUid) { M5Dial.Display.clear(); M5Dial.Speaker.tone(8000, 20); M5Dial.Display.drawString(M5Dial.Rfid.PICC_GetTypeName(piccType), M5Dial.Display.width() / 2, M5Dial.Display.height() / 2 - 30); M5Dial.Display.drawString("card id:", M5Dial.Display.width() / 2, M5Dial.Display.height() / 2); M5Dial.Display.drawString(uid, M5Dial.Display.width() / 2, M5Dial.Display.height() / 2 + 30); oldUid = uid; // Also send uid data to microcontroller Wire.beginTransmission(SLAVE_ADDRESS); Wire.write(uid.c_str()); Wire.endTransmission(); } } } // recieve and display UID data from another M5Dial void receiveEvent(int tSize) { uid = ""; for(int i = 0; i < tSize; i++) { uid += Wire.read(); } M5Dial.Display.clear(); M5Dial.Speaker.tone(8000, 20); M5Dial.Display.drawString("card id:", M5Dial.Display.width() / 2, M5Dial.Display.height() / 2); M5Dial.Display.drawString(uid, M5Dial.Display.width() / 2, M5Dial.Display.height() / 2 + 30); oldUid = uid; }
The code above can be copied over to another M5Dial and the addressing is just swapped. Theoretically it should work but when one dial receives RFID card data the other does not display this information. I think that it is transmitting this information but on the interior bus not the external bus. To fix this I added a line to my setup code to include the external I2C bus shown below:
Wire.begin (13, 15);
However that seemed to kill RFID functionality. And this is where I currently sit, hence the questions and comments above hoping for some help.
-
-
@felmue said in M5Dial's External Port A I2C Capability or Lack Thereof:
here
Your assumption is correct. From my understanding of I2C, it seems like an I2C bus should be able to support multiple masters on the same bus. And it should be possible to have a master receive information as long as it is not busy sending information.
With that said, it was busy with the RFID peripheral so maybe that's the problem or I could be entirely mistaken all together on how I2C works. You've given me some documents to digest as well. So I'll get back to you with a new configuration hopefully soon. Thanks!
-
@abraxas Have you considered ESP_NOW?
I no longer use cables, except for three inchers from the sensor!
Dial, Stamps, Cores, AtomS3!
It is amazing. -
@teastain said in M5Dial's External Port A I2C Capability or Lack Thereof:
ESP_NOW
No, mostly because I did not know this protocol existed. This looks like it could be a promising avenue. Thanks for the suggestion Teastain!
-
@abraxas I keep a sample on my GitHub, here:
https://github.com/teastainGit/ESP_NOWpeer2peer
There is ONE sketch for TWO devices, you have to enter the MAC address of one, into the sketch of the other, and vice-versa.
You will need to add the Dial library as required.
If you have problems contact me at teastain@me.com -
@abraxas said in M5Dial's External Port A I2C Capability or Lack Thereof:
@robski Not a bad idea but UART is located on pins G43 and G44 which are not broken out (Port B is G1 and G2). I might be able to use the USB C port but that's just a hassle and a half as far as prototyping, debugging, and expansion is concerned.
in theory you can reconfigure any port to work as uart
-
@teastain Thanks Teastain! I was looking into some esp-now examples but it was a bit of a struggle trying to figure out what is supposed to work. (A lot of examples and a lot of wrong ways to implement esp-now). Your code gave me the jump I needed. I was able to adapt your code to read Rfid tags and get cross talk happening! Thanks again!
-
@abraxas My Pleasure!
-Terry