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

    StickC Plus + PaHUB + 3 Ultrasonic I2C units

    Units
    5
    34
    25.0k
    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.
    • G
      gavin67890 @robot_alf
      last edited by

      I would assume from a new UIFlow window (started as StickC Plus and connected):
      Add/+ Pa.Hub unit (Port "A")
      Add/+ 1st ultrasonic unit (Port "PAHUB", PAHUB "PAHUB0")
      NB Dropdown will expand for PaHUB tree after Port "PAHUB"
      Add/+ 2nd ultrasonic unit (Port "PAHUB", PAHUB "PAHUB1")
      Add/+ 3rd ultrasonic unit (Port "PAHUB", PAHUB "PAHUB2")
      Then from the blocks selection drag an ultrasonic read distance as per the read device example then use dropdown to select ultrasonic_0, ultrasonic_1, ultrasonic_2, etc.

      Atom LITE | Atom Matrix | StickC | CORE2 | Paper | ...

      R 1 Reply Last reply Reply Quote 0
      • R
        robot_alf @gavin67890
        last edited by

        @gavin67890 nope (

        1 Reply Last reply Reply Quote 0
        • R
          robot_alf @gavin67890
          last edited by

          @gavin67890 yes, I did the same and checked a few times. Not working.

          >>> gc.collect)
          >>> 
          paste mode; Ctrl-C to cancel, Ctrl-D to finish
          === from m5stack import *
          === from m5ui import *
          === from uiflow import *
          === import unit
          === setScreenColor(0x111111)
          === pahub_0 = unit.get(unit.PAHUB, unit.PORTA)
          === Ultrasonic_0 = unit.get(unit.ULTRASONIC, unit.PAHUB0)
          === 
          === 
          Traceback (most recent call last):
            File "<stdin>", line 6, in <module>
            File "unit.py", line 187, in get
            File "<string>", line 1, in <module>
            File "units/_pahub.py", line 7, in __init__
            File "i2c_bus.py", line 32, in get
          KeyboardInterrupt: 
          >>>
          G 1 Reply Last reply Reply Quote 0
          • R
            robot_alf
            last edited by robot_alf

            Core2 working correct with PaHub but StickC Plus not.

            I've tried to use UIFlow 2.0 (Alpha-24), but can't run even just created empty project on StickC Plus:

            Connected to Serial Port!
            I (414565) UIFLOW_UTILITY: Read U32 Key: AUTODETECT Value: 4
            I (445565) UIFLOW_UTILITY: Read U32 Key: AUTODE
            MicroPython v1.20.0 on 2023-08-31; M5STACK with ESP32
            Type "help()" for more information.
            >>> 
            >>> 
            >>> import gc
            MemoryError: memory allocation failed, allocating 512 bytes
            >>> gc.collect()
            MemoryError: memory allocation failed, allocating 512 bytes
            >>> 
            paste mode; Ctrl-C to cancel, Ctrl-D to finish
            === import os, sys, io
            === import M5
            === from M5 import *
            === def setup():
            ===   M5.begin()
            === def loop():
            ===   M5.update()
            === if __name__ == '__main__':
            ===   try:
            ===     setup()
            ===     while True:
            ===       loop()
            ===   except (Exception, KeyboardInterrupt) as e:
            ===     try:
            ===       from utility import print_error_msg
            ===       print_error_msg(e)
            ===     except ImportError:
            ===       print("please update to latest firmware")
            === 
            === 
            === 
            MemoryError: memory allocation failed, allocating 512 bytes
            1 Reply Last reply Reply Quote 0
            • G
              gavin67890 @robot_alf
              last edited by gavin67890

              @robot_alf
              A couple of thoughts: https://www.youtube.com/watch?v=nMsCwqCE5c8 shows similar steps (likewise working from a Core-based device), but I noticed he doesn't Add/+ the PaHUB unit, although it is there to select from as a port (however this video does add https://www.youtube.com/watch?v=HBijjbXDaoo). This might just be an oversight, but I tried it in UIFlow and it does appear in the port dropdown without Add/+.

              The difference is the one pahub_0 line, you could try without. Also, I did note in the comments of the video above others who experienced problems using M5StickC & PaHUB :(.

              without add/+

              setScreenColor(0x111111)
              Ultrasonic_0 = unit.get(unit. ULTRASONIC, unit.PAHUB0)

              with add/+

              setScreenColor(0x111111)
              Ultrasonic_0 = unit.get(unit. ULTRASONIC, unit.PAHUB0)
              pahub_0 = unit.get(unit.PAHUB, unit. PORTA)

              2nd thought, I'm assuming the 20cm cables included in the Ultrasonic sensors are in use and approx. the same StickC Plus to PaHub. No bad pins, poor connections, excessive length, etc. Again thinking power, I was wondering if you could connect the Core2 to one of the 6 inputs, if possible 5V/GND only, to check/confirm sufficient supply on VCC. 3x Ultrasonic should be well within the 500mA from StickC Plus but just in case. Thinking along this line, do you have any other sensors to try (simple switches or similar)?

              Looping @m5stack , I think we have a common issue, so any assistance gratefully received please.
              Alt ref: https://community.m5stack.com/topic/1508/pahub-with-m5stick

              Atom LITE | Atom Matrix | StickC | CORE2 | Paper | ...

              1 Reply Last reply Reply Quote 0
              • R
                robot_alf
                last edited by

                I checked everything several times. Everything works fine for me with Core2, but it doesn’t work with StickC Plus. Moreover, I see the ultrasonic sensor connected through the PaHub if I select PortA for the sensor. And the same time the sensor not found when PAHUB0 port is selected.
                The problem is that we wanted to make a little size machine with 3 ultrasonic sensors and two servo360 for wheels. Core2 requires external power for the servo. StickC Plus has a servo module with a built-in battery that suitable for mobility devices with small dimensions but we can't use ultrasonic devices.
                Ok, I still trying to find a solution how to connect 3 ultrasonic sensors for the StickC Plus.
                To check my case and got the same error is very easy. Just connect ultrasonic sensor through pahub, add the hub and the sensor in UIFlow to the StickC Plus controller and run the project with empty code.

                G 2 Replies Last reply Reply Quote 0
                • G
                  gavin67890 @robot_alf
                  last edited by

                  @robot_alf, An alternate option for you, https://docs.m5stack.com/en/module/goplus2 (I have it, and it works well). This would drive the servos (it has a small battery), or I use external 6x AA pack and DC barrel jack connector.

                  Then either PaHUB I2C to sensors or it has 3x GPIO ports for alternate ultrasonic modules with GPIO ports (black not red), but that would, unfortunately, mean a sensor rebuy.

                  Atom LITE | Atom Matrix | StickC | CORE2 | Paper | ...

                  1 Reply Last reply Reply Quote 0
                  • G
                    gavin67890 @robot_alf
                    last edited by

                    @robot_alf, It would mean a switch to Arduino, but maybe this would help with fault finding (example for PaHub, which happens to use StickC) https://github.com/m5stack/M5StickC/blob/master/examples/Unit/PaHUB/PaHUB.ino
                    I'm thinking scan down through the tree to see where it's connected.

                    Atom LITE | Atom Matrix | StickC | CORE2 | Paper | ...

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

                      Hello guys

                      the following worked for me (M5StickCPlus fw 1.12.3, PaHub, 2x ultrasonic unit *)).

                      *) I don't actually have an ultrasonic unit - I simulated two of them with two ESP32C3 acting as I2C slaves on address 0x57.

                      Note: I did not add PaHub as unit. Just the two Ultrasonic units.

                      from m5stack import *
                      from m5ui import *
                      from uiflow import *
                      import unit
                      
                      setScreenColor(0x111111)
                      Ultrasonic_0 = unit.get(unit.ULTRASONIC, unit.PAHUB0)
                      Ultrasonic_1 = unit.get(unit.ULTRASONIC, unit.PAHUB1)
                      
                      label0 = M5TextBox(37, 38, "label0", lcd.FONT_Default, 0xFFFFFF, rotate=0)
                      label1 = M5TextBox(38, 115, "label1", lcd.FONT_Default, 0xFFFFFF, rotate=0)
                      
                      label0.setText(str(Ultrasonic_0.distance))
                      label1.setText(str(Ultrasonic_1.distance))
                      

                      Edit: I just thrown in four additional I2C units (RFID, EXT.IO2, Gesture and 4 Relay), all connected to the PaHub and everything still works fine for me.

                      Thanks
                      Felix

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

                      teastainT G R 3 Replies Last reply Reply Quote 0
                      • teastainT
                        teastain @felmue
                        last edited by

                        @felmue Hi Felix, where can I find more information on I2C slaves?
                        I could never get Master/Slave to work on ESP32.
                        A snippet of sample code would be REALY(!) nice.
                        Thanks. -Terry

                        Cheers, Terry!

                        100% M5Stack addict with several drawers full of product!

                        1 Reply Last reply Reply Quote 0
                        • G
                          gavin67890 @felmue
                          last edited by

                          @felmue Out of curiosity, could you try adding PaHub as a unit (Port A) and see if everything still works correctly?

                          Atom LITE | Atom Matrix | StickC | CORE2 | Paper | ...

                          1 Reply Last reply Reply Quote 0
                          • R
                            robot_alf @felmue
                            last edited by

                            @felmue looks like the same code that return "ultrasonic not found" at start, but I will check it.

                            1 Reply Last reply Reply Quote 0
                            • R
                              robot_alf
                              last edited by

                              I have made a simple test for Arduino and it works. It show that hardware part is working correct need just fix the problem in the code for UIFlow.

                              #include <M5StickCPlus.h>
                              #include <Unit_Sonic.h>
                              #include "ClosedCube_TCA9548A.h"
                              
                              #define PaHub_I2C_ADDRESS 0x70
                              ClosedCube::Wired::TCA9548A tca9548a;
                              
                              SONIC_I2C sensor;
                              
                              void setup() {
                                  M5.begin();
                                  tca9548a.address(PaHub_I2C_ADDRESS);
                                  sensor.begin();
                                  M5.Lcd.setTextFont(2);
                                  M5.Lcd.setTextColor(YELLOW, TFT_BLACK);
                                  M5.Lcd.println(("PaHUB Example"));
                                  M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK);
                              }
                              
                              void loop() {
                                static float newvalue = 0;
                                for (uint8_t channel = 0; channel < 6; channel++) {
                                  tca9548a.selectChannel(channel);
                                  M5.Lcd.print(channel);
                                  M5.Lcd.print(" = ");
                                  newvalue = sensor.getDistance();
                                  if ((newvalue < 4000) && (newvalue > 20)) {
                                    M5.Lcd.printf("%.2fmm", newvalue);
                                  } else {
                                    M5.Lcd.print("ERR");
                                  }
                                  M5.Lcd.print("\n");
                                }
                                delay(20);
                                M5.Lcd.fillScreen(BLACK);
                                M5.Lcd.setCursor(0,0);
                              }
                              
                              G 1 Reply Last reply Reply Quote 0
                              • felmueF
                                felmue
                                last edited by felmue

                                Hello guys

                                @teastain : See example here.

                                @gavin67890 : yes it still works when I add PaHub as unit on Port A.

                                @robot_alf : have you tried something similar in UiFlow/Micropython? E.g. only adding one Ultrasontic unit and then manually select the PaHub port/channel?

                                Thanks
                                Felix

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

                                1 Reply Last reply Reply Quote 0
                                • G
                                  gavin67890 @robot_alf
                                  last edited by

                                  @robot_alf Have you tried Download rather than just Run from UIFlow? I had it on another project that refused to Run, but worked OK from Download.

                                  Other than that, perhaps just recheck all again from the top, right StickC model (original or Plus), right units for PaHUB and Ultrasonic, etc. Did you want to add some screenshots from UIFlow, Blocky, Python, etc. Maybe with a few pairs of eyes we can spot something (remember to hide your API Key).

                                  Atom LITE | Atom Matrix | StickC | CORE2 | Paper | ...

                                  R 1 Reply Last reply Reply Quote 0
                                  • R
                                    robot_alf @gavin67890
                                    last edited by

                                    @gavin67890 Download not working. I think it is the same like run app just the controller switched to the "app" mode instead of "internet" mode.

                                    1 Reply Last reply Reply Quote 0
                                    • R
                                      robot_alf
                                      last edited by

                                      0_1693946459135_4a3ee96e-095d-4cd6-b8ab-4c08594362e2-image.png
                                      This is crazy but this code working with 3 sensors )
                                      The pahub and ultrasonic was selected to PortA. And sometimes I see distance from incorrect sensor. I think again that hardware part is working, but code for StickC Plus controllers have some bugs.
                                      M5Stack engineers, could you please send me python libraries for pahub and ultrasonic? Maybe I can help to investigate the problem. I don't want to spend time for reverse engineering them from bin-file of UIFlow firmware )

                                      G 1 Reply Last reply Reply Quote 0
                                      • R
                                        robot_alf
                                        last edited by

                                        This code also working but need to connect sensors to 1,2,3 ports of pahub, not to 0,1,2

                                        #include <M5StickCPlus.h>
                                        #include <Unit_Sonic.h>
                                        #include "ClosedCube_TCA9548A.h"
                                        
                                        #define PaHub_I2C_ADDRESS 0x70
                                        ClosedCube::Wired::TCA9548A tca9548a;
                                        
                                        SONIC_I2C sensor;
                                        
                                        void setup() {
                                            M5.begin();
                                            tca9548a.address(PaHub_I2C_ADDRESS);
                                            sensor.begin();
                                            M5.Lcd.setTextFont(2);
                                        }
                                        
                                        void loop() {
                                          static float newvalue = 0;
                                          for (uint8_t channel = 0; channel < 3; channel++) {
                                            tca9548a.selectChannel(channel);
                                            M5.Lcd.printf("%i = ", channel);
                                            newvalue = sensor.getDistance();
                                            if ((newvalue < 4000) && (newvalue > 20)) {
                                              M5.Lcd.printf("%.2fmm   ", newvalue);
                                            } else {
                                              M5.Lcd.print("ERR        ");
                                            }
                                            M5.Lcd.print("\n");
                                          }
                                          delay(20);
                                          M5.Lcd.setCursor(0,0);
                                        }
                                        M 1 Reply Last reply Reply Quote 0
                                        • M
                                          mtylerjr @robot_alf
                                          last edited by

                                          @robot_alf "need to connect sensors to 1,2,3 ports of pahub, not to 0,1,2"

                                          There are 2 hard problems in computer science: cache invalidation, naming things, and off-by-1 errors :D

                                          1 Reply Last reply Reply Quote 2
                                          • G
                                            gavin67890 @robot_alf
                                            last edited by

                                            @robot_alf That's encouraging.
                                            I take that label0 is Ultrasonic_0
                                            , label1 is Ultrasonic_1
                                            , label2 is Ultrasonic_2
                                            What happens if you complete the three unit ultrasonic set (by adding (Add/+) two more Ultrasonic units)?
                                            Have you tried increasing the Wait?

                                            Atom LITE | Atom Matrix | StickC | CORE2 | Paper | ...

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