I am trying to read a barcode reader but I am getting weird characters rather than the text expected.
The barcode reader is returning the correct text when connected to a Putty terminal session via USB/serial convertor.
When I connect the output to my Arduino, I get non text characters on my LCD and Arduino terminal.
The reader outputs at 9600 baud. I only use the Tx output connected to D2 input.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
char readChr;
char pageBarCode[40] ; // an array to hold publication barcode
int charCounter = 0; //count position in array
int searchChrNo = 22; //char in string to search for = 23rd char
int pageColour; //read from position in barcode string
boolean newBarCode = false; //Flag to show new code ready to process
SoftwareSerial mySerial(2, 3); // RX, TX
void setup()
{
Serial.begin(9600); // Used to type in characters from terminal
mySerial.begin(9600);
lcd.begin(16,2); // initialize the lcd for 16 chars 2 lines, turn on backlight
}
void loop()
{
// when characters arrive over the serial port...
if (mySerial.available())
{ // wait a bit for the entire message to arrive
delay(100);
newBarCode = true; //there is a new message to process
}
if ( newBarCode == true) {
lcd.clear();
lcd.setCursor(0,0);
while (mySerial.available() > 0 ) // read all the available characters
{
readChr = (mySerial.read() );
lcd.write (readChr);
Serial.print (readChr);
}
newBarCode = false; //end of processing, reset flag
}
}
The barcode reader is returning the correct text when connected to a Putty terminal session via USB/serial convertor.
Perhaps a link to the device would be useful.
Perhaps some details about this USB/serial converter would be useful.
Perhaps a schematic showing how it is wired to the Arduino would be useful.
What I'm thinking now is that the device is a RS232 device, not a TTL device. You might need a MAX232 chip between it and the Arduino.
Thanks to the help, I now have the hardware working. As suggested, it needed a Max323.
Now working on the finer points of displaying on the LCD in a meaningful manner and operating an output depending on the letter in a particular position. The parsing and out part I have working.