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

    Troubles with serial connection between Core2 and AtomMatrix

    Scheduled Pinned Locked Moved Core 2
    2 Posts 2 Posters 2.3k Views
    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.
    • H Offline
      HappyUser
      last edited by

      Wow, this should have been simple but apparently I am overseeing something.
      I have a M5Stack Core 2 connected to M5AtomMatrix using the Port A on Core 2 and HY2.0-4P port on the Matrix. Included the code of sender and receiver. But I dont see any transmission going on. Which obvious mistake am I making here?
      M5Stack Core 2 code :

      #include <M5Core2.h>
      #include <Wire.h>
      #define I2C_DEV_ADDR 0x55
      uint32_t i = 0;

      void setup() {

      M5.begin(true, true, true, true);
      delay(300);
      
      Serial.setDebugOutput(true);
      Wire.begin(32,33);  // SDA SCL M5Stack Core 2
      

      }

      void loop() {
      delay(5000);

      //Write message to the slave
      Wire.beginTransmission(I2C_DEV_ADDR);
      Wire.printf("Hello World! %u", i++);
      uint8_t error = Wire.endTransmission(true);
      Serial.printf("endTransmission: %u\n", error);

      //Read 16 bytes from the slave
      error = Wire.requestFrom(I2C_DEV_ADDR, 16);
      Serial.printf("requestFrom: %u\n", error);
      if(error){
      uint8_t temp[error];
      Wire.readBytes(temp, error);
      log_print_buf(temp, error);
      }

      }

      M5Atom Matrix code here:

      //#include "M5Atom.h"
      #include "M5StickC.h"
      #include <Wire.h>
      #define I2C_DEV_ADDR 0x55

      uint32_t i = 0;

      void onRequest(){
      Wire.print(i++);
      Wire.print(" Packets.");
      Serial.println("onRequest");
      }

      void onReceive(int len){
      Serial.printf("onReceive[%d]: ", len);
      while(Wire.available()){
      Serial.write(Wire.read());
      }
      Serial.println();
      }

      void setup() {

      M5.begin(true,true,true);
      delay(300);
      

      Serial.begin(115200);
      Serial.setDebugOutput(true);
      Wire.onReceive(onReceive);
      Wire.onRequest(onRequest);
      Wire.begin(26,32); // SDA SCL M5Atom

      }

      void loop() {

      }

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

        Hello @HappyUser

        you are so close. Right now you are setting up both devices as I2C masters. However M5Atom needs to be an I2C slave. To do this the first parameter of Wire.begin() needs to be the slave address. Try this:

        Wire.begin((uint8_t)I2C_DEV_ADDR, 26, 32);
        

        Thanks
        Felix

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

        1 Reply Last reply Reply Quote 0

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        • First post
          Last post