Simple `pulse_counter` device rebooting unexpectedly (during high speed)

So, I built a simple ESPHome pulse counter using an ESP32 and an ERCF Binky device. I powered everything with 3.3V, though I think that the ERCF implementation supplies the Binky PCB with 5V. Anyway, when I fire it up, it works – I get pulses and the device counts them.

However, I’m trying to run this at “high speed”, so I’m getting hundreds of pulses per second. When I try to do that the device just seems to reboot. I built it with a screen and using WiFi but I’ve simplified the YAML to be just the pulse counter and the problem still persists.

esphome:
  name: respooler
  friendly_name: Respooler
  build_path: ./build/respooler

esp32:
  board: nodemcu-32s
  framework:
    type: arduino

logger:
  level: DEBUG

safe_mode:

sensor:
  - platform: pulse_counter
    pin: GPIO13
    id: encoder_pulses
    name: "Encoder Pulses"
    icon: "mdi:square-wave"
    unit_of_measurement: "mm/min"
    update_interval: 1s
    accuracy_decimals: 1
    count_mode:
      rising_edge: increment
      falling_edge: increment

In level: DEBUG I still don’t see anything hinting at the problem, the device just seems to reboot (this is from the serial log):

[10:57:56][D][sensor:094]: 'Encoder Pulses': Sending state 11520.00000 mm/min with 1 decimals of accuracy
[10:57:57][D][pulse_counter:174]: 'Encoder Pulses': Retrieved counter: 11580.00 pulses/min
[10:57:57][D][sensor:094]: 'Encoder Pulses': Sending state 11580.00000 mm/min with 1 decimals of accuracy
[10:57:58][D][pulse_counter:174]: 'Encoder Pulses': Retrieved counter: 8520.00 pulses/min
[10:57:58][D][sensor:094]: 'Encoder Pulses': Sending state 8520.00000 mm/min with 1 decimals of accuracy
[10:57:59][D][pulse_counter:174]: 'Encoder Pulses': Retrieved counter: 10680.00 pulses/min
[10:57:59][D][sensor:094]: 'Encoder Pulses': Sending state 10680.00000 mm/min with 1 decimals of accuracy
[10:58:00][D][pulse_counter:174]: 'Encoder Pulses': Retrieved counter: 12840.00 pulses/min
[10:58:00][D][sensor:094]: 'Encoder Pulses': Sending state 12840.00000 mm/min with 1 decimals of accuracy
[10:58:00]ets Jul 29 2019 12:21:46
[10:58:00]
[10:58:00]rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
[10:58:00]configsip: 0, SPIWP:0xee
[10:58:00]clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
[10:58:00]mode:DIO, clock div:2
[10:58:00]load:0x3fff0030,len:1184
[10:58:00]load:0x40078000,len:13132
[10:58:00]load:0x40080400,len:3036
[10:58:00]entry 0x400805e4
[10:58:01][I][logger:156]: Log initialized
[10:58:01][C][safe_mode:079]: There have been 1 suspected unsuccessful boot attempts
[10:58:01][D][esp32.preferences:114]: Saving 1 preferences to flash...
[10:58:01][D][esp32.preferences:143]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[10:58:01][I][app:029]: Running through setup()...
[10:58:01][C][pulse_counter:147]: Setting up pulse counter 'Encoder Pulses'...
[10:58:01][C][pulse_counter:061]:     PCNT Unit Number: 0
[10:58:01][C][pulse_counter:107]:     Filter Value: 13us (val=1023)
[10:58:01][I][app:062]: setup() finished successfully!
[10:58:01][I][app:100]: ESPHome version 2024.9.0 compiled on Oct 12 2024, 10:56:50

How can I debug this further? I’m thinking o-scope, maybe to verify the voltage levels?

I just tried powering the sensor with 5v and it still reboots during high speed moves. :thinking:

Run what ?

It’s an encoder, to measure filament. The link in the first post has the detail of the encoder and sensor.

Sure, but that encoder probably measures something that “runs” at high speed.
Can you count out interferences, ground errors, power supply issues etc?

