1
\$\begingroup\$

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.

\$\endgroup\$
  • 1
    \$\begingroup\$ Do you know what is the protocol the scanner is communicating? \$\endgroup\$ – Eugene Sh. Feb 6 '15 at 18:47
  • \$\begingroup\$ Have you used the correct capacitors around your MAX232? \$\endgroup\$ – brhans Feb 6 '15 at 18:49
  • \$\begingroup\$ Yes, I have programmed it to run on RS232 protocol. I connected it with a desktop and received the proper value in decimal. \$\endgroup\$ – explorer Feb 6 '15 at 18:51
  • \$\begingroup\$ Yes, the connections of all the five capacitors are as per the diagram. \$\endgroup\$ – explorer Feb 6 '15 at 18:52
  • 1
    \$\begingroup\$ btw, can you show how exactly pins are connected to the DB9? \$\endgroup\$ – Eugene Sh. Feb 6 '15 at 19:46
1
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ handshaking is none, parity none and stop bit 1, which are same as default in arduino. We also shorted 7 and 8 pins, but no results \$\endgroup\$ – explorer Feb 7 '15 at 10:29
  • \$\begingroup\$ Any chance the scanner is set up for a bar code format that you don't have? Does the scanner give any indication that a successful scan was made? (Some models give a beep if a good bar code was read.) Note that some pins on the Arduino may not be compatible as RS232 inputs. Also the pinMode instructions should not be needed, (perhaps they are even reassigning the I/O pins incorrectly). For more reference see this example code: arduino.cc/en/Tutorial/SoftwareSerialExample \$\endgroup\$ – Nedd Feb 10 '15 at 13:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.