sparkfun / Weather_Shield

Barometric pressure, temperature, humidity and light sensing weather shield for Arduino.
https://www.sparkfun.com/
Other
69 stars 67 forks source link

Error in Weather_Shield_Weather_Station.ino where "windspeedmph" reads "0.0" #24

Closed bboyho closed 8 years ago

bboyho commented 8 years ago

There have been customers reporting that the variable "windspeedmph" is constantly reporting "0.0". This is an error in the code Weather_Shield_Weather_Station.ino [ https://github.com/sparkfun/Weather_Shield/blob/master/firmware/Weather_Shield_Weather_Station/Weather_Shield_Weather_Station.ino ].

Looking at the sequence of code, it appears that whoever originally wrote the code did not update the global variable windspeedmph for the printWeather() function. Line 226 was commented out in calcWeather() because the function _get_windspeed() was already called in the loop function. The value was saved in the local variable called currentSpeed on line 178:

//Calc the wind speed and direction every second for 120 second to get 2 minute average
float currentSpeed = get_wind_speed();
.
.
.

By saving the value from currentSpeed to the global variable, the global variable windspeedmph was able to update and display a value other than "0.0":

//Calc the wind speed and direction every second for 120 second to get 2 minute average
float currentSpeed = get_wind_speed();
windspeedmph = currentSpeed;//update global variable for windspeed when using the printWeather() function
.
.
.

Verifying windspeedmph

You can verify that the value is correct by uncommenting out lines 356-358 and removing "/" and "/":

/* Serial.println();
Serial.print("Windspeed:");
Serial.println(windSpeed);*/

Keep in mind that the the value printed in calcWeather() outputs to the nearest hundredth while printWeather() outputs to the nearest tenth. This is due to the way serial.print() is called [ https://www.arduino.cc/en/Serial/Print ] . The default has the Arduino print to two decimal places. In printWeather(), the code specifies printing to the one decimal place.

bboyho commented 8 years ago

Issue fixed in forked commit => https://github.com/bboyho/Weather_Shield/commit/cb2b3dee3dc1f11ecff50dbc76434f29dbfc3372

ToniCorinne commented 8 years ago

Fixed - closing the issue.