[SOLVED] Core2 - how to fix the error: call of overloaded 'begin(int ....)' is ambiguous
-
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); } }
-
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.
InM5Unit-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 -
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 -
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);
inUnit_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
FelixP.S. I do not have the Encoder hardware, so I cannot test this myself, sorry.
-
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.
-
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 -
-
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 -
-
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.
-
@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! -
-
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.
-
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 -
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
-
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.
-
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 -
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 -
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