I saw that and tried it out but I couldnāt get it to work and gave up in favor of the separate integration option which I have used before with the pulse_counter. Regardless, of all of this, I like your idea to try only rising/falling as a debug step so Iāll probably give it a try, though in order to use that and get the correct value Iāll have to use a filter with math to double the results.
pulse_counter reports a rate (ie pulses per minute which you multiply by a factor to get litres per minute etc)
Anyway, this is all beside the point, who cares about the units when I canāt get the thing to be stable. Iām trying it with the default count_mode right now, by the way: rising_edge: INCREMENT and falling_edge: DISABLE.
Yeah, I tried it with a 120Vac to 5V 3A dedicated USB micro supply but that didnāt seem to affect the problem, still rebooted. It very well could be that the plastic wheel is scraping the body of the encoder.
Iāve got the o-scope hooked up to it now and Iām watching the pulses and to be honest, they look pretty darn clean! Now at least I know that running my power drill at full tilt (on ā1ā speed) the shortest pulses I get are around 250Āµs.
This is 1s/DIV, so a long capture with variable slow speeds on the drill. When the plastic vane stops between the sensor, the output is 3.3V. When the vane does not block the sensor, the output is 0V.
Oh! No, I hadnāt, I guess I didnāt see that one or maybe I misinterpreted it. Iāll give that a try and see if itās the actual pulse_counter implementation causing the reboot or something external.
I was just about to go on an excursion building a small faraday cage to see if that would help! LOL.
Iāll give the āno pulse_counter definitionā experiment a try first, since that should be pretty easy and straight forward to prove out.
Giving hard time, made me curious now
At least you have scope, sooner or later youāll find something.
Your wiring is quite long, nice antenna as wellā¦ Twisting them (or better shortening) might offer some benefits.
Obviously you tried some other Gpio pinā¦?
I hadnāt until you just said that but I did try a completely different ESP32 ā same result and I just tried GPIO27 instead of GPIO14 and the problem persists.
I swapped the USB cable for a shorter one and this one has a ferrite bead on it but that didnāt seem to help either.
I got another probe on the VDD but this scope is REALLY crappy and I canāt really zoom into it too much vertically since the base of the signal must be displayed in the scope window. Anyway, this is a zoomed out view (2 seconds/DIV) and the failure happened just to the left of when the high-speed pulses stopped.
Wow, itās getting even betterā¦
What about the lambda on your yaml: if (id(battery_drill).rpm) >666 {rebootā¦
Seriously, there is only esp32 and optocoupler .Esp is now without code for interrupts and stabile voltages confirmed by scopeā¦?
Yeah, Iām wondering if I should just try to implement my own counter from the GPIO pin with straight C code using the Arduino IDE and see if I can get it to work with something besides ESPHome. Iāve only tinkered a little with that before, so itād take some time and googling but Iām not really sure what else I can try.
not that I know of. The failure points seem to be random ā not based on a time since last reboot. I am trying it again, this time without the powerdrill just hand cranking the thing and I can still cause reboots. Iām cranking it pretty slowly, the first time I got to almost 8 meters before the thing rebooted. If I try cranking it more it counts up between the reboots ā the value that it reboots at is random.
I asked Gemini to produce some interrupt-driven pulse counting ESP32 source code and it responded with this:
#include <Arduino.h>
const int pulsePin = 13;
const int mmPerPulse = 1;
volatile int pulses = 0;
volatile int totalPulses = 0;
void setup() {
Serial.begin(115200);
pinMode(pulsePin, INPUT);
attachInterrupt(digitalPinToInterrupt(pulsePin), countPulse, RISING);
}
void loop() {
static unsigned long previousMillis = 0;
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= 1000) {
previousMillis = currentMillis;
int currentPulses = pulses;
pulses = 0;
totalPulses += currentPulses;
Serial.print("Current Pulses: ");
Serial.print(currentPulses);
Serial.print(" Total Pulses: ");
Serial.print(totalPulses);
Serial.print(" Distance: ");
Serial.print(totalPulses * mmPerPulse);
Serial.println(" mm");
}
}
void countPulse() {
pulses++;
}
I took that code, compiled it on the Arduino IDE and sent it to the device. It isnāt great but it definitely shows pulses and a total in the Arduino Serial Monitor. However, after hand cranking it for about a minute, I can get the thing to reboot, just like it does with ESPHome: