Weird scale rs232 reading with Arduino UNO

Hi there,
I am absolute newbie in Arduino and electronics; I have checked a lot of entries in the forum and tried many things, but I still have no solution to my simple problem.
I have an Arduino UNO rev 3. I want to use Arduino to read the weight form a scale, and some other parameters from sensors, to perform operations and get some results.
When pressing a button in the scale, let’s call it “send” button, the scale sends the weight as rs232 (9600/8/N/1) using 14 Bytes. I have bought a sparkfun shield for adapting the rs232 voltage levels to TTL (SparkFun RS232 Shifter - SMD - PRT-00449 - SparkFun Electronics).
I have also taken pieces of code for reading the scale, adding a delay of 100 ms for checking purposes.

#include <SoftwareSerial.h>
#define rxPin 2
#define txPin 3

SoftwareSerial balanza = SoftwareSerial(rxPin, txPin); // RX, TX

char x;

void setup()  
{
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);

  Serial.begin(19200);
  Serial.println("Goodnight moon!");
  balanza.begin(9600);
 }

void loop() // run over and over
{
    if (balanza.available()) {
    int test = balanza.available();
    Serial.print(test);
    x = balanza.read();
    Serial.print(x); //this produces a series of countdown numbers and readings, only for checking purposes
    }
  delay(100);
  
  }

GND connected to GND. Rx pin (pin 2) connected to Tx of the shield. Tx pin (pin 3) connected to Rx of the shield. VCC is not connected following the scale’s manual. However, I have also tried connecting 5V and 3.3V to VCC, with little differences.
Having everything in place, when pressing the “send” button of the scale, what I obtain is the following:

[MODIFIED: removed “Goodnight moon!” becase I don’t get it when I press “send”; I get "Goodnight moon!"when I open the Serial Monitor, which is OK]
“14ÿ13ÿ12ÿ11ÿ10ÿ9ÿ8ÿ7ÿ6ÿ5ÿ4ÿ3ÿ2ÿ1ÿ”

14 and the countdown numbers are OK since it tells the number of Bytes of the message (balanza.available()).
However, instead of obtaining something like “W=+ 1.05kg” I only get fourteen “ÿ”, which is 255 (11111111).
I have tested connecting the scale to a PC, COM port, and I get normal responses, like “W=+ 1.05kg”.

So, I know that the scale sends the correct information, but I can only get “ÿÿÿÿÿÿÿÿÿÿÿÿÿÿ” (character).

