I use ESP8266 NodeMcu V3 board and built circuit similar to this one https://i.ytimg.com/vi/eFeOSiL-IBQ/hqdefault.jpg
At the beginning I tried to count "frequency"
In code bellow i expected -/+ 100 ticks per second (50Hz), but I got 200-208.
Code: Select all
import micropython
micropython.alloc_emergency_exception_buf(100)
import machine
import time
from machine import Pin
counter = 0
def handler(pin):
global counter
counter += 1
pin = machine.Pin(12, machine.Pin.IN, machine.Pin.PULL_UP)
pin.irq(trigger=Pin.IRQ_RISING, handler=handler)
while (True):
time.sleep_ms(1000)
print(counter)
counter = 0
Code: Select all
int counter = 0;
void setup() {
Serial.begin(115200);
pinMode(12, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(12), zcDetect, RISING);
}
void loop() {
delay(1000);
Serial.println(counter);
counter = 0;
}
ICACHE_RAM_ATTR void zcDetect() {
counter += 1;
}
Any suggestions?