calcul vitesse anémomètre - interruptions ESP8266

Bonjour,

J'ai une station météo qui fonctionne sur la base d'une arduino pro mini + NRF24L01+

L'émetteur est sur le toit, le récepteur (Wemos D1 Pro mini+ NRF24L01+) dans la maison.

Je voudrais tester cette station météo directement sur la Wemos D1 pro mini mais je n'arrive pas à comprendre comment fonctionne l'interruption sur cette carte et comment mettre en place un timer de 2.5 s.

Avec TimerOne, la commande : Timer1.initialize(500000); met en place un timer de 0.5 s et la routine isr_timer déclenche le calcul de vitesse toutes les 2.5 s (0.5 x 5 = 2.5).

Pouvez-vous m'aider pour ce calcul ?

Merci.

Ci dessous code qui fonctionne sur Arduino Pro mini :

//Capteur anémomètre-Girouette DAVIS
//Inspiré du site ci dessous
//http://cactus.io/hookups/weather/anemometer/davis/hookup-arduino-to-davis-anemometer-software
//Modifié par JMD car oubli ligne 39 "  attachInterrupt(digitalPinToInterrupt(WindSensorPin), isr_rotation, FALLING);"
//Plus quelques adaptations perso...

#include "TimerOne.h" // Timer Interrupt set to 2 second for read sensors 
#include <math.h>

#define WindSensorPin (2) // The pin location of the anemometer sensor 
#define WindVanePin (A1) // The pin the wind vane sensor is connected to 
#define VaneOffset 0; // define the anemometer offset from magnetic north 

int VaneValue; // raw analog value from wind vane
int Direction; // translated 0 - 360 direction
int CalDirection; // converted value with offset applied
int LastValue; // last direction value

char *sectors[ ] = {"N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW", "N"};
String compassDir = "";

volatile bool IsSampleRequired; // this is set true every 2.5s. Get wind speed
volatile unsigned int TimerCount; // used to determine 2.5sec timer count
volatile unsigned long rotations; // cup rotation counter used in interrupt routine
volatile unsigned long ContactBounceTime; // Timer to avoid contact bounce in isr

float WindSpeed; // speed miles per hour

void setup() {

  LastValue = 0;

  IsSampleRequired = false;

  TimerCount = 0;
  rotations = 0; // Set Rotations to 0 ready for calculations

  Serial.begin(115200);

  pinMode(WindSensorPin, INPUT);
  attachInterrupt(digitalPinToInterrupt(WindSensorPin), isr_rotation, FALLING);
  Serial.println("Davis Anemometer Test");
  Serial.println("Speed (MPH)\tKilometers\tDirection\tStrength");

  // Setup the timer interupt
  Timer1.initialize(500000);// Timer interrupt every 2.5 seconds
  Timer1.attachInterrupt(isr_timer);
}

void loop() {

  getWindDirection();

  // Only update the display if change greater than 5 degrees.
  if (abs(CalDirection - LastValue) > 5) {
    LastValue = CalDirection;
  }

  if (IsSampleRequired) {
    // convert to mp/h using the formula V=P(2.25/T)for Davis Anemometer 
    // V = P(2.25/2.5) = P * 0.9
    WindSpeed = rotations * 0.9;
    rotations = 0; // Reset count for next sample

    IsSampleRequired = false;

    Serial.print(WindSpeed); Serial.print("\t\t");
    //Serial.print(getKnots(WindSpeed)); Serial.print("\t");
    Serial.print(getKilometers(WindSpeed)); Serial.print("\t");
    Serial.print(CalDirection);
    getHeading(CalDirection); Serial.print("\t");
    Serial.print(compassDir); Serial.print("\t\t");
    getWindStrength(WindSpeed);
  }
}

// isr handler for timer interrupt
void isr_timer() {

  TimerCount++;

  if (TimerCount == 5)
  {
    IsSampleRequired = true;
    TimerCount = 0;
  }
}

// This is the function that the interrupt calls to increment the rotation count
void isr_rotation() {

  if ((millis() - ContactBounceTime) > 15 ) { // debounce the switch contact.
    rotations++;
    ContactBounceTime = millis();
  }
}

// Convert MPH to Knots
float getKnots(float speed) {
  return speed * 0.868976;
}

// Convert MPH to Km/h
float getKilometers(float speed) {
  return speed * 1.60934;
}

// Get Wind Direction
void getWindDirection() {

  VaneValue = analogRead(WindVanePin);
  Direction = map(VaneValue, 0, 1023, 0, 359);
  CalDirection = Direction + VaneOffset;

  if (CalDirection > 360)
    CalDirection = CalDirection - 360;

  if (CalDirection < 0)
    CalDirection = CalDirection + 360;

}
void getHeading(int direction) {
  int index = CalDirection % 360;//modulo
  index = round(index / 22.5);
  compassDir = (sectors[index]);
}


// converts wind speed to wind strength
void getWindStrength(float speed) {

  if (speed < 2)
    Serial.println("Calm");
  else if (speed >= 2 && speed < 4)
    Serial.println("Light Air");
  else if (speed >= 4 && speed < 8)
    Serial.println("Light Breeze");
  else if (speed >= 8 && speed < 13)
    Serial.println("Gentle Breeze");
  else if (speed >= 13 && speed < 18)
    Serial.println("Moderate Breeze");
  else if (speed >= 18 && speed < 25)
    Serial.println("Fresh Breeze");
  else if (speed >= 25 && speed < 31)
    Serial.println("Strong Breeze");
  else if (speed >= 31 && speed < 39)
    Serial.println("Near Gale");
  else
    Serial.println("RUN");
}