2

I want to interface my barcode scanner with an Arduino using RS232. I have connected 2 (RX), 3 (TX) and 5 (GND) of the RS232 with the corresponding pins of MAX232. I am taking TTL outputs on Arduino pins 6 and 7.

This is the code of the Arduino program:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(6, 7); // RX, TX

void setup() {
  Serial.begin(9600);
}

void loop() {
  // run over and over
  if (mySerial.available()) {
    byte x = mySerial.read();
    Serial.println(x);
  }
}

I am not getting any output on the serial monitor when I scan a product.

  • Please edit your question and include your schematic. – Nick Gammon Jan 14 '16 at 8:23
  • Did you every find the answer? – user23772 Jul 11 '16 at 0:42
  • @Ahnet : Yes at that time we had some other issues too, as mentioned in the comment so didn't put a check then. Thanks for reminding. – explorer Jul 12 '16 at 3:57
7

Assuming your Arduino has only one hardware serial connection (it's something like an Uno rather than a Mega) you're quite right in using software serial, the Arduino will already be using pins 2 and 3 to communicate via USB to the Serial monitor so you can't use them to communicate with the scanner.

However carefully look at your first line of code, you've asked software serial to use pins 6 & 7 yet hooked the barcode scanner to pins 2 & 3. Move those pins over to the one's you've specified.

Secondly in your setup function you've begun communication with hardware Serial but not software serial. You'll need to add something like mySerial.begin(XXX) where XXX is the baud rate for the scanner.

Finally you haven't told the Arduino what pinMode to use for 6 and 7. You'll want pinMode(6, INPUT) and pinMode(7, OUTPUT) in there too.

  • After adding mySerial.begin(XXXX) the code did work properly.. Whenever i move the RS232 pins slightly, i get digits printed on the screen. But not when I scan. – explorer Feb 6 '15 at 18:05
  • 1
    Are you certain you've got them the right way round? – darwinawardee Feb 10 '15 at 10:53
0

RS 232 works on different voltage levels than Arduino, I believe the values you are getting on the screen will have no meaning whatsoever, If the scanner output is TTL then yes it would work, but in my own experience that logic is inverted and you have to add a 1 to software serial:

SoftwareSerial mySerial(6, 7, 1); // RX, TX

The first step is checking what voltage level is given by your scanner output.

0

I tried this as well, for some reason it is NOT WORKING on pins 6 and 7, but it works perfectly using pins 10 and 11 instead. Of course, you still need to add the mySerial.begin().

protected by Community Jul 11 '16 at 9:07

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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