RS232 serial to Arduino data decoding

I am using RS232 female port to the machine who gives me 5 readings as output , I have connected Tx port to 12th pin of arduino uno and Rx port to 13th port of arduino uno and add GND connection
I have received the Output HEX format by - Serial2.print(Serial1.read(),HEX); line and output is like -
80 00 80 00 78 00 78 80 78 80 00 80 00 80 F8 00 80 80 78 00...... and so on,
I need the readings which is shown on the screen of that machine which are : 4.5, 0.01,100.0 etc
also if i change this - Serial2.print(Serial1.read(),HEX); and convert in char() still the output is -
??////////??//?????*///////

please help me to get it done with axact output showing on screen

Thanks in advanced,

Welcome to the forum

Why did you post in the Uncategorised category of the forum when its title says

:warning: DO NOT CREATE TOPICS IN THIS CATEGORY :warning:

Your topic has been moved to a more appropriate category

Do you have an RS232 to TTL adapter between the device and the Arduino ?

actually the machine has male RS232 port and i have attached RS232 to TTL Serial Interface Module

Then check the baud rate of your port.

I set the baud-rate 9600 for the first time and got the data which is in HEX format after that i have tried and test with different baud-rate below 9600 it gives me the data which was not in proper format and if i have set baud-rate above 21000 then data shows only 00000000000000000 or null(no data),
I need the output as readings shown in that machine display

If it worked at 9600 baud then why did you change it, particularly to a lower baud rate ?

If you don't want the data in HEX format then remove the HEX specifier from the print statement

I assume that you realise that both ends of the serial link need to be set to use the same baud rate

I assume that you realise that both ends of the serial link need to be set to use the same baud rate - Yes
I have received data with HEX :
78
80
0
80
0
80
0
...... So on
and Without HEX - 01921200128012802481280128012801280128012801280128012..... So on

Readings are shown in machines are - FAT - 0.04, SNF - 0.0, Density - 0.00, Added Water - 100, protien - 0.00

the output showing is something like this and i got the output in - 01921200128012802481280128012801280128012801280128012..... So on

Please post your sketch, using < CODE/ > tags when you do

Do you have a data sheet for the machine that is sending the data and does it describe the format of the data that it outputs ? What machine is it ? Link ?

I have used below code :

#include <SoftwareSerial.h>

SoftwareSerial mySerial(12, 13);  // RX, TX
void setup()
{
    Serial.begin(9600);    // open serial port for debugging
    mySerial.begin(9600);  // open software serial port for RS232 device
}

void loop()
{
    if (mySerial.available())
    {
        Serial.println(mySerial.read());  // read data from RS232 device and output to serial monitor
    }
}

MOD edit - added code tags


this is milk analyser machine showing the readings as data i need to just decode it when i received it in arduino uno

I have Auto formatted your sketch in the IDE and added the code tags as you ignored the advice to use them

Can you provide a link to it or better still to its data sheet ?

I have check with your code and the output is -
128128120128120120012001280128248128128012801280128012801280128012801280128120128120128120...... and so on

i dont have the data sheet

I did not change your code, I simply reformatted it to make it easier to read

Is the analyser set up to print data or to pass it to the Milk Data 2001 software on the PC ?

Is the analyser set up to print data or to pass it to the Milk Data 2001 software on the PC ?
yes its set up to print the data there is one app which is used to take the data from serial port with wired connection

When you have the analyser set to print rather than pass data to an app does it use a printer that is part of the system or a generic printer ?

The output that you have posted does not appear to hold structured data

its generic printer this machine is also supported for mairy dairy app
i have try the -

#include <SoftwareSerial.h>

SoftwareSerial mySerial(12, 13);  // RX, TX
void setup()
{
    Serial.begin(2400);    // open serial port for debugging
    mySerial.begin(2400);  // open software serial port for RS232 device
}

void loop()
{
if(mySerial.available()>0){
Serial.print((char)mySerial.read());
}
    
}

---------- and the output is redundant-
(00300000000099990000000010029)(00300000000099990000000010029)(00300000000099990000000010029)(00300000000099990000000010029)

i have change the baud-rate at 2400

Assuming that it prints correctly when you use the printer, what baud rate is the printer set to ?

I note that once again you did not use code tags when posting your sketch. Please edit the post, select the sketch and click on < CODE/ > above the edit window to add the code tags before saving your post

I have set the baud-rate 2400 and my code is below:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(12, 13);  // RX, TX
void setup()
{
    Serial.begin(2400);    // open serial port for debugging
    mySerial.begin(2400);  // open software serial port for RS232 device
}

void loop() {
  if (mySerial.available()) { // Check if there is data available
    String data = mySerial.readStringUntil('\n'); // Read the data until a newline character is encountered
    String temp = ""; // Temporary variable to store the digits
    int count = 0; // Counter to keep track of the number of digits read
    for (int i = 0; i < data.length(); i++) {
      char c = data.charAt(i);
      if (isdigit(c)) { // Check if the character is a digit
        temp += c; // Add the digit to the temporary variable
        count++; // Increment the counter
        if (count == 5) { // If we have read 5 digits, it means we have a complete value
          float value = temp.toFloat()*100 / 100.0; // Convert the string to a floating-point value and divide by 100 to get the actual value
          Serial.print(value, 2); // Print the value with 2 decimal places
          if (i < data.length() - 1) { // If this is not the last value, print a comma
            Serial.print(", ");
          }
          temp = ""; // Reset the temporary variable
          count = 0; // Reset the counter
        }
      }
    }
    Serial.println(); // Print a newline character at the end of the line
  }
}

showing the output which is quite similar but still its showing all reading as 0.00
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,

actual output is - 0.00, 0.0, 0.00, 100, 0.00

Simplifying things, but if you use your code from post #11 with the baud rate set to 2400, do you see anything that looks like the expected output being displayed?