Pages: [1]   Go Down
Author Topic: serial.print shows wrong float numbers  (Read 883 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,
I am new to Arduino.
I have a set up a project reading a MS5611 baro board.
Everthing works fine on my Win7 installation, but when i connect the board to XP I get bad output on my serial monitor
Win XP output:
Temp:142767.2 Altitude:-14628628.0m Normdruck: 316851.90 bei 135.00m
Win 7 output:
Temp:24.5 Altitude:103.4m Normdruck: 1006.6 bei 135.00m

floating point numbers are wrong, string is OK.
the connection Arduino to PC is done by cp210x usb-serial adapter.
Everthing is setup equal on XP and Win7.
Any idea what wrong here?
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 111
Posts: 5236
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Haven't seen your Arduino code yet.

From Win7 to XP do you just pull the USB connector out of the Win 7 machine and into the XP machine? Or do you have two separate setups, one connected to a Win 7 machine and the other one to a XP machine?
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Suggest you post your code, and also write a test sketch that just prints out hard-coded values similar to the ones you're seeing here. At the moment it's not clear whether the problem is the sketch printing rubbish, or the valid output being scrambled (somehow very selectively) before it reaches the PC. Neither seems likely, so you need to simplify the test system and eliminate some assumptions.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 221
Posts: 13846
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Temp:142767.2 Altitude:-14628628.0m Normdruck: 316851.90 bei 135.00m

Note: The arduino floating point has only 6 or 7 significant digits. check spec IEEE754. That means 10 digit numbers cannot be represented ...

It looks to me like it wants to read doubles which are 8 bytes where float are 4 bytes.

which terminal programs are you using?
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

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

I have attached my code.
I use a Arduino pro mini board, which is conneted to the PC by an CP210X USB2UART connector
I have installed the latest driver on both machines (WIN7 and WIN XP)
I use the Serial Monitor on both machines and I tried also with HTerm.exe (hyperterminal) which shows always the same,
on WIN7 everything is OK, on Win XP floating numbers are wrong.

* Baro_MS5611_V1.ino (4.82 KB - downloaded 6 times.)
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 221
Posts: 13846
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
on WIN7 everything is OK, on Win XP floating numbers are wrong.
Amazing!

- do you upload the sketch again or just connect the Arduino?
- which IDE version are on WIN7 / XP?

- Can you try this sketch on both machines? (just upload it once)
Code:
float pi=3.14159265;

void setup()
{
  Serial.begin(115200);

  for (int i = 0; i < 8; i++)
  {
    Serial.println(pi, i);
  }
  Serial.println();
}

void loop()
{
}
« Last Edit: February 04, 2013, 12:58:22 pm by robtillaart » Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 116
Posts: 4324
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Missing int in line 7 ?
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 221
Posts: 13846
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

fixed int,  smiley-red thank you smiley-wink
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 116
Posts: 4324
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No problem.  Nothing compared to some howlers that I have posted.
Luckily I had a spare int here so was able to run the code and I can confirm that it works as expected for me.
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 221
Posts: 13846
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I did not test it, just "spit out" the code in one stream, but thanks for confirming that it does what it should do.

These kind of minimal test sketches are useful when debugging the Arduino core
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

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

Thank you for your hints.
I took the above code into my sketch ( I put it into the "loop") compiled it on WIN XP:
I get these results:
3
3.1
3.14
3.142
3.1416
3.14159
3.141593
3.1415927
3.14159274

     TEMP= 142768.03     ALTITUDE= -14634452.00m     1-Normdruck=  318159.0    bei 135.00m




then I took the Arduino to WIN7:
first I got the same strange results....
3
3.1
3.14
3.142
3.1416
3.14159
3.141593
3.1415927
3.14159274

     TEMP= 142770.59     ALTITUDE= -14627349.00m     1-Normdruck=  316493.2    bei 135.00m
3
3.1
3.14
3.142
3.1416
3.14159
3.141593
3.1415927
3.14159274

     TEMP= 142770.70     ALTITUDE= -14626947.00m     1-Normdruck=  316399.8    bei 135.00m
3
3.1
3.14
3.142
3.1416
3.14159
3.141593
3.1415927
3.14159274

     TEMP= 20.11     ALTITUDE= 167.00m     1-Normdruck=  1009.5    bei 135.00m
3
3.1
3.14
3.142
3.1416
3.14159
3.141593
3.1415927
3.14159274

     TEMP= 20.22     ALTITUDE= 166.80m     1-Normdruck=  1009.5    bei 135.00m



but suddenly the serial out gave correct floating numbers
this is absolutly strange!
I did not compile the code again on WIN7
Could thes line be the problem
Serial.print(getAltitude(Pressure, Temperature));
maybe the output is the pointer to the function?

Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 631
Posts: 50165
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Could thes line be the problem
Serial.print(getAltitude(Pressure, Temperature));
maybe the output is the pointer to the function?
What does the getAltitude() function return? Does it make sense to be printing that without any prefix?
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 111
Posts: 5236
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I guess the print of a float is not the problem but the sensor is not working correctly on the XP machine. My guess is your XP machine is not delivering enough power to the USB for your circuit. Have you tried powering your Arduino with an external power supply?
Logged

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

I had the same problem some time back and seem to remember that this was a code problem to do with not using bitshifting. Has the code been posted? I would be surprised if it was a hardware problem .
Best
Vanja
Logged

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

I got this sort of rubbish from my BMP085,  which was working six month ago.
After a lot of mucking around,  I eventually came to the conclusion that I had
someone ruined the chip,  maybe connected 5V to it or something.
The communication was working but the measurements were rubbish.
Logged

Pages: [1]   Go Up
Jump to: