Pages: [1]   Go Down
Author Topic: Unable to get Data from Serial Device using Arduino Mega  (Read 415 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am trying to read the data from a Ultra Sonic Fuel Sensor(the link).The Baud rate of this device is 9600.The device basically sends data at regular time intervals.I am able to read the output in the PC using Terminal software.Given below is a sample.

Eg:*XD,205B,00,0000,0031,0000,0000,null#

I am trying to connect this device to Arduino through serial port provided in the device and when I see the Serial Monitor,the output is not correct.Given below is the sample.

5320215115451166102572432302302432302302302302432303816623024323023023023024323023023023051822281141463

Quote
String incoming_char;      // Will hold the incoming character from the Serial Port.

void setup()
{
  //Initialize serial ports for communication.
  Serial.begin(9600);
  Serial1.begin(9600);
  Serial.println("Starting Communication with Fuel Sensor");
}
void loop()
{

 //If a character comes in from the cellular module...

  if(Serial1.available() >0)
  {
    incoming_char=String(Serial1.read());    // Get the character from the cellular serial port.
    Serial.print(incoming_char);  // Print the incoming character to the terminal.
  }
}
The Arduino is powered from USB and the Device from a 12V supply. The voltage levels from the device Tx-GND=-5.44V,Rx-GND=-8.22V.

I initially thought the the issue might be because of the voltage range and made a voltage divider circuit and fed Arduino the proportionate voltage.Even that is not working. So,what is the thing which is going wrong ?Please guide me.
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There is a problem with your arduino Mega. That voltage values are not right for sure.
Logged

Offline Offline
God Member
*****
Karma: 57
Posts: 941
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi baluvignesh

Code:
Serial.print(incoming_char);  // Print the incoming character to the terminal.

The comment here is wrong.  The print method treats each character in the String as a number and prints it in decimal format.

Try changing it to this:

Code:
if(Serial1.available() >0)
  {
    Serial.write(Serial1.read());
  }

This should print each character as a character.

Regards

Ray
Logged

Hackscribble.  Writing about making things.
arduino@hackscribble.com | www.hackscribble.com

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Hackscribble,

I tried your suggestion.

Now I am getting this .

5Ê—š3¦f9óææóææææóæ&¦æóææææóææææ3Rär’

I guess that this piece of string is getting converted to corresponding numbers in decimal format.  So,I will have to check now why I am getting this junk characters from the Serial.Any pointers ?
« Last Edit: July 01, 2014, 12:01:46 am by baluvignesh » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Luis,

Can you please elobrate ? .I read in some site that it is ok to have negative voltages.
Logged

Offline Offline
Faraday Member
**
Karma: 62
Posts: 3031
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Don't use a string with serial.read( ).

Serial.read( ) reads a single character.

Try reading the character and then sending to the serial monitor.

If that works,  then stick it into a char array.
Logged

Oregon, USA
Offline Offline
Edison Member
*
Karma: 68
Posts: 2264
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The output is probably RS232, which uses inverted logic and voltage levels that are totally incompatible with the Arduino. If so, you need an RS232-TTL converter, like this one: http://www.pololu.com/product/127
Logged

"It seems to run on some form of electricity"

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi jremington,
Thanks for your suggestion.That was the issue.Got a RS232-TTL converter and it worked.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you set your serial monitor to the correct baud? This happens to me when I open the serial port at 9800 and set the serial monitor to 115800 or something other than the port I have already opened to.
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You were using RS232 on TTL device? Glad your arduino is ok smiley
Logged

Pages: [1]   Go Up
Jump to: