Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP32: PulseIn does not work (and it's weird too) #9979

Open
0wwafa opened this issue Jan 19, 2025 · 0 comments
Open

ESP32: PulseIn does not work (and it's weird too) #9979

0wwafa opened this issue Jan 19, 2025 · 0 comments
Labels
bug esp32 espressif applies to multiple Espressif chips pulseio
Milestone

Comments

@0wwafa
Copy link

0wwafa commented Jan 19, 2025

CircuitPython version

Adafruit CircuitPython 9.2.3 on 2025-01-17; ESP32 Devkit V1 with ESP32

Code/REPL

#If you save this as code.py and the run it on boot or soft boot, it will only show 0 and hitting control C will end with 0 (no pulses received)
import board,pulseio,digitalio,time
sense=digitalio.DigitalInOut(board.D14)
sense.direction=digitalio.Direction.INPUT
input("PRESS RETURN TO START\n")
sense.direction=digitalio.Direction.OUTPUT
p=pulseio.PulseIn(board.D13,1024,0)
print('0',len(p))
time.sleep(1)
print('1',len(p))
p=pulseio.PulseIn(board.D13,1024,1)
time.sleep(1)
print('2',len(p))

try:
  while True:
    while p:
      print(p.popleft())
    p=pulseio.PulseIn(board.D13,1024,0)
    time.sleep(0.01)

except KeyboardInterrupt:
  sense.direction=digitalio.Direction.INPUT
  print(len(p))
  p.deinit()
  sense.deinit()
  print("program ended.")
  pass

except Exception as e:
  sense.direction=digitalio.Direction.INPUT
  p.deinit()
  sense.deinit()
  print("program ended because of ",e)



# but if you run this in the REPL, it gets pulses (a hundred in my case, even if the source is continuously sending pulses for test)

>>> p=pulseio.PulseIn(board.D13,1024,0)
>>> len(p)
100

after that p does not "grow" I have to run again p=pulseio.PulseIn(board.D13,1024,0) in the REPL
and even if I wait a long time, I get 100-120 pulses.
(the source is continuously sending pulses with variable lengths between 40 and 520 microseconds!)

Behavior

explained above.

Description

No response

Additional information

No response

@0wwafa 0wwafa added the bug label Jan 19, 2025
@dhalbert dhalbert added espressif applies to multiple Espressif chips pulseio labels Jan 20, 2025
@dhalbert dhalbert added this to the 9.x.x milestone Jan 20, 2025
@tannewt tannewt modified the milestones: 9.x.x, Long term Jan 21, 2025
@tannewt tannewt added the esp32 label Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug esp32 espressif applies to multiple Espressif chips pulseio
Projects
None yet
Development

No branches or pull requests

3 participants