Good Day
I would like to know the reason I am receiving 0 values the hardware is good , have tested the sensor with a multimeter and am getting the desired output the wiring is 100% and have tested each and every cable it an analog signal and am using the Nucleo F446RE Pin PA_1 but getting ) value all the time , connected it as per below
Output :
Wind Direction is 0
Wind Direction is 0.00
Code as per below :
#include “mbed.h”
AnalogIn Wind_vane(PA_1); //Analog in API for analog vane input connected to port pin PA1
Ticker Vane_Interrupt; //Ticker API intrrupt to create interrupt at set interval time
int Vane_ain_current = 0, Vane_ain_old = 0; //Analog input is read as interger value - create variable to store and process the vane integer value
float Vane_angle = 0; //The vane angle is floating point data type =- create variable
void Vane_Interrupt_handler(){ //create the code that will run when the Ticker API interrupt the CPU at the set interval
Vane_ain_current = Wind_vane; //Read the vane analog input and store its value in the variable
if(Vane_ain_current!=Vane_ain_old) //Check to see if the current vane integer value is different from previous the stored value
{switch(Vane_ain_current){ //Use a switch case structure to assign vane angle value according to the read vane integer vaue
case 3300: Vane_angle = 0.0; //vane integer value read is 3300, therefore write the vane angle 0.0 into the variable
case 6570: Vane_angle = 22.5; //repeat the cases for all vane interger values
case 8200: Vane_angle = 45.0;
case 891: Vane_angle = 67.5;
case 1000: Vane_angle = 90.0;
case 688: Vane_angle = 112.5;
case 2200: Vane_angle = 135.0;
case 1410: Vane_angle = 157.5;
case 3900: Vane_angle = 180.0;
case 3140: Vane_angle = 202.5;
case 16000: Vane_angle = 225.0;
case 14120: Vane_angle = 247.5;
case 120000: Vane_angle = 270.0;
case 42120: Vane_angle = 292.5;
case 64900: Vane_angle = 315.0;
case 21880: Vane_angle = 337.5;
default: Vane_angle = 0.0; //If read vae integer valuse is not one of the above cases, make the vane angle 0.0 as a default value
}}
}
int main (){
Vane_Interrupt.attach(&Vane_Interrupt_handler,2000ms); //Ticker interrupt initialised to interrupt the CPU every 2 seconds
while(true) {
printf("Wind Direction is %6d\n", Vane_ain_current); //Displays interger value read from vane analog input
printf("Wind Direction is %4.2f\n",Vane_angle); //Displays vane angle as assign in witch case structure in the interrupt handler
ThisThread::sleep_for(500ms); //Put the main task into a 500 ms sleep - it does not get executed fro 500ms.
}
}