Problem on Arduino Uno serial communication

I’m a beginner in arduino and i have a problem to get the output data.
The project that i’ve been doing is to transfer the data from detector to arduino and display the output through serial monitor using RS232. I’ve used the RS232 shield to connect the detector and arduino.
if i connect the detector directly to PC, i got the output exactly like the data shown on the detector. but when arduino is connected inbetween detector and PC, the output is as below:

Left column is the output that i get while the right column is the output that i want to get.

#include <SoftwareSerial.h>

SoftwareSerial mySerial(5,6); 
int incomingData = 0; 

void setup() 
{
 Serial.begin(2400);
 mySerial.begin(2400);
}

void loop() 
{
  if(mySerial.available() > 0) 
  {
  incomingData = mySerial.read();
  Serial.println(incomingData); 
  }
  
}

How can i get the output exactly like the one displayed on detector

What baud rate do you have set in the serial monitor?

thank you for your response. i used 2400 baudrate.

Can you explain what your table means? I don’t understand what it is telling us.

The project that i’ve been doing is to transfer the data from detector to arduino and display the output through serial monitor using RS232. I’ve used the RS232 shield to connect the detector and arduino.

What detector? Part number? Link? What RS232 shield? Link?

we use LUDLUM AREA MONITOR MODEL 375 as detector (http://www.ludlums.com/multisites/medphys/images/stories/product_manuals/M375_&_M375slash2_&_M375slash4_&_M375-Series-One.pdf)

RS232 shield (http://www.dfrobot.com/wiki/index.php/RS232_Shield)

Based on my project, the output on Serial Monitor was supposed to display the same reading on the detector which is LUDLUM MOEDEL 375. What I’m trying to say is that when I connected the detector to arduino and to PC using RS232, I did not get the same output as the detector. The output that I received was on the left column of the table (i.e 246 246 246 54 187 159 159 159 159 157 159 229 135).

However, when I directly connect the detector to PC still using RS232 without arduino, I manage to get the same output as the detector, which is represented as the values in the right column of the table (0000.4000010).

Based on the table, 246 represents 0, 54 represents ‘.’, 235 represents 1, 187 represents 4 and so on and so forth.

Thus, I was wondering how could I get the same output as the detector? Is there any coding that I should add/know in order to get the same output?

below is the reference for the table before.

|500x239

The problem could be arising for one of two reasons. The Arduino may not be receiving the data correctly OR the Arduino may not be sending the data correctly to the PC.

Have you run any tests to ensure that the Arduino is receiving the data correctly. For example by displaying the raw data that is received on the Serial Monitor?

I wonder should this

Serial.println(incomingData);

be

Serial.print(incomingData);

If you intend the Arduino to do something with the data you will probably need a more sophisticated system for receiving the data. Have a look at the examples in serial input basics

...R

@Robin2:

The Arduino may not be receiving the data correctly OR the Arduino may not be sending the data correctly to the PC.

I was thinking the same thing but I could not figure out why or how to get the correct data.

Yes, I have tested using simple experiments, such as the LED will turn on and it will display text on the Serial Monitor, display data by controlling from potentiometer, display output sensor, etc.

I have tried both methods Serial.println(incomingData); and Serial.print(incomingData); Well, correct me if I’m wrong but if using Serial.print I suppose I must parse the end line because otherwise it will appear on the same line as the previous data.

Once I’m able to display the data correctly, I have to do some mathematical formula to calculate its moving average.

you will probably need a more sophisticated system for receiving the data

What do you mean by more sophisticated system? Do I need to add external circuitry?

True RS232 protocol ( +- 15 v bipolar signalling) is seldom used. The spec just state "it dumps x bytes of data every x seconds." Find out if the data is 0 = low = ground and 1 = +5V = high or something else. The PC (COM) interface and your RS232 shield MAY not use SAME levels. Verify if your protocol , not just baud rate(!) matches what the device is sending - stop bits, parity etc.

You MAY need a level converter which are commercially available.

With no transfer going on, what voltage level do you see on the Rx & Tx lines?

@CrossRoads

voltage level on RX & TX line is 1.9V and -8.7V respectively

This is the faulty code!

  incomingData = mySerial.read();
  Serial.println(incomingData);

println() converts the value to an ascii string. so a byte with 0 in it will be converted to '0' or decimal 40?

If you use read on the input side then use write on the output.

  incomingData = mySerial.read();
  Serial.write(incomingData);

Mark

@holmes4:

so a byte with 0 in it will be converted to ‘0’ or decimal 40?

It doesn’t return 0 nor 40. Instead it displays 246 according to table in post #1. However, if 0 is placed after decimal point, it returns 251.

  incomingData = mySerial.read();
  Serial.write(incomingData);

I’ve tried this code but it returns weird characters.

nasyitah:
@CrossRoads

voltage level on RX & TX line is 1.9V and -8.7V respectively

On the Arduino pin? You shouldn’t have -8.7 V there.

holmes4:
This is the faulty code!

  incomingData = mySerial.read();

Serial.println(incomingData);




println() converts the value to an ascii string. so a byte with 0 in it will be converted to '0' or decimal 40?

ASCII 4010 is a ‘(’

nasyitah: Yes, I have tested using simple experiments, such as the LED will turn on and it will display text on the Serial Monitor,

Am I correct to think that it displays the correct data on the Serial Monitor ?

If not you must get that to happen before you do anything else.

I have tried both methods Serial.println(incomingData); and Serial.print(incomingData); Well, correct me if I’m wrong but if using Serial.print I suppose I must parse the end line because otherwise it will appear on the same line as the previous data.

That is true if you use the Serial Monitor but it may not be true with your PC program.

If the device is not sending linefeeds to the Arduino then the Arduino should not be sending linefeeds to the PC.

Once I’m able to display the data correctly, I have to do some mathematical formula to calculate its moving average. What do you mean by more sophisticated system? Do I need to add external circuitry?

I just mean more sophisticated code - such as in serial input basics

...R