For the past couple of days i have been trying to create a program which reads from a Tx of barcode scanner. I have tried a bunch of different things such as different programs but also different scanners. A sample program that i wrote is for example:
#include <SoftwareSerial.h>
SoftwareSerial mySerial (50, 51);
unsigned char incomingByte;
void setup ()
{
Serial.begin (9600);
mySerial.begin (9600);
Serial.println ("begin initial Serial!\n");
}
void loop ()
{
while(mySerial.available () > 0)
{
incomingByte=mySerial.read ();
Serial.print (incomingByte,HEX);
}
Serial.println ();
}
At this time i can not provide a proper connection diagram (will when i have a chance), but the arduino MEGA 2560 is connected with 3 wires to the barcode scanner, A Tx (pin 50), Rx (pin 51) and GND
background info on transmitted data: startbit: 0x02 stopbit: 0x03
Ultimate goal: Scanner scans barcode, arduino reads the datastream and sends a output when it recognizes a code.
How do i achieve the ultimate goal?
Thanks in advance!
Arduino 2560 pin 50 and 51 are TTL level signals. You need to provide a RS-232 driver to invert and level shift the signal.
An example driver is MAX232CPE.
Also, softwareserial supports an option to invert the logic level. From the Arduino page:
inverse_logic: is used to invert the sense of incoming bits (the default is normal logic). If set, SoftwareSerial treats a LOW (0 volts on the pin, normally) on the Rx pin as a 1-bit (the idle state) and a HIGH (5 volts on the pin, normally) as a 0-bit. It also affects the way that it writes to the Tx pin. Default value is false.
Warning: You should not connect devices which output serial data outside the range that the Arduino can handle, normally 0V to 5V, for a board running at 5V, and 0V to 3.3V for a board running at 3.3V.