Reading RS232 output to Arduino

This is my first post, so please forgive any missed steps. I am about 1 year into Arduino programming, and have been reading topics here for that time.

I am starting a project that involves reading the output of a laboratory scale to an Arduino. Eventually the project will use an Arduino Giga, but I wanted to start small and am using a Nano for bench testing to confirm that I can read the serial data. I have been reading threads for several days and the closest that I came to my topic was how to get weight form Weight Scale and ek 300i. This topic used a very similar scale to the one I am using, which is an A&D FX-120i (https://weighing.andonline.com/sites/default/files/documents/FX-i%20et%20FZ-i%20Manuel%20Francais.pdf).

After going through the electronics, I determined that I should be able to read the output directly from the DB9 connector on the scale to the Arduino, so it is wired with the Signal Ground (pin 5) from the DB9 to the Nano GND pin, and as I only need to read the data, the TXD pin (2) is wired to pin D6 on the Nano. I checked the printer setup, and it is set to 19200 Baud, and 8 bits w/no parity.

Here is the code that I am using, which I mostly copied from the other topic thread, but I am using SoftwareSerial to use additional pins on the Nano:

#include <SoftwareSerial.h>  // Include lbrary to do serial communications on alternate pins
SoftwareSerial scale(6, 7);  //(TXD, RXD)

const byte numChars = 32;
char receivedChars[numChars];
boolean newData = false;

void setup() {
  scale.begin(19200);

  Serial.begin(9600);
  Serial.println("<Arduino is ready>");
}

void loop() {
  recvWithEndMarker();
  showNewData();
}

void recvWithEndMarker() {
  static byte ndx = 0;
  char endMarker = '\n';
  char rc;

  while (scale.available() > 0 && newData == false) {
    rc = scale.read();
    Serial.print("Char received  ");  
    Serial.print((byte)rc);          
    Serial.println();                
    if (rc != endMarker) {
      receivedChars[ndx] = rc;
      ndx++;
      if (ndx >= numChars) {
        ndx = numChars - 1;
      }
    } else {
      receivedChars[ndx] = '\0';  
      ndx = 0;
      newData = true;
    }
  }
}

void showNewData() {
  if (newData == true) {
    Serial.print("This just in ... ");
    Serial.println(receivedChars);
    newData = false;
    delay(5000);
  }
}

When I run the program, I get the "", if the TXD line is not connected, if it is connected, nothing happens. If I connect the TXD pin after the program gives the "", I get the data set below:

Char received 191 Char received 113 Char received 99 Char received 229 Char received 235 Char received 0 Char received 86 Char received 213 Char received 90 Char received 237 Char received 246 Char received 214 Char received 150 Char received 182 Char received 54 Char received 107 Char received 151 Char received 191 Char received 113 Char received 99 Char received 229 >>>>Repeats indefinitely>>>>>>>

The scale is showing "132.92 gn" so based on the printer manual, I would expect to see data of "ST,00132.92 g" followed by a carriage return and a line feed (ASCII 0Dh and 0Ah respectively). I also never see the "This just in ... " text from the second subroutine.

Can someone explain what I need to do to get the data formatted into something I can use? Also, is there any need for the "showNewData()" subroutine?

Thanks for the help

The scale most likely uses RS232 voltage levels, which can range from -12V to 12V and destroy Arduino inputs.

You need an RS232 to UART level converter, like this one:

jremington, Thanks for your advice. I had some Max3232 units here, but measured 5v straight off of the scale output, so I assumed I didn't need it. I of course was wrong.

Here is the output that I am getting now:
Start
ST,+00132.98 GN
Test
ST,+00132.98 GN
Test
ST,+00132.98 GN
Test
ST,+00132.98 GN

Here is the program:

#include <SoftwareSerial.h>  
SoftwareSerial scale(6, 7);  
//float inByte = 0;
char inByte = 0;

void setup() {
  Serial.begin(9600);
  scale.begin(19200);
  Serial.println("Start");
}
void loop() {

  while (scale.available() > 0) {
    inByte = scale.read();
    Serial.print(inByte);
  }
  if (inByte > 0) {
    Serial.println("Test");
  }
  inByte = 0;
  delay(50);
}

The delay(50); time is critical to ensure you read a clean line of data. Now I just need to convert the ASCII text to a float and plow ahead.

Thanks for the help.

Glad it is working!

Note that RS232 voltage level swings can be between 0 to 5V, but the HIGH/LOW bits are also inverted with respect to TTL serial.

If you increase the Serial monitor baud rate below to a more reasonable value like 115200, you may not need the 50 ms delay.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.