Interfacing weighing scale to Arduino Uno via RS232

I am trying to obtain the weights from a weighing scale KERN ew220-3nm to Arduino Uno through RS232.
This is the code :

#include <SoftwareSerial.h>
SoftwareSerial mySerial(5, 4);  

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

}

void loop() 
{
 while (mySerial.available()){
   Serial.println(mySerial.read(),HEX);
}
 }

As per the device manual, the complete transmitted output consists of 15 words, 1 start bit, 8 data bits(except 2-9 words which are data bytes and have maximum 6 characters), no parity, 2 stop bits.

This is the output obtained :

6A
9F
7C
F1
86
C6
1A
C6
46
19
43
97
43
15
79
EB
0

I have a few doubts -

  1. Do the 2 stop bits as mentioned in the device manual disturb my complete data or is it ignored?

  2. Whenever I print the incoming byte, does it print only the last byte or does it print some data from before along with the incoming data(if it is not a complete byte)?

  3. Is the data to be read inversely due to the RS232 protocol of sending the LSB first?

  4. The results include 16 or sometimes 17 words (which is basically not possible). The first word is 2BH or 20H and the last words as specified by the manual are CR and LF. But I cannot detect any output corresponding to that. Does that mean all of my output is some garbage data or do I need to decode it somehow?

Please help me with this. Thank you.

I understood more about working with RS232 protocol since the last post, but as it turns out, not enough. My previous doubts are solved. But I have newer ones.

I saw something about the Library AltSoftSerial and used it in my program instead of SoftwareSerial and I think I am getting better results. It is to do with the amount of time the libraries waste before recording the data using Interrupt.
I know that this library gives better results as the manual says that the serial data is made of 15 words (bytes) and I am getting exactly 15 bytes now, with constant 1st, 2nd last and last bytes, as expected. But still, the data does not match the one I require. I shouldn’t be required to decode serial data, should I?

The ‘new’ code is

#include <AltSoftSerial.h>
AltSoftSerial mySerial;  
#define TwobitDelay 200
void setup()  {
   Serial.begin(9600);  
   mySerial.begin(9600);
}
 void loop() {
   while (mySerial.available()){
     Serial.println(mySerial.read(),HEX);
     delayMicroseconds(TwobitDelay);
   }
}

And my results are :

6A
C6
C6
86
C6
E3
C6
C6
86
13
E1
23
45
1E
3D

As mentioned earlier, 6A, 1E and 3D are obtained in every set of data. Also, this is for 0 gram, which could mean C6 or 86 is 0. But I do not think I should need to decode it this way.
Please guide me on what could still be wrong. Thank you.

Do you have a link to the manual?

Here is the link : manual

How do you have "8.2.2 Parameters for the serial interface" set up?

If you have doubts about the data you can connect the device to some kind terminal emulator like the Realterm which is able provide raw data in hexa to output.
Your program from first post should work correctly also. You’ve wrote that your question from the first post were solved, anyway:

  1. Do the 2 stop bits as mentioned in the device manual disturb my complete data or is it ignored?

Serial has 1 stop bit by default (8N1), see the reference for begin() to avoid confusion. Stop bits are cared out on bottom level and read() provides pure raw data only.

  1. Whenever I print the incoming byte, does it print only the last byte or does it print some data from before along with the incoming data(if it is not a complete byte)?

Whenever you read incoming byte it is removed from serial line buffer and it is no more available for reading. Since you have condition for data availability you can print only incoming byte which is not read yet.

  1. Is the data to be read inversely due to the RS232 protocol of sending the LSB first?

Data a sent and read in same order.

  1. The results include 16 or sometimes 17 words (which is basically not possible). The first word is 2BH or 20H and the last words as specified by the manual are CR and LF. But I cannot detect any output corresponding to that. Does that mean all of my output is some garbage data or do 1. Do the 2 stop bits as mentioned in the device manual disturb my complete data or is it ignored?
    I need to decode it somehow?

The first condition is to have correct serial line setting.

You are mixing word and byte phrase. Word is 2 bytes!

According the manual, you have to provide the config parameter into begin() function to set 2 stop bits since there is no setting option. For an example Serial.begin(9600, SERIAL_8N2). You have to use HW serial line for it since software serial libs probably doesn't support this settings.

wildbill:
How do you have "8.2.2 Parameters for the serial interface" set up?

The scale parameters are set as 9600 baud rate with no parity.

Budvar10:
According the manual, you have to provide the config parameter into begin() function to set 2 stop bits since there is no setting option. For an example Serial.begin(9600, SERIAL_8N2). You have to use HW serial line for it since software serial libs probably doesn't support this settings.

I read it somewhere that receiver stop bits can be set to 1 bit even when the transmitter is 2 stop bits. But I will try it with Hardware pins, just to be sure.

Budvar10:
You are mixing word and byte phrase. Word is 2 bytes!

The manual mentions only words. But it also says that the last word is 0AH. So does it mean 1 or 2 bytes for words?

tbafna:
I read it somewhere that receiver stop bits can be set to 1 bit even when the transmitter is 2 stop bits. But I will try it with Hardware pins, just to be sure.

I don't think so. You have to have exactly 2 stop bits.

Quote from: Budvar10 on 29-03-2015, 22:41:55

You are mixing word and byte phrase. Word is 2 bytes!

The manual mentions only words. But it also says that the last word is 0AH. So does it mean 1 or 2 bytes for words?

I see, they write about words but thought bytes, I think.

Budvar10:
According the manual, you have to provide the config parameter into begin() function to set 2 stop bits since there is no setting option. For an example Serial.begin(9600, SERIAL_8N2). You have to use HW serial line for it since software serial libs probably doesn't support this settings.

I have tried it using the hardware serial pins of Arduino Uno with the pin configured with Serial_8N2 and it gives me the same results as above.

Did you try a terminal emulator also?

Budvar10:
Did you try a terminal emulator also?

I finally did. Using HTerm, I got the same results as with the Arduino. In fact, the results match with the ones obtained with SoftwareSerial library and not AltSoftSerial library.
The results of Even and No parity vary in the number of bytes too. That cannot be right.

Just idea but try to decrease speed to default 2400.
...and without stop bits ?

EDIT: Another thing: Is the connection correct, are you using rs232/ttl convertor?
Ah, default speed is 1200.

Budvar10:
Just idea but try to decrease speed to default 2400.
...and without stop bits ?

I don't understand. How do I not use stop bits?

Budvar10:
EDIT: Another thing: Is the connection correct, are you using rs232/ttl convertor?

For the emulator, it already has the circuit in the wire, right?
With the arduino, I am already using MAX232.

tbafna:
For the emulator, it already has the circuit in the wire, right?
With the arduino, I am already using MAX232.

I just want to know if it is ok, but yes.

I don't understand. How do I not use stop bits?

Just suggestion to try different stop bits on the receiving site only and tx site stay unchanged. The data gives me no sense. I analyzed it from right, left, bits... just catching straw.

The last things:

  1. Is the serial cable ok? Could you try it on any other device?
  2. Something with the scale device.
  3. Decrease the transfer speed.
  4. To try measure some weights and seek for pattern in data.