0

Audio Problem
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Audio Problem

by lawrenceyy on Thu Feb 11, 2021 9:31 pm

I have a feather M4 Express with a Prop-Maker stacked on top. I also have a HC-SR04 and speaker (attached to Prop-Maker). The problem I am running into has to do with the order of my code. When I initialize the HC-SR04 before the audio code, the speaker plays fine. When I initialize the HC-SR04 after the audio code, the speaker plays a bunch of static.

I've stripped down my code to highlight the problem. This one plays the wave file fine.
Code: Select all | TOGGLE FULL SIZE
import board
import digitalio
import audioio
from audiocore import WaveFile
import adafruit_hcsr04

#initialize HC-SR04
sonar = adafruit_hcsr04.HCSR04(trigger_pin=board.RX, echo_pin=board.D4)

#audio
propMakerPower = digitalio.DigitalInOut(board.D10)
propMakerPower.direction = digitalio.Direction.OUTPUT
propMakerPower.value = True
speaker = audioio.AudioOut(board.A0)
wave = WaveFile(open("StreetChicken.wav", "rb"))

#play wave
speaker.play(wave)
while speaker.playing:
    pass


This one plays static noise.
Code: Select all | TOGGLE FULL SIZE
import board
import digitalio
import audioio
from audiocore import WaveFile
import adafruit_hcsr04

#audio
propMakerPower = digitalio.DigitalInOut(board.D10)
propMakerPower.direction = digitalio.Direction.OUTPUT
propMakerPower.value = True
speaker = audioio.AudioOut(board.A0)
wave = WaveFile(open("StreetChicken.wav", "rb"))

#initialize HC-SR04
sonar = adafruit_hcsr04.HCSR04(trigger_pin=board.RX, echo_pin=board.D4)

#play wave
speaker.play(wave)
while speaker.playing:
    pass


What is causing the speaker to play static noise in the second code example?

Thanks,

Lawrence Yun

lawrenceyy
 
Posts: 88
Joined: Thu May 07, 2015 12:32 pm

Re: Audio Problem

by tannewt on Fri Feb 12, 2021 3:30 pm

This sounds like a bug! Please file an issue here with all of the files needed to replicate it: https://github.com/adafruit/circuitpython/issues Thanks!

tannewt
 
Posts: 2189
Joined: Thu Oct 06, 2016 8:48 pm

Re: Audio Problem

by lawrenceyy on Fri Feb 12, 2021 4:51 pm

Okay, I'll post the bug to github.

I should also mention that in the code where audio does play (example 1), the sonar readings are off. The values are still proportional - smaller reading when target is close and larger when target is far. But the readings are 10-20x larger.

How long will it take for someone to find a solution to this bug? Will it be posted in a new version of CircuitPython? I kind of need a solution in the next week or two.

lawrenceyy
 
Posts: 88
Joined: Thu May 07, 2015 12:32 pm

Re: Audio Problem

by tannewt on Tue Feb 16, 2021 2:08 pm

lawrenceyy wrote:How long will it take for someone to find a solution to this bug? Will it be posted in a new version of CircuitPython? I kind of need a solution in the next week or two.


We make no promises if/when things will be fixed. Yes, fixes would be pushed in new versions. Like most open source projects, we provide no warranty.

tannewt
 
Posts: 2189
Joined: Thu Oct 06, 2016 8:48 pm

Re: Audio Problem

by kevinjwalters on Thu Feb 18, 2021 9:05 am

Is it worth trying different versions of CircuitPython here to see if older/newer versions work?

kevinjwalters
 
Posts: 883
Joined: Sun Oct 01, 2017 3:15 pm

Please be positive and constructive with your questions and comments.