🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    M5Dial's External Port A I2C Capability or Lack Thereof

    Arduino
    4
    13
    4.5k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      Abraxas
      last edited by

      I was pretty excited to see an external I2C port (G13 - SDA & G15 - SCL) on the M5dial since it seems to act more like a self-contained smart sensor than a microcontroller. I figured this I2C port could potentially allow it to communicate with another micro-controller/computer allowing it to relay quite a bit of information along. However, I'm not really seeing a way to initialize and use this port for this purpose. Am I missing something here? I know the dial has an internal I2C port (G11 - SDA & G12 - SCL) being used to read RFID, touch screen, and RTC functions. Does this interfere with having a second I2C bus open?

      1 Reply Last reply Reply Quote 0
      • robskiR
        robski
        last edited by

        maybe use UART functionality to communicate with another controller/computer

        M5StickC, M5StickCPlus, M5StickCplus2,M5GO, M5Core, M5Tough, M5Core2, M5 Demo Board, M5Dial, M5Paper, M5Atom, M5Cardputer, M5StampS3, CoreMP135, StamPLC, AirQ

        A 1 Reply Last reply Reply Quote 0
        • felmueF
          felmue
          last edited by

          Hello @Abraxas

          why are you saying that? Did you try to use the external port A for I2C and hit an issue?

          Please find an example here which scans the internal and external I2C bus.

          Thanks
          Felix

          GPIO translation table M5Stack / M5Core2
          Information about various M5Stack products.
          Code examples

          A 1 Reply Last reply Reply Quote 0
          • A
            Abraxas @robski
            last edited by

            @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.

            robskiR 1 Reply Last reply Reply Quote 0
            • A
              Abraxas @felmue
              last edited by Abraxas

              @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.

              teastainT 1 Reply Last reply Reply Quote 0
              • felmueF
                felmue
                last edited by

                Hello @Abraxas

                ok, now I understand. Well, one of the M5Dial needs to be an I2C master and the other needs to be an I2C slave. Right now, it seem to me, you're setting both M5Dials up as I2C master.

                Please check documentation here and here.

                Thanks
                Felix

                GPIO translation table M5Stack / M5Core2
                Information about various M5Stack products.
                Code examples

                A 1 Reply Last reply Reply Quote 0
                • A
                  Abraxas @felmue
                  last edited by

                  @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!

                  1 Reply Last reply Reply Quote 0
                  • teastainT
                    teastain @Abraxas
                    last edited by

                    @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.

                    Cheers, Terry!

                    100% M5Stack addict with several drawers full of product!

                    A 1 Reply Last reply Reply Quote 0
                    • A
                      Abraxas @teastain
                      last edited by

                      @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!

                      teastainT 1 Reply Last reply Reply Quote 0
                      • teastainT
                        teastain @Abraxas
                        last edited by

                        @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

                        Cheers, Terry!

                        100% M5Stack addict with several drawers full of product!

                        A 1 Reply Last reply Reply Quote 0
                        • robskiR
                          robski @Abraxas
                          last edited by

                          @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

                          M5StickC, M5StickCPlus, M5StickCplus2,M5GO, M5Core, M5Tough, M5Core2, M5 Demo Board, M5Dial, M5Paper, M5Atom, M5Cardputer, M5StampS3, CoreMP135, StamPLC, AirQ

                          1 Reply Last reply Reply Quote 0
                          • A
                            Abraxas @teastain
                            last edited by

                            @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!

                            teastainT 1 Reply Last reply Reply Quote 1
                            • teastainT
                              teastain @Abraxas
                              last edited by

                              @abraxas My Pleasure!
                              -Terry

                              Cheers, Terry!

                              100% M5Stack addict with several drawers full of product!

                              1 Reply Last reply Reply Quote 0
                              • First post
                                Last post