Bonjour,
J'ai trouvé un sketch qui permet de lire le contact d'un anémomètre et d'écrire la vitesse du vent sur le moniteur série. Je voudrais plutôt indiquer la vitesse sur un afficheur LCD. Tout va bien tant que je ne met pas les renseignements concernant l'afficheur. Voici le sketch avec les infos pour l'afficheur en commentaires#include <LCD.h>
#include <LiquidCrystal.h>
#include <LiquidCrystal_I2C.h>
#include <math.h>
// Include Wire Library for I2C
#include <Wire.h>
// Include NewLiquidCrystal Library for I2C
#include <LiquidCrystal_I2C.h>
#define WindSensorPin (2) // The pin location of the anemometer sensor
volatile unsigned long Rotations; // cup rotation counter used in interrupt routine
volatile unsigned long ContactBounceTime; // Timer to avoid contact bounce in interrupt routine
float WindSpeed; // speed miles per hour
// Define LCD pinout
const int en = 2, rw = 1, rs = 0, d4 = 4, d5 = 5, d6 = 6, d7 = 7, bl = 3;
// Define I2C Address - change if required
const int i2c_addr = 0x27;//gros display
LiquidCrystal_I2C lcd(i2c_addr, en, rw, rs, d4, d5, d6, d7, bl, POSITIVE);
void setup() {
delay(10);
Serial.begin(9600);
lcd.begin(20, 4); // Set display type as 20 char, 4 rows
Wire.begin();
pinMode(WindSensorPin, INPUT);
attachInterrupt(digitalPinToInterrupt(WindSensorPin), isr_rotation, FALLING);
}
void loop()
{
//display on serial monitor
Serial.print(WindSpeed);
Serial.print(" Km/h");
Serial.print (" ");
Serial.print("Rotations ");
Serial.println(Rotations);
//display on LCD screen
//lcd.setCursor(5, 0);
//lcd.print("Anemometre");
//lcd.setCursor(8, 2);
//lcd.print(WindSpeed);
//lcd.print(" Km/h");
Rotations = 0; // Set Rotations count to 0 ready for calculations
sei(); // Enables interrupts
delay (3000); // Wait 3 seconds to average
cli(); // Disable interrupts
// convert to mp/h using the formula V=P(2.25/T)
// V = P(2.25/3) = P * 0.75
WindSpeed = Rotations * 0.75 * 2.75;
}
// 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();
}
}
hello
ce code signifie qu'un top de l'anémomètre est signalé au µ par un flanc descendant
cela veut dire aussi que lorsqu'il n'y a pas de flanc descendant, l'entrée doit etre au niveau haut
pour ce faire, il faut soit utiliser la résistance de pull up interne du µ
pinMode(WindSensorPin, INPUT_PULLUP);
soit mettre une résistance de pull up en hard
Pas réellement en fait. Elles sont bloquées pendant une centaine de ms environ et débloquées pendant 3s.
If you block interrupts and you write to serial, and the serial buffer gets full, what happens then?
Then IMHO the printf is waiting for the interrupt handler for the serial port to remove the bytes from the buffer in order to continue, but there are no interrupts comming and your sketch risks to hang.
You are on the french forum. Using french is required.
Even if blocking interrupts while using Serial is a bad practice, the OP says that the program was running fine until he add the liquidCrystal library.
In his software, he is using pin 2 as the windsensor pin and also as the enable of the LCD. So there is a chance ( is it really a chance) that the enable, is blocking the sensor ouptut and no wind speed is detected.
Vous êtes sur le forum français. L'utilisation du français est obligatoire.
Même si bloquer les interruptions lors de l'utilisation de Serial est une mauvaise pratique, l'OP dit que le programme fonctionnait correctement jusqu'à ce qu'il ajoute la bibliothèque liquidCrystal.
Dans son logiciel, il utilise la broche 2 comme broche du capteur de vent et également comme activation de l'écran LCD. Il y a donc une chance (est-ce vraiment une chance) que l'activation bloque la sortie du capteur et qu'aucune vitesse du vent ne soit détectée.