Formerly working with other devices of the Nano Family (Nano 33 BLE, Nano 33 BLE Sense) I changed over to the ESP32. For most of my sketches I used while(!Serial);
to wait for the serial monitor connection to be established.
This does not work reliable with Nano ESP32. Sometimes the printed output of the sketch becomes visible, sometimes not. I tried multiple combinations (compiling and uploading with and without an opened Serial Monitor window; one or multiple instances of Arduino IDE opened; some or no more Serial Monitor windows opened; enabled/disabled Arduino_Create_Agent; browser not/connected to Arduino IoT cloud), but I could not reproduce a stable pattern when it works or when it does not work.
Only reliable solution is to remove while(!Serial);
from the code and insert some delay(1000);
command to ensure the first lines printed are catched by the serial connection. Weird.
---EDIT--- delay(1000)
also not reliable, so I guess this is an issue of serial connection
Is there a known problem or another method to interrupt the execution for as long as the serial connection is not established?
BTW: I'm going to replace all of my mbed-based Nano 33 devices, since there is a major issue with mbed's Wire library. Wire.endTransmission() does a read() instead of a write() if the transmitBuffer is empty (usedTxBuffer == 0), causing problems with some I2C peripherals, especially with detecting devices with common I2C scanning methods.
see discussions:
https://forum.arduino.cc/t/nano-33-ble-i2c-problems-caused-in-mbed-wire-cpp-read-write-bit-on-i2c-scan/964676/6
https://github.com/arduino/ArduinoCore-mbed/issues/414
https://github.com/arduino/ArduinoCore-mbed/pull/415
I know, this is off-topic, but I'm so disappointed about it. It took me several weeks to find the cause, wrote some discussions in the forum and created a pull request in GitHub. But nothing happens. I'm so tired to fix this piece of sh*t in the code after each mbed_nano library's update.
Wire.cpp looks good now for Nano ESP32 and works with all my devices.
Respected Arduino team, can you please bring working stuff to the market? I know, the offered combination of hardware, software and cloud platform is complex, but at least advertised foundations should work. Thank you!
mbed_nano Wire.cpp (4.0.4):
uint8_t arduino::MbedI2C::endTransmission(bool stopBit) {
#ifndef TARGET_PORTENTA_H7
if (usedTxBuffer == 0) {
// we are scanning, return 0 if the addresed device responds with an ACK
char buf[1];
int ret = master->read(_address, buf, 1, !stopBit);
return ret;
}
#endif
if (master->write(_address, (const char *) txBuffer, usedTxBuffer, !stopBit) == 0) return 0;
return 2;
}
esp32 Wire.cpp (2.0.11):
/*
https://www.arduino.cc/reference/en/language/functions/communication/wire/endtransmission/
endTransmission() returns:
0: success.
1: data too long to fit in transmit buffer.
2: received NACK on transmit of address.
3: received NACK on transmit of data.
4: other error.
5: timeout
*/
uint8_t TwoWire::endTransmission(bool sendStop)
{
if(is_slave){
log_e("Bus is in Slave Mode");
return 4;
}
if (txBuffer == NULL){
log_e("NULL TX buffer pointer");
return 4;
}
esp_err_t err = ESP_OK;
if(sendStop){
err = i2cWrite(num, txAddress, txBuffer, txLength, _timeOutMillis);
#if !CONFIG_DISABLE_HAL_LOCKS
//release lock
xSemaphoreGive(lock);
#endif
} else {
//mark as non-stop
nonStop = true;
#if !CONFIG_DISABLE_HAL_LOCKS
nonStopTask = xTaskGetCurrentTaskHandle();
#endif
}
switch(err){
case ESP_OK: return 0;
case ESP_FAIL: return 2;
case ESP_ERR_TIMEOUT: return 5;
default: break;
}
return 4;
}