It might be worth a try to lower the debug level to something like `WARN. :warning:

Often it is the logger which causes a reboot and not the component itself :bulb:

I tried using a dedicated 5V 3A supply to power the ESP32. I also tried adding more cap to the 3.3V power rail. Neither of those experiments worked. :expressionless:

I actually had it on WARN to begin with and added DEBUG to see what was going on.

1 Like

Then maybe try without logger other then that I don’t see much more ways to “lighten” your yaml as it is already quite a minimal one :thinking:

If you are convinced it’s code related keep on. If you have doubts, feel free to present your hardware. I still don’t know if you have a hamster running on the encoder wheel or 10kW motor running, or something else…

I’m not convinced. I’m grasping at straws here. This is my setup, just tested it and it rebooted several times before I disconnected it.


In the foreground is the ESP32 and in the background the KY-010 board, with the EE-SX398 and I’ve tried this with the 5V pin, too. :-1:

I’m running a 3d printed respooler which takes filament from one spool and moves it to the other - I’m driving it with my battery powered drill. I want the encoder to measure the length of the filament while I do this. I figured it would be cake, but then I ran into these reboots that seem to be a show stopper.

I can’t do that because then I’d have no way to tell what was happening! :smiley:

Originally, I had a screen on it using I2C so I could read out the # of pulses and total but I’ve removed it to simplify. I guess since it doesn’t seem to be the source of the reboot I technically could put that back and disable the logger… maybe I’ll give that a try.

You only need one of these:

The pulse is a 50% duty cycle pulse every millimetre. If you count on both the rising and falling edge you will get twice that.

This may fix your issue as you are counting 1/2 as often.

Also also this:

unit_of_measurement: "mm/min"

Should just be “mm”. You get one pulse per mm. Not per time interval.

You shouldn’t, Esp Gpios don’t appreciate 5V.

If the suggestion above from tom_l doesn’t resolve issue, take some odds out and remove the pulse counter from your code. If it’s still resetting try with another power supply/cable.

According to the head of Expresif the inputs are 5v tolerant.

https://www.qworqs.com/blog/2021/05/19/are-the-esp32-and-esp8266-5v-tolerant-yes-they-officially-are/

This is incorrect @tom_l. I want it to count on every millimeter because of the design of the encoder. I’ve already calibrated it at my desk using a strand of filament that is 100mm long.

you can see in the image below that the gear has a vaned wheel attached to it which has 1mm fins on it. If I only use rising_edge or only use falling_edge, the measured distance will only be half the length of the strand of filament.

This is also wrong, I have the pulse_counter block with “mm/min” because that’s what the pulse_counter always reports. If you look at the logger examples I’ve posted EVERYTHING that the pulse_counter reports is normalized to 1 minute. I can have it report in 2s intervals but if it gets 5 pulses during those 2 seconds it will say: 150 pulses (which is 60 seconds divided by 2 seconds times 5 pulses). AND this value isn’t totaled, it’s only for the update_interval – which is why I chose mm/min as the units. If I can get the pulse_counter to work correctly, my plan was to include a block like this:

  - platform: integration
    name: "Total Filament Length"
    id: total_filament_length
    icon: "mdi:counter"
    sensor: encoder_pulses
    time_unit: min
    device_class: "temperature"
    state_class: "measurement"
    unit_of_measurement: mm
    accuracy_decimals: 1

Which will sum up all the pulse_counter measurements for me but I’ve removed it for the debug of the reboots…

this is good to know because I was worried that 5V to the sensor may raise up the output voltage to a point painful for the ESP32. Looking at the spec sheet for the sensor it looks like the minimum supply voltage is 4.5V but this PCB seems to work at 3.3V so I’m not sure if I need to use the 5V supply. Anyway, it doesn’t seem to help the reboots.

The more I play with this setup the more I’m wondering if it’s some static electric charge playing a role because these spools of filament have a lot of separation happening, especially when I ramp up the speed. Maybe there’s a large/wide magnetic field playing a role in the signals somehow… only I’m not sure how I should attempt to protect the wiring and whatnot from the magnetic flux. I’m wondering if I can just wrap it up in aluminum foil or something…

Interferences are the most difficult thing to debug. Also, could the encoder wheel touch the plastic body of the sensor at high speed? Creating static electricity…

But try with different power source and short cable first.
rst:0x1 (POWERON_RESET),boot:0x13
smells like power problem or interference.

None of what you said is correct. Good luck.

please don’t get upset. You’ve helped me in the past. have you used the pulse_counter before?