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: