I'm having trouble connecting a SparkFun 2D Barcode Scanner Breakout (effectively a DE2120) to a 30-pin ESP32 dev kit v1 (marked ESP-WROOM-32) and running the SerialScan sample application for this sensor successfully.

I believe I have the two devices connected as per the instructions:

ESP32 -> DE2120
3V3 -> 3.3v
RX2 -> RX
TX2 -> TX

In the sample code I have pins configured as follows:

SoftwareSerial softSerial(25,27); 

(according to the mapping here these are the TX2/DX2 and the right pin numbers)

But something is not right: the sample code never reports a connection being made. Tracing this back, it looks like isConnected() here is always returning false, which means sendCommand() is either timing out or getting a DE2120_COMMAND_NACK.

I'm stumped. I've tried 2 different scanner units, replaced all the cables, tried swapping pin numbers around, and done a load of trials using HardwareSerial too with no success. The scanner unit itself responds to commands when I connect it to a laptop and talk to it over USB serial.

Any ideas? I am assuming there is something deeply trivial I'm getting wrong (e.g. in the physical connection or in the specifics of serial connections on ESP32). Generally I've found example code from Arduino libraries runs first time, but I am relatively new to Arduino.

Update 7/20: I have tried with pins 16 and 17, and also with RX2->TX and TX -> RX2. I have scanned the setup barcode as per the instructions.

  • 2
    1) For Serial Communication, you usually connect RX - TX, and TX - RX. 2) For ESP32, the naming convention is based on GPIO pin numbers, So Serial2 (HardwareSerial) is on 16 GPIO16-RX2), and 17 (GPIO17-TX2). 3) ESP32 has 3 hardware serial ports, there is no need for SoftwareSerial.
    – hcheung
    Jul 20 at 5:54
  • maybe the scanner module has to be programmed to use the serial port ... it may be programmed by scanning programming barcodes
    – jsotola
    Jul 20 at 6:27
  • Thank you both. I have tried the connection pattern you suggested, hcheung (though wouldn't reversing the pin numbers in the source code have the same effect? I tried that too), and have tried with 16 and 17 as the pin numbers. SoftwareSerial is what the example source code uses, in my own program I tried using HardwareSerial too. jsotola: yes, I had already done that step - updated original question with details.
    – Tom Hume
    Jul 20 at 15:42

1 Answer 1


Answering my own question: this is about the scanner not getting enough power from the ESP32 devkit board, I think.

When I power both the barcode scanner and the ESP32 from separate power supplies (both USB) I can connect from the ESP32 to the scanner and read codes just fine.

However when I power the scanner from the ESP32, following the instructions in the hookup guide, the scanner is unresponsive.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.