1

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.

Greenonline
  • 2,064
  • 7
  • 23
  • 38
explorer
  • 250
  • 3
  • 11
  • 1
    Do you know what is the protocol the scanner is communicating? – Eugene Sh. Feb 06 '15 at 18:47
  • Have you used the correct capacitors around your MAX232? – brhans Feb 06 '15 at 18:49
  • Yes, I have programmed it to run on RS232 protocol. I connected it with a desktop and received the proper value in decimal. – explorer Feb 06 '15 at 18:51
  • Yes, the connections of all the five capacitors are as per the diagram. – explorer Feb 06 '15 at 18:52
  • By protocol I mean the logical protocol. What kind of values should it send? – Eugene Sh. Feb 06 '15 at 18:54
  • @EugeneSh. No i dont know the logical protocol. Please give me some information on what is that and how to find it out. – explorer Feb 06 '15 at 18:56
  • Ok, RS-232 is a so-called physical layer. It is used to transmit bytes, regardless of their meaning. The higher-level layer would be the protocol I mean. It will define what kind of bytes would be sent. For example it could be just a simple ASCII text protocol, where each byte is encoding a readable character – Eugene Sh. Feb 06 '15 at 19:00
  • @EugeneSh. ASCII is the default protocol. – explorer Feb 06 '15 at 19:04
  • Ok. Are you sure about the baud rate? – Eugene Sh. Feb 06 '15 at 19:05
  • @EugeneSh. Yes, it is 9600. – explorer Feb 06 '15 at 19:06
  • Looks like electrical problem. Can you measure the +10/-10V? – Eugene Sh. Feb 06 '15 at 19:32
  • 1
    btw, can you show how exactly pins are connected to the DB9? – Eugene Sh. Feb 06 '15 at 19:46
  • Depending on the scanner it's probably worth tying the CTS and RTS lines and DTR and DSR lines together on the scanner end of the connector. It might rely on hardware handshaking bt default. – PeterJ Feb 07 '15 at 04:58
  • Does the barcode scanner work properly if connected directly to the PC, to Hyperterminal or PuTTY (a test for funny protocols etc)? Then, does if work with only pins 2,3,5 connected (a test for any hardware flow control required)? – tomnexus Feb 07 '15 at 05:24
  • @EugeneSh. I had placed a strip on the breadboard and a strip on 2,3,5 pins on the DB9 end. They were connected with jumper wires. 5 pin to GND. 2nd to 14 and 3rd to 13 pin of MAX232. Then 11th pin of IC to 7 pin on Arduino and 12th pin to 6th of Arduino. 5V supply to IC was given from 5V output on arduino and both their grounds made common with the GND of RS232 (pin 5) – explorer Feb 07 '15 at 09:15
  • @EugeneSh. On giving supply to the scanner, i measured the voltage between 5 and 3 pins, which i am getting 0.02V. On scanning the product also no change is observed. – explorer Feb 07 '15 at 09:32
  • This is not right. Pin 2 of Db9 is Rx of the computer, and hence Tx of the device. So it has to be connected to 13 or 8 of the chip, and corresponding 12 or 9 to Rx of arduino. Tx of arduino will go 11or 10, and 14 or 7 going to DB9 pin 3, which is scanner's RX. – Eugene Sh. Feb 07 '15 at 11:31
  • @EugeneSh.. Thank you. I corrected the connections and i am getting the output. – explorer Feb 12 '15 at 06:27

1 Answers1

1

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.

Nedd
  • 7,939
  • 15
  • 19
  • 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 – explorer Feb 07 '15 at 10:29
  • 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: http://arduino.cc/en/Tutorial/SoftwareSerialExample – Nedd Feb 10 '15 at 13:10