Anemometer ESp32 Interrupt

ea6dx_esp32
Posts: 1
Joined: Mon Nov 11, 2019 4:19 pm

Anemometer ESp32 Interrupt

Postby ea6dx_esp32 » Mon Nov 11, 2019 4:29 pm

Hi all , i just try to port an Arduido code to ESP32 , the issue is that in a single turn of the anemometer my counter read 63 , how i can fix that ??? The anemometer use a magnetic sensor. and i have added a a resistor 10K and Capacitor of 100nf , i try in a arduino-uno board and works great , but no on a ESP32 . I can not read the Voltage anemometers due it works with a magnetic sensor,.
Thanks you

Code: Select all

// Pin definitions
# define Hall sensor 2         //  pin 2 ESP32 ( Carefull  to when Writting the ESP32 need to unplug that PIN , because is used internally in the boot)

// Constants definitions
const float pi = 3.14159265;           // Pi Number
int period = 5000;               // Interval of time analized(miliseconds)
int delaytime = 2000;             // Time between samples (miliseconds)
int radius = 90;      // Radio from the center to end of CUP in mm
// Variable definitions
unsigned int Sample = 0;   // Sample number
unsigned int counter = 0; // magnet counter for sensor
unsigned int RPM = 0;          // Revolutions per minute
float speedwind = 0;         // Wind speed (m/s)
float windspeed = 0;           // Wind speed (km/h)



void setup()
{
  // Set the pins
  pinMode(2, INPUT);
  digitalWrite(2, HIGH);     //internall pull-up active

     
  //Start serial
  Serial.begin(9600);       // sets the serial port to 9600 baud
  }

void loop()
{
  Sample++;
  Serial.print(Sample);
  Serial.print(": Start measurement...");
  windvelocity();
  Serial.println("   finished.");
  Serial.print("Counter: ");
  Serial.print(counter);
  Serial.print(";  RPM: ");
  RPMcalc();
  Serial.print(RPM);
  Serial.print(";  Wind speed: ");
 
//*****************************************************************
//print m/s 
  WindSpeed();
  Serial.print(windspeed);
  Serial.print(" [m/s] ");             
 
//*****************************************************************
//print km/h 
  SpeedWind();
  Serial.print(speedwind);
  Serial.print(" [km/h] "); 
  Serial.println();
  delay(delaytime);                        //delay between prints
}



// Measure wind speed
void windvelocity(){
  speedwind = 0;
  windspeed = 0;
  counter = 0; 
  attachInterrupt(digitalPinToInterrupt(2),addcount, RISING);
  unsigned long millis();       
  long startTime = millis();
  while(millis() < startTime + period) {
      
  }
}


void RPMcalc(){
  RPM=((counter)*60)/(period/1000);  // Calculate revolutions per minute (RPM)
}

void WindSpeed(){
  windspeed = ((4 * pi * radius * RPM)/60) / 1000;  // Calculate wind speed on m/s
 
}

void SpeedWind(){
  speedwind = (((4 * pi * radius * RPM)/60) / 1000)*3.6;  // Calculate wind speed on km/h
 
}

void addcount(){
  counter++;
} 


tommeyers
Posts: 184
Joined: Tue Apr 17, 2018 1:51 pm
Location: Santiago, Dominican Republic

Re: Anemometer ESp32 Interrupt

Postby tommeyers » Tue Nov 12, 2019 8:29 pm

Your problem is a very common problem: Bounce.

With a scope you will see it

In your code you will experience it

There are a lot of posts here and other locations; Google: "Key Bounce"

Tom Meyers
IT Professional, Maker
Santiago, Dominican Republic

tommeyers
Posts: 184
Joined: Tue Apr 17, 2018 1:51 pm
Location: Santiago, Dominican Republic

Re: Anemometer ESp32 Interrupt

Postby tommeyers » Tue Nov 12, 2019 8:36 pm

I was curious about maybe using a 555 and found this:

https://www.element14.com/community/com ... -debouncer

It has other helpful data.

Tom Meyers
IT Professional, Maker
Santiago, Dominican Republic

Who is online

Users browsing this forum: No registered users and 62 guests