Serial (RS232) communication between a Digital Indicator and Arduino Uno

Hi,

I am working on a project about data acquisition using serial communication (RS232). Please see attached files for the setup, dacell, and the serial monitor result.

A load cell is connected to a DACELL digital indicator (also an amplifier) and this digital indicator is connected to Arduino through RS232 serial communication.

Here's the code:

#include <SoftwareSerial.h>
SoftwareSerial myserial(6, 7); //RX, TX

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

void loop() {
  if (myserial.available()) {
    Serial.write(myserial.read());
  }

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

Basically, I want to manipulate the data that I am reading and being printed in the serial monitor (if possible to remove "US", "NT", and "ST") and leave out the numbers only. Right now, I am using the serial monitor to check if the data being sent is the same as shown in the digital indicator. Later on, I will save these data in an Excel file (hopefully without that "US", "NT", and "ST" ).

Thank you.

Empty imported post

Read the tutorial serial input basics, it will teach you what you need.
Serial input basics

Removing the "US", "NT", and "ST" is known as parsing.

This is covered in example #5 of PerryBebbington's above link.

Hi,

I checked the examples and tried some of it. However, the examples were about receiving data coming from the serial monitor. In my case, the Arduino is the one receiving data coming from an external instrument (Digital indicator) and projecting it to the serial monitor. The data that I am getting is in this format "US, NT, +0011.98". I just want to remove the "US, NT," part and keep the data "+0011.98".

Or am I just missing something from the tutorial. Apologies if this thread becomes troublesome.

Thank you.

PerryBebbington:
Read the tutorial serial input basics, it will teach you what you need.
Serial input basics

If that data string ends with a line feed (it looks like it does) you could use the example #2 modified to use software serial to read it and the strtok() function (like in example #5) to parse.

Here is an example showing what I mean (line feed as the end marker).

// Robin2's Example 2 - Receive with an end-marker modified to work with software serial
// strtok() to parse the data.
// by groundfungus aka c. goulding

#include <SoftwareSerial.h>

SoftwareSerial ssPort(6, 7);

const byte numChars = 32;
char receivedChars[numChars];   // an array to store the received data

char *strings[5];
char *ptr = NULL;

boolean newData = false;

void setup()
{
   Serial.begin(9600);
   ssPort.begin(9600);
   Serial.println("<Arduino is ready>");
}

void loop()
{
   recvWithEndMarker();
   parseData();

}

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

   while (ssPort.available() > 0 && newData == false)
   {
      rc = ssPort.read();
      Serial.print(rc);
      if (rc != endMarker)
      {
         receivedChars[ndx] = rc;
         ndx++;
         if (ndx >= numChars)
         {
            ndx = numChars - 1;
         }
      }
      else
      {
         receivedChars[ndx] = '\0'; // terminate the string
         ndx = 0;
         newData = true;
      }
   }
}

void parseData()
{
   if (newData == true)
   {
      byte index = 0;
      ptr = strtok(receivedChars, ",");
      while (ptr != NULL)
      {
         strings[index] = ptr;
         index++;
         ptr = strtok(NULL, ",");
      }
      //Serial.println(index);
      // the separate pieces
      for (int n = 0; n < index; n++)
      {
         Serial.print("piece # ");
         Serial.print(n);
         Serial.print("  ");
         Serial.println(strings[n]);
      }
      Serial.print("\n the number as a string ");
      Serial.println(strings[2]);
      Serial.print("the number as a float data type ");
      float number = atof(strings[2]);
      Serial.println(number);
      newData = false;
   }
}

Or am I just missing something from the tutorial.

Probably missing that it gives general principals that apply to any serial data, the origin of the data is not important, what is important is understanding ways to manipulate it. I think GroundFungus has given you a good example.