UART commands for a barcode scanner?

47 Views Asked by At

I am wanting to add a barcode scanner to my Arduino project.

Looking on the internet I see lots of barcode scanners with "UART" compatibility. I looked up the UART protocol and how to use it with the Serial object.

But none of the scanners say what UART values to send via the Serial object in order to start scanning, stop scanning, or know when the scanner got a value. They all seem to assume that I will just know this.

I have tried searching for common UART code for barcode scanners, but I can't seem to find anything.

Are there common commands/values to send via UART for start and stop the scanning of a barcode scanner? (If so, what are they?)

2

There are 2 best solutions below

2
Guillius On

UART is an RX/TX protocol, unlike with e.g. I2C or SPI there is no master who always has to initiate/start the communication. So with UART between an Arduino and a barcode scanner, both can send each other data when it's needed (the data will be in a buffer for the receiver to read).

If you look closely at examples like this one: https://www.rtscan.net/arduino-qr-code-scanner/

You see two things:

  1. if (mySerial.available() > 0 )
    Here the Arduino checks if some data was received from the scanner (if the function returns an integer value >0 this means that there are that amount of bytes available to be read from the scanner.
  2. send_cmd() function is used to send data/commands to the scanner, in order to change the baud rate (the UART communication speed).

PS: in this kind of application it's important to use the SoftwareSerial library, because if you try to use the standard Serial interface (pins 0 and 1 and the default Serial connection between the pc and the Arduino) then the pc-Arduino link would interfere with the Arduino-scanner link.

1
Guillius On

Since you changed an important phrase in the question: "Are there common commands/values to send via UART for start and stop the scanning of a barcode scanner? (If so, what are they?)"

To find an answer for this type of question, you need to read the data sheet of the particular scanner you're interested in. If the commands exist, you'll find them there.

In for example this case, the scanner has 3 so called "trigger modes":
https://www.amazon.com/NETUM-Bluetooth-Handheld-Wireless-NT-1228BL/dp/B07CBS52KJ?th=1
more information is found in the User Manual on the same page:
https://m.media-amazon.com/images/I/B1ZCBcCtqhL.pdf

The key takeaway from this is that it depends on the specific scanner you are using.