i have a scooter wheel (10 inch) and i want to measure speed of it.
there is built in hall sensor(5v) which is going low/high 30 times for 1 full wheel rotation
so i used 10k/20k voltage devider to make 5v 3.3v and i try to read in esp32
its working ok but my question is . if wheel rotate 25kmh it means it need to make 1 full rotation for 11.5milliseconds which is 30 pulses
is esp32 able to read 30 pulses for 11.5 milliseconds?
const int gpio_pulse_IN_M2 = 2; // Change this to the desired GPIO pin
volatile int M2_pulseCount = 0;
volatile int M2_lastState = LOW;
void setup() {
Serial.begin(9600);
pinMode(gpio_pulse_IN_M2, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(gpio_pulse_IN_M2), M2_pulseCounter, CHANGE);
}
void loop() {
if (Serial.available()) {
Serial.print("Pulse Count: ");
Serial.println(pulseCount/30);
}
delay(1000); // You can add a delay or perform other tasks in your loop
}
void M2_pulseCounter() {
int currentState = digitalRead(gpio_pulse_IN_M2);
if (currentState != lastState) {
M2_pulseCount++;
M2_lastState = currentState;
}
}
This, however, seems strange. On every interrupt, the interrupt pin will of course be the same as the previous time it was triggered, because that's the reason the interrupt code runs. So, you might get a count on the first pass through, but after that, you'll never increase your counter.
Hmm. If there's a character, Send message. wait a second. Send message. Wait a second. Send message. You never remove the character, so it will always be there, once you've sent one. If you never send a character, there's nothing in the buffer, so false, so no printing.
This is an ESP32, so you've got a 32 bit counter going.
So, what is it you're seeing that made you ask your question?