Esp32C3 BarcodeScanner Serial blocking
Posted: Tue Jan 04, 2022 4:53 am
**Hardware:**
Esp32C3: https://jacobstoner.com/ESP32-C3/esp32- ... eet_en.pdf
https://jacobstoner.com/ESP32-C3/esp-c3 ... cation.pdf
**Barcode sensor:**
https://cdn.sparkfun.com/assets/b/5/0/e ... 4.6___.pdf
**Connection:**
**Esp32C3 == BarcodeSensor**
3.3v == 3.3v
Rx (pin 19) == Tx
Tx (pin 18) == Rx
Gnd == gnd
**Code**
**Output:**
**Problem:**
As soon I scan a barcode, the serial blocks anything that is in the loop.
Like it will keep printing "int" until I have scanned through barcode reader, then it just only outputs whenever a barcode is scanned.
Even if i keep my void loop empty, it still prints the read barcode, which makes sense as the pins are directly connected to Tx and Rx.
Apparently Esp32C3 has only 1 hardware Uart [ 18 and 19 pins].
Maybe my knowledge on Serial through Rx tx is naïve but I do not see this behavior on Arduino Mega.
Perhaps is this a Esp32C3 issue? Any workaround?
Thanks in Advance to your kind replies!
Esp32C3: https://jacobstoner.com/ESP32-C3/esp32- ... eet_en.pdf
https://jacobstoner.com/ESP32-C3/esp-c3 ... cation.pdf
**Barcode sensor:**
https://cdn.sparkfun.com/assets/b/5/0/e ... 4.6___.pdf
**Connection:**
**Esp32C3 == BarcodeSensor**
3.3v == 3.3v
Rx (pin 19) == Tx
Tx (pin 18) == Rx
Gnd == gnd
**Code**
Code: Select all
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
}
void loop() { // run over and over
if (Serial.available()) {
String recvdCode = Serial.readStringUntil('');
int strToInt = recvdCode.toInt();
Serial.println("int");
Serial.println(strToInt);
if (strToInt)
{
Serial.println(String("recvdCode str ") + String(recvdCode));
Serial.println(String("recvdCode int") + String(strToInt));
}
}
}
Code: Select all
int
int
int
234010
023680
042740
As soon I scan a barcode, the serial blocks anything that is in the loop.
Like it will keep printing "int" until I have scanned through barcode reader, then it just only outputs whenever a barcode is scanned.
Even if i keep my void loop empty, it still prints the read barcode, which makes sense as the pins are directly connected to Tx and Rx.
Apparently Esp32C3 has only 1 hardware Uart [ 18 and 19 pins].
Maybe my knowledge on Serial through Rx tx is naïve but I do not see this behavior on Arduino Mega.
Perhaps is this a Esp32C3 issue? Any workaround?
Thanks in Advance to your kind replies!