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

    PbHub 1.1 on STAMPLC - Couldn't find Pbhub on PortA

    PRODUCTS
    3
    5
    71
    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.
    • B
      bensonwhlee
      last edited by

      I am using STAMPLC and have all function included the PWR485 are normal. However, I purchase a PbHub to use as a extended input for buttons. I cannot connect the PbHub on PortA or PortC on STAMPLC.
      I follow the sample code as follow in setup:
      #include "M5UnitPbHub.h"
      M5UnitPbHub pbhub;
      void setup() {
      Serial.begin(115200);
      if (!pbhub.begin(&Wire, UNIT_PBHUB_I2C_ADDR, 2, 1, 400000U)) {
      Serial.println("Couldn't find Pbhub");
      while (1) delay(1);
      }
      }

      void loop() {
      Serial.printf("ch:%d adc:%d\r\n", 0 , pbhub.analogRead(0));
      delay(1);
      }

      The following is the response on Serial Monitor:
      Couldn't find Pbhub

      E (1982) i2c.master: I2C transaction unexpected nack detected
      E (1983) i2c.master: s_i2c_synchronous_transaction(924): I2C transaction failed
      E (1984) i2c.master: i2c_master_multi_buffer_transmit(1186): I2C transaction failed

      Wirings and functions are correct, G1 and G2 can get analogue and digital data I/O as normal. Any hints to solve the problem. I have write a simple I2C scanner program on Port A G2, G1 pin, there was response from Address 0x61, but Pbhub library cannot read data from Pbhub

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

        Hello @bensonwhlee

        I think you need to use the M5StamPLC library together with M5Unified and M5GFX libraries for it to work properly.

        Please find an example here which works for me.

        Edit: if you don't need M5StamPLC specific functions then it should be sufficient to add the following line to your setup code:

        Wire.begin(2, 1, 400000U);
        

        Thanks
        Felix

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

        B 1 Reply Last reply Reply Quote 0
        • B
          bensonwhlee @felmue
          last edited by

          @felmue
          Thank you Felmue,
          By testing the Wire interface and M5UnitPbHub seperately, I finally got response from the PbHub. I'm not sure what cause the problem. When I used your sample with the minimal code, the PbHub responsed and got analog data back after serval reset or unplug/replug the PortA cable. But it is not consistency working after each program download.
          In my more complicated program with SD, PWR485 , M5StamPLC.Display , the PbHub did not work at all. But if I just put in I2C scanning code together with my program, there is response from PbHub that address 0x61 was found.
          I think the problem is the command:
          pbhub.begin(&Wire, UNIT_PBHUB_I2C_ADDR, 2, 1, 400000U) and
          Serial.printf("0:%d 1: %d 2:%d 3:%d 4:%d 5:%d \n",pbhub.analogRead(0), pbhub.analogRead(1), pbhub.analogRead(2), pbhub.analogRead(3), pbhub.analogRead(4),pbhub.analogRead(5));

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

            Hello @bensonwhlee

            try adding a delay(500) before calling pbhub.begin(). My above linked code fails to initialize PbHub without a delay.

            Thanks
            Felix

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

            S 1 Reply Last reply Reply Quote 0
            • S
              Slarck @felmue
              last edited by

              @felmue said in PbHub 1.1 on STAMPLC - Couldn't find Pbhub on PortA:

              Hello @bensonwhlee

              try adding a delay(500) before calling pbhub.begin(). My above linked code fails to initialize PbHub without a delay.

              Thanks
              Felix

              “Thanks @felmue, that’s a helpful tip about the delay. I’ve seen similar I2C issues where peripherals don’t initialize properly without a short wait after boot. Good to know it applies to the PbHub too!”

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