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

    M5stack core2 control 12 channel Servo module

    Modules
    3
    12
    9.2k
    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.
    • L
      LishengKKK
      last edited by

      Hi,

      I'm using M5stack core2 and 12 channel servo module (https://docs.m5stack.com/en/module/servo) to control servo motors.

      I plug the servo module onto the m5stack core2 and use the code (https://github.com/m5stack/M5Core2/blob/master/examples/Module/SERVO/SERVO.ino)

      but the servo motor, does not work properly, the motor works fine with other drivers.

      I guess there might be some problem with the code.

      could you please help to check if the M5stack core2 could work with the Servo module?

      thank you.

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

        Hello @LishengKKK

        try changing this line:

        Wire.begin(32, 33, 100000UL);
        

        to:

        Wire.begin((int) 32, (int) 33, 100000UL);
        

        Thanks
        Felix

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

        1 Reply Last reply Reply Quote 0
        • L
          LishengKKK
          last edited by

          @felmue thank you.

          I changed the code as you suggested, but the servo still doesn't work.

          could you please share the code which works well on your side?

          thanks again.

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

            Hello @LishengKKK

            my suggestion is based on other examples using I2C where the original code would initialize an I2C slave instead of an I2C master due to some recent changes in the ESP32 Arduino framework.

            I am sorry, but I don't have working code to share as I don't have the necessary hardware to test (e.g. I don't have a Servo module). Sorry.

            Thanks
            Felix

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

            teastainT L 2 Replies Last reply Reply Quote 0
            • teastainT
              teastain @felmue
              last edited by

              @felmue Hi, I see a number of posts where the fix is adding (int) twice in the function’s parameters.
              It seems the parameters are already correct, can you help me understand what difference this makes?
              -thanks, Terry

              Cheers, Terry!

              100% M5Stack addict with several drawers full of product!

              1 Reply Last reply Reply Quote 0
              • L
                LishengKKK @felmue
                last edited by

                @felmue

                thanks a lot, but I still can not fix the problem, now I change to use another controller instead of core2.

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

                  Hello @LishengKKK

                  please try this - leave Wire.begin() as it is but replace Wire with Wire1 in the two functions Servo_write_us90() and Servo_write_angle().

                  Explanation: M5Core2 uses Wire1 for the internal I2C and Wire for the external I2C (Groove port). Wire1 is initialized in M5.begin() and used for the touch screen.

                  Thanks
                  Felix

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

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

                    Hello @teastain

                    Wire.begin() used to always initialize an I2C master, but in recent ESP32 Arduino framework versions an ESP32 can also be setup as I2C slave. But instead of creating a new function like Wire.beginSlave() it has been decided to overload the already existing begin() function so it can be used to initialize an I2C master or a slave.

                    The compiler / linker decides from the argument types which begin function to call. The I2C master begin function is defined like this:

                    bool begin(int sda, int scl, uint32_t frequency=0);
                    

                    And the I2C slave begin function is defined like this:

                    bool begin(uint8_t slaveAddr, int sda, int scl, uint32_t frequency);
                    

                    Now if you call Wire.begin(SDA, SCK) and SDA and SCK are defined as uint8_t the I2C slave begin is called (instead of the intended I2C master begin) since the argument types match better.

                    Thanks
                    Felix

                    P.S.: my original advise to typecast the arguments to (int) was useless as numbers are already defined as int.

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

                    1 Reply Last reply Reply Quote 0
                    • L
                      LishengKKK @felmue
                      last edited by

                      @felmue
                      thank you very much, follow your tips, now the M5stack cores can work with the 12-channel servo.

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

                        Hello @LishengKKK

                        cool. I am happy to hear you got it working. Thank you for reporting back.

                        Thanks
                        Felix

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

                        L 1 Reply Last reply Reply Quote 0
                        • L
                          LishengKKK @felmue
                          last edited by

                          Hi, @felmue

                          Meanwhile, I got a reply from the 'support@m5stack.com'

                          they provided another solution.....

                          in the M5stack core2 library (~/Arduino/libraries/M5Core2/src),
                          in the class 'void M5Core2::begin'
                          change
                          ' // I2C init
                          if (I2CEnable == true) {
                          Wire.begin(32, 33);
                          }'

                          to
                          ' // I2C init
                          if (I2CEnable == true) {
                          Wire.begin(21, 22, 100000UL);
                          }'
                          then in the arduino code:
                          add 'Wire.begin(22, 21);'

                          then the core2 and 12-channel servo will work properly.

                          but the weird thing is that they still work even when I delete the line 'Wire.begin(21,22);' meaning delete all the 'Wire.begin(..,..);' in the void setup() .

                          this is a bit funny.

                          L 1 Reply Last reply Reply Quote 0
                          • L
                            LishengKKK @LishengKKK
                            last edited by

                            @lishengkkk

                            0_1669725911615_fbaad8a0-e3c8-43d4-8534-c63e11b13031-image.png

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