Interfacing barcode scanner with arduino using RS232

arduinobarcodemax232rs232serial

I want to connect a barcode scanner with Arduino. I used MAX232 to convert the levels. I have taken only 3 pins: 2(RX), 3(TX) and 5(GND) from the DB9 cable and given them to pins of MAX232 as shown in the figure:

RS232 with MAX232

This is the code written in Arduino:

#include <SoftwareSerial.h>  
SoftwareSerial mySerial(6, 7); // RX, TX

void setup()  
{
  Serial.begin(9600);
  pinMode(6,INPUT);
  pinMode(7,OUTPUT);
  mySerial.begin(9600);
}

void loop() 
{
    if (mySerial.available())
    Serial.println(mySerial.read());
}

When I move the TX pin on DB9, I get readings like 255, 240, 189, etc., i.e. random numbers. However, when I scan the barcode, I am not getting any output.
I also checked the output of TX pins on an oscilloscope, which showed symmetric waves for a very short amount of time. Again, when the pin 12 of MAX232 (TTL output) was connected to the oscilloscope, no reading was observed.

Best Answer

The 5v signals between the Max232 and your Arduino are inverted (due to the internal gates of the chip). Is the Arduino's 5v RS232 format set up to read data that way? If not try placing extra inverter gates between the Max232 and the Arduino input and output pins. (But if the setup works for another RS232 device perhaps it is ok, then see next paragraph.)

Be sure that the handshake input of the scanner is being satisfied, (otherwise there will be no output data from it). Alternately set the scanner's handshake parameter to "None". If there is no way to disable the handshake you might wire the remaining Max232 buffer (T1out or T2out) up to the scanner's handshake pin, (possibly pin 7 CTS - but check the scanner manual), then fix the other side high or low to satisfy the scanner. Some RS232 devices can be fooled to always output data by shorting there own handshake pins together - CTS & RTS, (possibly on pins 7 & 8 - but again check the manual). Of course verify that you are matching the scanner's other RS232 parameters such as baud, parity, bits, etc.