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

    [SOLVED] Core2 - how to fix the error: call of overloaded 'begin(int ....)' is ambiguous

    Arduino
    3
    19
    16.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.
    • Marelli7M
      Marelli7
      last edited by Marelli7

      When using the GitHub M5Unit_Encoder (with recently updated .cpp) I'm getting this call of overloaded error.

      .../Arduino/libraries/M5Unit-Encoder/src/Unit_Encoder.cpp: In member function 'void Unit_Encoder::begin(TwoWire*, uint8_t, uint8_t, uint8_t, uint32_t)':
      .../OneDrive-Persoonlijk/Arduino/libraries/M5Unit-Encoder/src/Unit_Encoder.cpp:11:46: error: call of overloaded 'begin(int, int, uint8_t&)' is ambiguous
           _wire->begin((int)_sda, (int)_scl, _speed);
                                                    ^
      In file included from .../Arduino/libraries/M5Unit-Encoder/src/Unit_Encoder.h:13,
                       from .../Arduino/libraries/M5Unit-Encoder/src/Unit_Encoder.cpp:1:
      .../Library/Arduino15/packages/m5stack/hardware/esp32/2.0.4/libraries/Wire/src/Wire.h:79:10: note: candidate: 'bool TwoWire::begin(int, int, uint32_t)'
           bool begin(int sda=-1, int scl=-1, uint32_t frequency=0); // returns true, if successful init of i2c bus
                ^~~~~
      .../Library/Arduino15/packages/m5stack/hardware/esp32/2.0.4/libraries/Wire/src/Wire.h:80:10: note: candidate: 'bool TwoWire::begin(uint8_t, int, int, uint32_t)'
           bool begin(uint8_t slaveAddr, int sda=-1, int scl=-1, uint32_t frequency=0);
                ^~~~~
      
      exit status 1
      
      Compilation error: exit status 1
      

      The author just edited the .ccp file because of this error. Somehow didn't work for me...
      It's obvious that something is wrong with the number of arguments, but I do not have the knowledge to figure out what to do to solve this.

      below the .ino (stripped to the basics)

      #include "Unit_Encoder.h"
      Unit_Encoder encoder;
      
      void setup() {
        M5.begin();       // Init M5Stack
        encoder.begin();  //sensor.begin(&Wire) doesn't work
      }
      
      void loop() {
        //signed short int encoder_value = encoder.getEncoderValue();
        bool btn_status = encoder.getButtonStatus();
      
        if (!btn_status) {
          M5.Lcd.fillRect(20, 160, 30, 30, DARKGREY);
          M5.Lcd.setTextColor(YELLOW);
          M5.Lcd.setTextSize(1);
          M5.Lcd.drawString("button", 30, 180, 4);
        }
      }
      
      1 Reply Last reply Reply Quote 0
      • felmueF
        felmue
        last edited by felmue

        Hello @Marelli7

        thank you for reporting this error. We tried to fix some stuff regarding I2C master / slave but it looks like the Encoder library needs an additional fix.
        In M5Unit-Encoder/src/Unit_Encoder.h try replacing:

            uint8_t _speed;
        

        with

            uint32_t _speed;
        

        BTW: I made a pull-request to fix issue in the library.

        Thanks
        Felix

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

        1 Reply Last reply Reply Quote 0
        • Marelli7M
          Marelli7
          last edited by

          Hello Felix,

          Thanks for the quick reply, that part is solved! Compiled and runs on the Core2 !! (even without the #include "pins_arduino.h")
          but... something else is wrong too I guess.
          The encoder doesn't return any values (value = -1) and the LED's do not respond to setLEDColor(). I2C-scan shows correct address 0x40 meaning the STM32F0 is found on the I2C-bus.
          Done testing with a slightly modified example (stauts replaced by status ... I'm a dislect too ;-)

          void loop() {
            signed short int encoder_value = sensor.getEncoderValue();
            bool btn_status = sensor.getButtonStatus();
            Serial.println(encoder_value);
            if (last_value != encoder_value) {
              if (last_value > encoder_value) {
                sensor.setLEDColor(1, 0x000011);
              } else {
                sensor.setLEDColor(2, 0x111100);
              }
              last_value = encoder_value;
            } else {
              sensor.setLEDColor(0, 0x001100);
            }
            if (!btn_status) {
              sensor.setLEDColor(0, 0xC800FF);
            }
            M5.Lcd.fillRect(00, 00, 160, 70, DARKGREY);   //overwrite text
            M5.Lcd.setTextColor(YELLOW);
            M5.Lcd.setTextSize(1);
            M5.Lcd.drawString("button  " + String(btn_status), 10, 10, 4);
            M5.Lcd.drawString("encoder " + String(encoder_value), 10, 40, 4);
            delay(20);
          } 
          

          Regards,
          Paul

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

            Hello @Marelli7

            hmm, since the example was for M5Stack I am wondering if the correct GPIOs are defined for the external I2C on port A. (M5Stack uses 21 and 22 whereas M5Core2 uses 32 and 33.)
            Could you try to add the following lines just before _wire->begin((int)_sda, (int)_scl, _speed); in Unit_Encoder.cpp:

            Serial.printf("SDA: %d SCL: %d\n", SDA, SCL);
            Serial.printf("_sda: %d _scl: %d\n", _sda, _scl);
            

            then post the debug output here? Both SDA and _sda should be 32 and both SCL and _scl should be 33.

            Thanks
            Felix

            P.S. I do not have the Encoder hardware, so I cannot test this myself, sorry.

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

            1 Reply Last reply Reply Quote 0
            • Marelli7M
              Marelli7
              last edited by

              I added these lines to the .cpp file, but there is no related output on the Serial Monitor.

                  _sda   = sda;
                  _scl   = scl;
                  _speed = speed;
              	Serial.printf("SDA: %d SCL: %d\n", SDA, SCL);
              	Serial.printf("_sda: %d _scl: %d\n", _sda, _scl);
                  _wire->begin((int)_sda, (int)_scl, _speed);
              

              Any other tips to get these GPIO's displayed?

              No worries. I'll do the testing for you.

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

                Hello @Marelli7

                after burning the modified application and attaching the debug window try resetting your M5Core2 (button next to the SD card slot). The debug output probably happens before the debug window has reattached. Alternatively add a delay() of a couple of seconds before those lines.

                Thanks
                Felix

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

                Marelli7M 1 Reply Last reply Reply Quote 0
                • Marelli7M
                  Marelli7 @felmue
                  last edited by

                  @felmue

                  SDA: 21 SCL: 22
                  _sda: 21 _scl: 22
                  

                  The sticker on bottom of the Core2 :
                  0_1664812413941_45b23e0b-b792-468a-8321-9e7f07f4285b-afbeelding.png

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

                    Hello @Marelli7

                    ok, for some reason the compiler / linker thinks you are using an M5Stack. Is there a way you can select the board you are using? It should be M5Core2.

                    Alternatively you can try to force it to use the correct GPIOs for M5Core2 by replacing this line:

                        sensor.begin();
                    

                    with

                        sensor.begin(&Wire, 0x40, 32, 33);
                    

                    Thanks
                    Felix

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

                    1 Reply Last reply Reply Quote 0
                    • Marelli7M
                      Marelli7
                      last edited by

                      Hello @felmue,

                      Arduino IDE 2.0.0 current settings:
                      0_1664821688430_Core2.jpg

                      No luck using sensor.begin(&Wire, 0x40, 32, 33);

                      teastainT 1 Reply Last reply Reply Quote 0
                      • Marelli7M
                        Marelli7
                        last edited by

                        It's getting worse: same issue using the M5Stamp_I/O:
                        connected an HW-040 (rotary encoder module) to the M5Stamp I/O.
                        WireScan.ino found address 0x45.

                        while (!extio.begin(&Wire, 32, 33, 0x45)) {  //I2C was 21,22 for Core 2 32,33
                            //Serial.println("extio Connect Error");
                            M5.Lcd.drawString("extio Connect Error", 0, 0, 4);
                            while (1) {}
                          }
                        

                        Core2 display shows: extio Connect Error

                        BTW: The Unit_DDS function generator with an STM32 works fine connected to the Core2.

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

                          @marelli7 Hi!
                          I set up my Core2 with a M5Stack ENVII sensor with this simple program...and it works fine.
                          #include <Wire.h>
                          #include <M5Core2.h>
                          #include <SHT3X.h>
                          SHT3X sht30;
                          float tempC = 12.3;

                          void setup() {
                          Wire.begin(32, 33); //SDA, SCL for Core 2 and Stamp PICO
                          Serial.begin(115200);
                          delay(1000);
                          Serial.println("Setup " );
                          }
                          void loop() {
                          if (sht30.get() == 0)
                          {
                          tempC = sht30.cTemp;
                          }
                          delay(1000);
                          Serial.print("Temp= " );
                          Serial.println(tempC, 1);
                          }

                          I realize that the ENVII does not use sensor.begin(), but I just wanted to say that Wire.begin(32, 33); works with Core2 and an I2C sensor.
                          Hope this helps!

                          Cheers, Terry!

                          100% M5Stack addict with several drawers full of product!

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

                            Hello @Marelli7

                            hmm, not sure what's going on.

                            Could you try installing UIFlow firmware (using M5Burner) onto your M5Core2 and then use UIFlow online? I've checked and the Encoder Unit is available for M5Core2. That would tell us that the hardware and setup is ok.

                            Thanks
                            Felix

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

                            Marelli7M 1 Reply Last reply Reply Quote 0
                            • Marelli7M
                              Marelli7
                              last edited by

                              Hi @felmue,

                              I'm not familiar with UIFlow (yet). Currently using Arduino IDE to program and maintain a dozen ESP32 Devkits.
                              Can I use both UIFlow and Arduino IDE alternately?

                              I cannot understand why my Unit_DDS runs fine on a Core2 and where it goes wrong using the encoder and Stamp I/O -using Arduino IDE. All 3 are using the STM32-chip.

                              The lack of easy accessible I/O makes the Core2 less usable for me. That's why I first bought the Extend I/O (PCA9554PW) > Not working. Then the I2C Encoder (not working) and Stamp I/O (not working). Quite frustrating.

                              First I'll try the Encoder on an ESP32 or even an Uno to set the frequency of the DDS.

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

                                Hello @Marelli7

                                yes, you can use UIFlow and Arduino IDE alternately. UIFlow is just another ESP32 firmware.

                                While those units use the same STM32 chip the firmware inside the STM32 chip is different.

                                I do have the unit EXTIO2 (which uses the same internal STM32 firmware as Stamp I/O) and it works fine with my M5Core2 after adapting the M5Stack example for M5Core2 by replacing those two lines:

                                #include <M5Stack.h>
                                
                                while (!extio.begin(&Wire, 21, 22, 0x45)) {
                                

                                with

                                #include <M5Core2.h>
                                
                                while (!extio.begin(&Wire, 32, 33, 0x45)) {
                                

                                like you did.

                                Note: Make sure you have installed the latest M5Unit-EXTIO2 library. It has been fixed as well for the I2C master slave issue, but the version number has not been increased. So you probably need to re-install it in your environment manually. If your installed version has this line

                                _wire->begin((int)_sda, (int)_scl);
                                

                                then your version already has the fix. Note the two (int).

                                Thanks
                                Felix

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

                                1 Reply Last reply Reply Quote 0
                                • Marelli7M
                                  Marelli7
                                  last edited by

                                  @felmue

                                  Thanks a lot!! Message "extio Connected" made my day. I already changed the I2C adresses, but the (int) did the trick.
                                  I was close to the point to give the Core2 some flying lessons.

                                  Next will be getting familiar with UIFlow

                                  let's close this topic

                                  1 Reply Last reply Reply Quote 0
                                  • Marelli7M
                                    Marelli7 @felmue
                                    last edited by

                                    Hello @felmue ...A Catch22

                                    Finally managed to get the M5Burner to do its job (needed a Burner beta version for the Mac .....why...)

                                    the IDE doesn't has the encoder unit listed in the Unit list when using the (+), but the IDE does connect to my Core2. And I don't know how to add unlisted Units to the IDE

                                    The web version has the Unit_Enoder but is unable to connect to the Core2 (using Chrome). Somehow I'm unable to select the port to be used. User ajb2k3 suggested to use the orange Terminal button. The terminal connects OK, but the UIFlow doesn't.

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

                                      Hello @Marelli7

                                      the IDE version is quite old and as I understand no longer maintained. I don't think you can add unlisted units to it.

                                      When UIFlow firmware is burned and running on your M5Core2 use M5Burner to set SSID and password. It should then connect to your WiFi and the UIFlow (online) backend.

                                      UIFlow, running in the browser, also connects the the backend. You then type in the ID that is shown on the M5Core2 screen and the browser and the M5Core2 then talk to each other through the backend.

                                      Note: for that to work no USB connection is needed.

                                      Thanks
                                      Felix

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

                                      1 Reply Last reply Reply Quote 0
                                      • Marelli7M
                                        Marelli7
                                        last edited by

                                        Thanks again @felmue
                                        I appreciate these spot-on answers other then guessing what might be the cause (sorry).

                                        I wasn't aware of that and I noticed that my Mac was on another SSID. No I understand why 'it' asks to use the same SSID as my mac....

                                        FYI: I got my Unit_DDS running on the Core2, controlled by a rotary-encoder (HW-040) connected to the M5Stamp I/O. Both, DDS and I/O, on I2C. Completely useless, other than testing my oscilloscope and hearing loss and blowing a candle with 10Hz, but fun to build.

                                        groeten,
                                        Paul

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

                                          Hello @Marelli7

                                          you are welcome. I sounds like you are having fun. And thanks for reporting back. I am glad to hear you got it working to your liking.

                                          Thanks
                                          Felix

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

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