Hello, I am using this QR/Barcode Scanner. I want to use it with an arduino uno to scan barcodes however when it detects a barcode it just beeps and doesn't return anything on the serial monitor. I connected the vcc to 5v, gnd to gnd, and then connected the green tx pin to pin 0 and white rx pin to pin 1. Here's the code I'm using
#include <SoftwareSerial.h>
SoftwareSerial mySerial(0, 1); // RX, TX
void setup()
{
Serial.begin(9600);
mySerial.begin(9600); // set the data rate for the SoftwareSerial port
}
void loop()
{
if (mySerial.available()) // Check if there is Incoming Data in the Serial Buffer.
{
while (mySerial.available()) // Keep reading Byte by Byte from the Buffer till the Buffer is empty
{
char input = mySerial.read(); // Read 1 Byte of data and store it in a character variable
Serial.print(input); // Print the Byte
delay(5); // A small delay
}
}
}
So can anyone tell me if there's something wrong with the code or if I'm not connecting the data pins to the right places for an uno?
#include <SoftwareSerial.h>
SoftwareSerial mySerial(4, 5); // RX, TX (0 and 1 colliding with hardware serial pins)
void setup()
{
Serial.begin(9600);
mySerial.begin(9600); // set the data rate for the SoftwareSerial port
}
void loop()
{
if (mySerial.available()>=1) // Check if there is Incoming Data in the Serial Buffer.
{
while (mySerial.available()) // Keep reading Byte by Byte from the Buffer till the Buffer is empty
{
char input = mySerial.read(); // Read 1 Byte of data and store it in a character variable
Serial.write(input); // Print the Byte
delay(5); // A small delay
}
}
}
Ok I switched it to pins 4 and 5 and it has an extended beep and then nothing shows on the serial monitor. I was doing some tests and it doesn't even get past the if(mySerial.available()){
so for some reason it can detect a barcode but whenever it reads it it doesn't give any data to the serial monitor. Do I need to specify I'm trying to read barcodes? Or is this component just dysfunctional.
There seems to be some confusion about the serial interface of the barcode reader that you linked to
At one point on the page the serial interface is described like this
USB and TTL dual interface
and in another
Connectivity Technology RS232, USB Cable
RS232 and TTL are not the same thing. The Arduino uses TTL levels and cannot directly use an RS232 interface. Have you got a data sheet for the scanner that clarifies what type of serial interface it has ?
Well in the tutorial it says to connect it to pin 4 and 5 and I assumed that that was the tx and rx of the Nano. Turned out to be wrong but when I changed that to pin 4 and 5 of the uno it still didn't work.