Sparkfun Anemometer sensor reading

Hi

I want to read the wind speed from my sparkfun wind speed sensor the sensor only read’s wind speed greater than 2,4km/h . Please advise on the error that I might have done as I am struggling to compile on MBED OS :

#include “mbed.h”

DigitalIn Anemometer(PB_10); // Digital in API for Digital Anemometer
Ticker Anemometer_Interrupt; //Ticker API intrrupt to create interrupt at set interval time
int Anemometer_din_current = 0, Anemometer_din_old = 0; //Digital input is read as interger value - create variable to store and process the Anenometer integer value
float Anemometer_Speed = 2400;

void Anemometer_Interrupt_handler(){ //create the code that will run when the Ticker API interrupt the CPU at the set interval
Anemometer_din_current = Anemometer; //Read the Anemometer Digital input and store its value in the variable
if(Anemometer_din_current!=Anemometer_din_old) //Check to see if the Anemometer integer value is different from previous the stored value
float get_windspeed() {
float s;
Anemometer_din_old speed = 2400; // Local Variable value
speed *= Anemometer_Speed;
speed /= 1000 ; // To give value in km/h
Anemometer_Speed = 0 ;
}
}

int main (){

      Anemometer_Interrupt.attach(&Anemometer_Interrupt_handler,2000ms); //Ticker interrupt initialised to interrupt the CPU every 2 seconds

    

while(true) { 
printf("Windspeed: %3.2d\r\n",Anemometer_din_current); //Displays interger value read from Anemometer Digital input
    ThisThread::sleep_for(500ms);   //Put the main task into a 500 ms sleep - it does not get executed fro 500ms.
    }

}

Hello again,

void Anemometer_Interrupt_handler(){ //create the code that will run when the Ticker API interrupt the CPU at the set interval
Anemometer_din_current = Anemometer; //Read the Anemometer Digital input and store its value in the variable
if(Anemometer_din_current!=Anemometer_din_old) //Check to see if the Anemometer integer value is different from previous the stored value
float get_windspeed() {
float s;
Anemometer_din_old speed = 2400; // Local Variable value
speed *= Anemometer_Speed;
speed /= 1000 ; // To give value in km/h
Anemometer_Speed = 0 ;
}
}

This not seems to be a valid function, it looks like a mess, one function in another incomplete function.

BR, Jan

So how should it look please advise whom can assist ?

thanks

I do not know your source of this. From my point of view you are trying for a code like is in this library - WeatherMeters - Weather Meters (Sparkfun) http://mbed.org/users/… | Mbed

However, we already discussed about it

BR, Jan

Good evening

I am trying to create my own code with own library to read the anemometer as the sample code is incorrect in the link .

Regards

Sorry, but why do you think that? How I said many times before not working / is incorrect is no reason, there must be a real reason for that.

You are using this sparkfun shield right?
So try this - Sparkfun_Weather_Meter - Sparkfun’s Weather Meter demo | Mbed

BR, Jan

Hello

Would like to know as to what can be wrong as I get the below Serial output .

Wind Direction is 0
Wind Direction is %4.2f
Wind Direction is 0
Wind Direction is %4.2f
Wind Direction is 0
Wind Direction is %4.2f
Wind Direction is 0
Wind Direction is %4.2f
Wind Direction is 0
Wind Direction is %4.2f

++ MbedOS Error Info ++
Error Status: 0x80010133 Code: 307 Module: 1
Error Message: Mutex: 0x20000564, Not allowed in ISR context
Location: 0x8008451
Error Value: 0x20000564
Current Thread: rtx_idle Id: 0x20001AC4 Entry: 0x80062DD StackSize: 0x280 StackMem: 0x20001B90 SP: 0x2001FEA4
For more info, visit: mbedos-error
– MbedOS Error Info –

Regards

Hello,

In default the printing floats is disabled in the Mbed OS. You need change project configuration via mbed_app.json file (edit an existing one or create a new one in the root of the project). It could look like here - mbed_app.json example

MbedOS crashed because you probably use printf or any read/write method inside of interrupt. These methods are covered by Mutex so it is not possible to do that like that.
You can change project configuration (same as above) to bare metal profile (No RTOS = no Mutex = no crash) or you need change your code.

BR, Jan