I have also used another rs232/ttl adaptor (http://www.ebay.com/itm/MAX3232-RS232-Serial-Port-To-TTL-Converter-Module-5V-COM-DB9-Connector-W-Cable-/131297394854), but the result has been even worse: I didn’t receive anything when pressing the “send” button of the scale; I only got data when switching the scale off: about 64 Bytes of weird characters.

I have swapped many times Rx and Tx just to check if I was wrong. I have set the Serial baud rate coming to my PC to 19200 to avoid echo with the baud rate of the scale.

What can be wrong? Are both shields damaged? Any ideas or similar problems? Should this be completely solved by using another arduino module with 2 or more hardware serials?

THANK YOU!

Is the RS232 output actually at RS232 voltages? It is extremely common for "RS232" to be used to refer to serial that uses TTL voltage levels.

Thanks for the answer! Just checked the voltage of DB9 pins, 5 to 2 and 5 to 3, with the scale on but not sending data: -8.7 V in both cases. So, I need the rs232 to ttl adapter. Anything wrong? Thanks again.

IgnacioLV: So, I know that the scale sends the correct information, but I can only get "ÿÿÿÿÿÿÿÿÿÿÿÿÿÿ" (character).

That character is the one with the value 255 (0xFF). You usually will get that if you read from a serial port that has no data available and put the result in a byte or char. The -1 that means "No data available" gets truncated to 0xFF. However: it looks like your code is doing the right thing so it should not be trying to read when the buffer is empty. Another cause might be characters that are all 1's. This might be caused by a baud rate that is wildly off or by bad wiring. Have you tried swapping RX and TX? Sometimes the names get switched around.

IgnacioLV: Having everything in place, when pressing the "send" button of the scale, what I obtain is the following:

"Goodnight moon! 14ÿ13ÿ12ÿ11ÿ10ÿ9ÿ8ÿ7ÿ6ÿ5ÿ4ÿ3ÿ2ÿ1ÿ"

Your sketch prints the "Goodnight moon!" message after the Arduino board has made a reset.

Why does your Arduino board reset itself, when you press the "send" button of the scale?

Your Arduino should NOT RESET when you press the "send" button of the scale!

If your Arduino does a reset, then most likely you have problem. Wrong cabling. Short circuit. Or something similar.

Perhaps cabling of pin-2 and pin-3 mixed up.

Thanks @johnwasser. Indeed, my scale has to send 14 bytes (14 characters) when sending the weight, and therefore receiving 14 "ÿ" is more or less OK; I mean, there is data available to read, but somehow I read it badly... As you suggest, I have swapped many times Rx and Tx, without positive results. I really don't know what else to do.

To @jurs I am SORRY!! When I press the send button, the reading I get is the one under "Goodnight moon". I am sorry for having been imprecise. So, when pressing "send" I get 14ÿ13ÿ.....

Thank you!

IgnacioLV:
To @jurs
I am SORRY!! When I press the send button, the reading I get is the one under “Goodnight moon”. I am sorry for having been imprecise. So, when pressing “send” I get 14ÿ13ÿ…

OK, in that case perhaps everything is OK and you just decided to use the worst library that ships with the Arduino IDE: SoftwareSerial.

This SoftwareSerial library has always problems when used with HardwareSerial at the same time.

Perhaps the problems might become less when trying not to print the countdown numbers and just use:

    if (balanza.available()) {
    Serial.write(balanza.read());
    }

Does that make a difference?

@jurs
Not really. Now I get this “ÿÿÿÿÿÿÿÿÿÿÿÿÿÿ”; indeed, I wrote the code with the “available()” information to increase my control, being tired of “ÿÿÿÿÿÿÿÿÿÿÿÿÿÿ” :wink:
Will I solve this issue easily by getting an Arduino DUE or another one with two or more hardware Serials?
Thanks for your time!

Post. Your. Code.

After the last modification, my code looks like this

#include <SoftwareSerial.h>
#define rxPin 2
#define txPin 3
SoftwareSerial balanza = SoftwareSerial(rxPin, txPin); // RX, TX
char x;
void setup()  
{
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  Serial.begin(19200);
  Serial.println("Goodnight moon!");
  balanza.begin(9600);

}

void loop() // run over and over
{
   if (balanza.available()) {
    Serial.write(balanza.read());
    }
  
  }

IgnacioLV: Will I solve this issue easily by getting an Arduino DUE or another one with two or more hardware Serials?

Changing the board will only help in case that you damaged the receive pin/port on your Arduino board.

You didn't provide RS232 voltage (10V or such) to any Arduino pin, didn't you?

If you damaged rxPin 2 you also would be able to use another (undamaged) pin with SoftwareSerial on the Arduino board.

Did you try different baud rates for the scale? Did you check with a PC terminal program that 9600 is really the correct default baud rate for the scale?

I'd perhaps also initialize SoftwareSerial before sending chars using Serial.

void setup()  
{
  balanza.begin(9600);
  Serial.begin(19200);
  Serial.println("Goodnight moon!");
}

jurs: Changing the board will only help in case that you damaged the receive pin/port on your Arduino board.

You didn't provide RS232 voltage (10V or such) to any Arduino pin, didn't you?

Not as far as I know. I always had these readings, and my Arduino is brand new. I haven't had opportunities to damage the pins. I have been trying with different pins. However, I can check this tomorrow.

jurs: If you damaged rxPin 2 you also would be able to use another (undamaged) pin with SoftwareSerial on the Arduino board.

Just done. No difference

jurs: Did you try different baud rates for the scale?

Yes, the results are also weird (2400, 4800, 14400 and 19200) "þÿÿÿÿ", "ÿÿÿûÿÿýý", "ÿ¿·ÿÿÿÿÿÿÿÿÿÿÿ¿ÿÿ÷·" and "ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ". Nice, isn't it? ;-)

jurs: Did you check with a PC terminal program that 9600 is really the correct default baud rate for the scale?

Yes, it worked well.

jurs: I'd perhaps also initialize SoftwareSerial before sending chars using Serial.

void setup()  
{
  balanza.begin(9600);
  Serial.begin(19200);
  Serial.println("Goodnight moon!");
}

Oh! I was really expecting this would have an effect. But I am still getting the same "ÿÿÿÿÿÿÿÿÿÿÿÿÿÿ". Thanks for your time @jurs

IgnacioLV: Oh! I was really expecting this would have an effect. But I am still getting the same "ÿÿÿÿÿÿÿÿÿÿÿÿÿÿ".

Which version of the Arduino IDE do you use?

If Windows, try either IDE version 1.0.1 ... 1.0.5 or version 1.6.1!

You don't try any version number higher than 1.0.5 but lower than 1.6.1, do you?

jurs: Which version of the Arduino IDE do you use?

If Windows, try either IDE version 1.0.1 ... 1.0.5 or version 1.6.1!

You don't try any version number higher than 1.0.5 but lower than 1.6.1, do you?

I have just upgraded to 1.6.1 (I had 1.0.6); unfortunately I still get the same answer. Do I need to upgrade something else, besides the arduino software itself?

IgnacioLV: I have just upgraded to 1.6.1 (I had 1.0.6); unfortunately I still get the same answer. Do I need to upgrade something else, besides the arduino software itself?

No, the Arduino Changelog at http://arduino.cc/en/Main/ReleaseNotes tells for v1.6.1:

Improved SoftSerial library and therefore this "improved" library should be used automatically if you include it and use the 1.6.1 IDE.

Although the overall quality of that library is very bad, it should show something different than you can see while receiving your scale data.

If you want to try a much better serial software emulation, install and use the AltSoftSerial library. Although you must change pins: AltSoftSerial cannot use every pin on your board, but the pins are fixed and depend on the board. On the other side: That library works much better than SoftwareSerial.

And if nothing else helps: Best you can do ist to use always hardware serial, so perhaps try an Arduino board which has two or more hardware serial interfaces on board (i.e. MEGA2560 = 4x hardware serial).

jurs: If you want to try a much better serial software emulation, install and use the AltSoftSerial library. Although you must change pins: AltSoftSerial cannot use every pin on your board, but the pins are fixed and depend on the board. On the other side: That library works much better than SoftwareSerial.

WONDERFUL!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Now I received this data: 168 194 212 223 223 201 209 202 201 223 148 152 242 245 Which in text is: ¨ Â Ô ß ß É Ñ Ê É ß ” ˜ ò õ But if I assess the difference to 255: 87 61 43 32 32 54 46 53 54 32 107 103 13 10 In text it is:

W

+

6 . 5 6

k g " " " " So: W=+ 6.56 kg OU YESSSS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! YES!!!!!!!!!!!!!!!!! YES!!!!!!!!!!!! THANK YOU!!!!!!!!!!!!!!!!!

I just need to investigate how to get the inverted value correctly without burning anything...

Thanks jurs!!!!!!!!!!!!!!!!!!!!!!!!