Description
CircuitPython version
CircuitPython 8.05 on the ESP32. Image file used: adafruit-circuitpython-doit_esp32_devkit_v1-en_GB-8.0.5.bin
Code/REPL
import board
import busio
import sdcardio
import storage
import audiocore
import audiobusio
import time
import pulseio
import array
import gc
spi = busio.SPI(board.D18,MOSI=board.D23,MISO=board.D19)
cs=board.D5
sdcard = sdcardio.SDCard(spi, cs)
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, "/sd")
aud=audiobusio.I2SOut(board.D32,board.D25,board.D33,left_justified=False)
pulserx=pulseio.PulseIn(board.D27,maxlen=200,idle_state=True)
wav=audiocore.WaveFile("/sd/qaudio/Energiser-DataConfirmed.wav")
while True:
print("Playing wav file")
aud.play(wav)
pulsedata=array.array('H',[5000,846,399,462,783,468,369,465,372,846,399,465,789,1266,399,3765,399,465,3699,468,3708,3762,402,3765,402,3765,399,849,405,468,789,423,402,462,366,465,372,849,396,1269,813,468,3708])
for x in range(10):
pulsetx=pulseio.PulseOut(board.D22,frequency=28800, duty_cycle=32768)
pulsetx.send(pulsedata)
pulsetx.deinit()
gc.collect()
time.sleep(0.05)
pulserx.clear()
print("TX Data")
time.sleep(0.1)
while aud.playing:
print("I'm alive")
time.sleep(0.1)
print("Finished!")
Behavior
Audio plays with stuttering. The ESP32 freezes up requiring a hard reset after running for a short while. No errors are displayed.
Description
Audio plays just fine while pulseio.PulseOut isn't being called, but any audio playing while a pulseio.PulseOut command is being executed the audio stutters. This supplied code with the pulseio.PulseOut related lines enabled but the pulseio.PulseIn related lines commented out will run without crashing but will cause stuttering. If the pulseio.PulseOut commands are commented out as well then the audio plays perfectly.
If I enable the lines relating to pulseio.PulseIn then it will crash. If there is almost zero data flowing in to data pin being used by pulseio.PulseIn then it will take many minutes before it crashes. If however data is actively being transmitted then it will crash within a minute or two. I'm unclear if the audio is connected to this crashing or not, it could just be that pulseio.PulseIn crashes on its own.
In all cases the crash didn't generate any errors displayed on REPL, it just froze and didn't continue.
Audio file used is 16bit unsigned 44.1kHz of 1.9 seconds in length.
Additional information
Please be aware that my test board has an IR receiver connected to the pulseio.PulseIn pin and is actively receiving IR while this was being tested, this may impact the results. My pulseio.PulseOut pin is actively driving an IR LED, so actively transmitting when called by this code. LED is being driven by a BC549 with a 1K resistor on the base connected to the GPIO pin of the ESP32.