SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By xdomingo
#175033
Hi:
I'm just setting a Meteo Station folowing "official" tutotial.
https://learn.sparkfun.com/tutorials/we ... nderground

I just bough a
Weather Shield DEV-12081
and
Weather Meters SEN-08942
and additional components and I mounted them.
I burn in my Arduino R3 the firmware from
https://github.com/sparkfun/Weather_Shi ... Shield.ino

I can read all data from serial port from my PC ( rain Gauge and wind direction) but no data about Wind Speed is showed, an "nan" value appears in WindSpeedMhp value. All connections and solder parts seems to be ok.

I need to know what is the correct way in order discover where is the problem and how to determine if any part is defective or wasted.

Thanks in advance and best regards.
By Mee_n_Mac
#175090
My guess is that you're getting "Not a Number" results because there are no clicks coming in from the wind speed device. If you look at this snippet of code ;
Code: Select all
//Returns the instataneous wind speed
float get_wind_speed()
{
float deltaTime = millis() - lastWindCheck; //750ms
deltaTime /= 1000.0; //Covert to seconds
float windSpeed = (float)windClicks / deltaTime; //3 / 0.750s = 4
windClicks = 0; //Reset and start watching for new wind
lastWindCheck = millis();
windSpeed *= 1.492; //4 * 1.492 = 5.968MPH
/* Serial.println();
Serial.print("Windspeed:");
Serial.println(windSpeed);*/
return(windSpeed);
}
... if deltaTime is 0 then you'll try to divide by zero to calculate windSpeed, a sure fire way to get a NaN.
According to this snippet ;
Code: Select all
void wspeedIRQ()
// Activated by the magnet in the anemometer (2 ticks per rotation), attached to input D3
{
if (millis() - lastWindIRQ > 10) // Ignore switch-bounce glitches less than 10ms (142MPH max reading) after the reed switch closes
{
lastWindIRQ = millis(); //Grab the current time
windClicks++; //There is 1.492MPH for each click per second.
}
}
... the clicks or ticks come in on digital pin 3. You might want to check wiring to/from that pin. If you have a voltmeter you should be able to slowly rotate the anemometer and see a voltage change 2 times each revolution.
By xdomingo
#175523
Well, it seems that something is not clear in the code.
Making test you can see (below) that everytime windspeedmph, windgustmph, windgustdir is nan or 0 but windspdmph_avg2m is correct.
Shound I rewrite the code of the firmware?

Best regards.

$,winddir=180,windspeedmph=nan,windgustmph=0.0,windgustdir=0,windspdmph_avg2m=13.2,winddir_avg2m=178,windgustmph_10m=31.2,windgustdir_10m=270,humidity=62.6,tempf=75.0,rainin=0.01,dailyrainin=0.01,pressure=101490.25,batt_lvl=4.18,light_lvl=0.09,#
By Valen
#175578
xdomingo wrote:Well, it seems that something is not clear in the code.
Making test you can see (below) that everytime windspeedmph, windgustmph, windgustdir is nan or 0 but windspdmph_avg2m is correct.
Shound I rewrite the code of the firmware?
...
If you want to rewrite the code then you must first know what needs to change. What would you like to change to the code?

Have you verified that the windspeed measurement pulses from the magnetic switch are correctly detected? Does the calculated average windspeed match with a forced turnrate that you applied to it? Just because a number comes out doesn't mean that it is the correct value.
By D_Heidner
#176148
There is an error in the code that is posted on the github.

The function get_wind_speed, is called twice in the code. Once to obtain the current wind speed for the averages and the second time for value of windspeedmph.

The problem is that the function is being called TWICE within less than 1 millisecond, no clock ticks pass. The clock tick value is a global variable "lastWindCheck"

You can see the problem if you enable the debug trail in the get_wind_speed function by un-commenting the following section. You will see a correct wind speed displayed, then when the second call results in a divide by zero error, the "nan" results.

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

An easy fix is to simply change the reference to the second function call to the prior currentSpeed value:

//Calc windspeed
/*windspeedmph = get_wind_speed();*/
windspeedmph = currentSpeed;

currentSpeed should at the beginning of the sketch with the other global variables.( roughly lines 55-60) This also means that you will need to change the declaration for currentSpeed (around line 190). (This note for the global variable added 2014-11-03)

There are other errors in the code, if the GPS is installed - the simple serial print.. has lattitude and longitude both labeled as "lat". The GPS altitude is also not returned by the TinyGPS++ library, the cause of this is I believe a buffer overflow when reading from the gps.
Last edited by D_Heidner on Mon Nov 03, 2014 7:23 pm, edited 1 time in total.
By burt46
#176520
I have the same problem with nan values for the wind speed. My averages just accumulate and are false.

D_Heidner - I get a 'currentSpeed' not declared in this scope. Where should it be declared?

Thanks
Burt
User avatar
By Ross Robotics
#176538
Are you using the code from the first post from Github? It's declared on line 173.
By Tirant
#177453
Hello. I don't quite understand which lines need to be corrected. The previous posts are quite unclear to me. I am using the code from GitHub. Please tell me what exactly needs to be done to the code in order to get the windspeedmeter work.

Uncommenting the following lines

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

shows me some values, but I want the "windspeedmph" to work in the Serial Monitor.
User avatar
By bboyho
#191271
Just for future reference, a customer recently reported an issue with the code and I was able to remedy the issues that "D_Heidner" pointed out in this forum post. The issues had to do with the Weather Station outputting "windspeedmph=0.0" [ https://github.com/sparkfun/Weather_Shield/issues/24 ] and the GPS Example Code not displaying one of the variables as longitude [ https://github.com/sparkfun/Weather_Shield/issues/23 ]. The NaN error seems to have been corrected in a previous fix in the GitHub repository => [ https://github.com/sparkfun/Weather_Shi ... -139683094 ] .