Go Down

Topic: serial.print shows wrong float numbers (Read 921 times) previous topic - next topic

stoffel67

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?

pylon

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?

PeterH

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.
I only provide help via the forum - please do not contact me for private consultancy.

robtillaart

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?
Rob Tillaart

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

stoffel67

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.

robtillaart

#5
Feb 04, 2013, 06:42 pm Last Edit: Feb 04, 2013, 06:58 pm by robtillaart Reason: 1
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: [Select]

float pi=3.14159265;

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

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

void loop()
{
}
Rob Tillaart

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

UKHeliBob

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

robtillaart

Rob Tillaart

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

UKHeliBob

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.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

robtillaart

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
Rob Tillaart

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

stoffel67

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?


PaulS

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?

pylon

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?

vanja100

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

michinyon

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.

Go Up