RS232 Continuous Serial Communication Unidentifiable Data

Hi guys,

I’m trying to use my Arduino Uno as an interface to collect data from different sensor outputs and output a ‘report’ when a test has been completed, I’m however running into difficulties reading data from a serial output via RS232. Your help would be much appreciated.

The sensor outputting RS232 is a set of scales, datasheet link:
https://www.scalesmart.com/media/PFB-Manual.pdf
The section on data output starts on page 44. It describes the serial communication setting (9600/8-N-1), and data output format (17 bytes long, starting with ST/US (stable/unstable) marker and ending with CR and LF line breaks). I’ve spoken to the scale manufacturer and they confirmed the data is in ASCII format.
Picture with RS232 monitor on PC: https://ibb.co/hMZQDL

I’ve plugged the scales into my PC, and using a piece of serial monitoring software have confirmed the data is being output as it should (although it actually outputs 18 bytes per message- I assume the datasheet was formatted incorrectly). The PC receives eg.: "ST,G 34.44 g ".

I’m using a DFROBOT RS232 shield (with integrated MAX3232 chip), link:
https://www.dfrobot.com/product-1030.html

I have the correct RS232 cable plugged into the RS232 shield, with headers running between the output pins on the shield to pins 10, 11 and GND on the Arduino (the VCC pin is left unused). I’m using the SoftwareSerial library to activate pins 10&11 for communication with the scales, and leaving 0&1 for USB.

Using the following code with the SoftwareSerial library (created by Tom Igoe, and posted on this forum) :

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
}

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

The serial monitor outputs seemingly nonsensical data, with boxes suggesting it’s receiving incomplete characters (see attached picture of the serial monitor). Note I added timestamps out of interest.

(Sadly the picture doesn’t want to embed- here’s a link)

Seeing as boxes are appearing in the serial monitor, I assume some of the data is being lost or I’m not giving Arduino the message structure it needs to interpret the incoming data. After research, I’m still not sure why the Serial Monitor is separating the data like it is- groups of characters (and boxes) seem to be coming in at exactly the same time (notice on the timestamps), but are still being separated by a line.

Please let me know if I can provide more information that would be any use. Your help is much appreciated!

The serial monitor outputs seemingly nonsensical data, with boxes suggesting it's receiving incomplete characters

Your crap code is outputting crap. Well, color me surprised.

  if (mySerial.available()) {
    Serial.write(mySerial.read());
    Serial.println(mySerial.read());
  }

Serial.available() does NOT return true or false. It returns the number of bytes available to be read. If there is one byte in the buffer, it is NOT OK to read two bytes.

The value returned by the read() method is, as you've proven, a char in an int. If you stored the value in a char, and then print()ed the stored char, I'm willing to be a box of donuts that you'd get better results.

(Sadly the picture doesn't want to embed- here's a link)
Monitor-Output-1 — ImgBB

No, that's a URL. THIS is a link:

Took me less than 0.1 seconds to click the link icon before pasting the URL.

Thanks for the response.

My bad for the URL, first time posting.

I modified the code to the following (is this what you were suggesting):

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  Serial.println("Goodnight moon!");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
}

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

The image linked below shows the new output, still nonsense.

is this what you were suggesting

Yes.

The image linked below shows the new output, still nonsense.

All I see is a blank screen. Probably caused by the proxy server I'm behind.

I wonder if the device is using inverted logic. Try adding true as the third argument to the SoftwareSerial constructor.

Or, if the default is true, make the 3rd argument false.

The picture linked before showed the serial monitor outputting the box icon on several individual lines, followed by a line with "y". This repeated.

Looks like default is false, so I changed it to true and received no characters.

Which rs232 pin do you have connected to arduino pin 10? i.e. do you have RX and TX the right way round?

How is the mode switch on your shield set?

Also, it’s not your issue, but it’s probably worth running Serial at a higher baud rate as you’re emitting more characters than you’re reading.

I have the shield output TX pin connected to pin 10, and the RX pin connected to pin 11. This is opposite to the pins I assign in my code, I assume it because the shield TX refers to the scale TX pin, which needs to be connected to the RX on Arduino? I assume if they were the wrong way around I wouldn't be receiving any data at all?

The switch is set to OFF on the shield when uploading code, and ON when monitoring incoming data.

If I run serial at a different rate to the scales will it not miss/double up on bit readings- leading to an incorrect reading on the serial monitor?

Thanks for the help btw

You should be able to run serial at a different speed without issue. Except, that it looks like when the switch is ON, the shield sends data to the hardware serial port, which you're trying to use to tell you what you're reading, so there may be conflict.

What happens if you run the sketch with the shield's switch off?

I’ve just tried with a different serial speed using the following code (I assume that’s correct, or do I need to change the software serial speed too?), and get even more random characters (now spreading across a number of lines):

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(19200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
}

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

With the shield ‘OFF’, I get nothing in the serial monitor.

I assumed that with the RX and TX lines, one can send and receive data simultaneously (although I’m not sending anything to the scales anyway).

I’ve just noticed that no matter if the scales are connected or not, I get the same reading in the monitor when the shield is powered ON. The shield ‘thinks’ there is incoming data from RS232. I’ve checked for shorts in the headers.

That shield seems like it's more trouble than it's worth - it looks from their (very basic) tutorial example that the thing is hard wired to the Arduino's serial port, which seems a little ...inconsiderate.

If you have one, I'd be inclined to use another arduino so that the one with the shield can read serial and push it out to the second over software serial. The receiver (also using software serial) can report what's being seen over hardware serial to your PC. At least that'll establish whether it's working.

Hmmm, not a great shield. To use it in this case, you should switch the run/program switch to "program" so that it doesn't interfere with the Serial comms to the PC.

But if you do that, the 5V TX and RX signals aren't available on any headers or jumpers on the board. (Or maybe I missed them on the schematic.)

Cut or bend pins 0 and 1 on the shield. Then put jumpers from those headers to your software serial pins. Put the switch in "run".

Thank you for the replies. Are the TX and RX headers not on the bottom right of the schematic (along with GND and VCC)? This image shows it with a green box around:

I’ll try hooking an extra Arduino up tomorrow.

I managed to get an oscilloscope on the shield TX header (the one highlighted in the schematic linked above), and found it to be running between -5 and -8V, I assume this should be between 0 to 5V for Arduino UART? If I’ve measured correctly this could suggest there’s a problem with the shield, rather than the way it’s hooked up. I’ve posted on the DFROBOT forum, hopefully they’ll confirm.

Oscilloscope image:

No, those headers are the +/-12V RS232 signals.

The negative voltage is expected for RS232.