Audio Output on OpenMV Cam H7

OpenMV related project discussion.
kimchibonfire
Posts: 4
Joined: Sun Nov 10, 2019 7:45 pm

Audio Output on OpenMV Cam H7

Postby kimchibonfire » Mon Nov 11, 2019 12:36 pm

Hello,
My group and I are working on our capstone project using the OpenMV Cam H7. We want to know if it is possible to connect an I2S DAC and Amplifier, like you would on a Raspberry Pi or an Arduino, to this board. If it is, how do we go about doing it?
We just need to play a small audio file after running through our algorithm.
Thanks.
User avatar
kwagyeman
Posts: 4457
Joined: Sun May 24, 2015 2:10 pm

Re: Audio Output on OpenMV Cam H7

Postby kwagyeman » Mon Nov 11, 2019 12:45 pm

Hi, you can just do that via the DAC pin and a timer callback. Google MicroPython play audio file over DAC. Then just edit the example code to use our DAC pin.
Nyamekye,
User avatar
kwagyeman
Posts: 4457
Joined: Sun May 24, 2015 2:10 pm

Re: Audio Output on OpenMV Cam H7

Postby kwagyeman » Mon Nov 11, 2019 12:46 pm

Nyamekye,
User avatar
kwagyeman
Posts: 4457
Joined: Sun May 24, 2015 2:10 pm

Re: Audio Output on OpenMV Cam H7

Postby kwagyeman » Mon Nov 11, 2019 12:51 pm

The processor is completely capable of playing high quality audio. However, I don't think the code linked above handles the glitch between playing and loading a sound. If you need to play a long audio file you typically need to have a double buffer thing where you have different chunks of the audio ready to go constantly. The example linked to above is simple... But, you will have to work on the code probably to make it sound better.

With the H7 you can fit like 200KB in RAM so if you do not exceed that for your audio file you are fine. Once you go above that you have to made the code better to make the audio quality better.
Nyamekye,
kimchibonfire
Posts: 4
Joined: Sun Nov 10, 2019 7:45 pm

Re: Audio Output on OpenMV Cam H7

Postby kimchibonfire » Mon Nov 11, 2019 10:21 pm

So we want to select from multiple audio files stored in an sd card, would that work for this case?
Also for the H7 can the audio breakout board just be an AMP and use the DAC function of the H7
User avatar
kwagyeman
Posts: 4457
Joined: Sun May 24, 2015 2:10 pm

Re: Audio Output on OpenMV Cam H7

Postby kwagyeman » Mon Nov 11, 2019 10:37 pm

Since files are objects which are garbage collected you just call "del object", and then "gc.collect()" to delete the python object and then you can load another small wave file into RAM.

As for the audio output sure. I've never done this before however.
Nyamekye,
kimchibonfire
Posts: 4
Joined: Sun Nov 10, 2019 7:45 pm

Re: Audio Output on OpenMV Cam H7

Postby kimchibonfire » Tue Nov 12, 2019 12:38 am

Thanks a lot for the help. I'll probably have more questions in the future, so thank you in advance.
absinth2k7
Posts: 1
Joined: Wed Dec 11, 2019 9:58 pm

Re: Audio Output on OpenMV Cam H7

Postby absinth2k7 » Thu Dec 19, 2019 9:34 pm

i am also interested in audio output for the openmv cam h7. can anyone help me on what amplifier to use and how can i output a sound.. thanks....
kimchibonfire
Posts: 4
Joined: Sun Nov 10, 2019 7:45 pm

Re: Audio Output on OpenMV Cam H7

Postby kimchibonfire » Tue Feb 04, 2020 12:57 pm

So I followed the guide that you posted earlier and I'm having trouble getting a wave file to output properly. The interesting thing is that we got our hands on an older model, I think it was the M4 or M7, and the code worked properly, but trying the same code on the H7 didn't work.

We just have a class D amplifier connected to P6 on the H7 and the amplifier was powered with a bench power supply at 5V.

Code: Select all


import time, pyb, wave, gc
from pyb import DAC

dac = DAC(pyb.Pin("P6"))

def sound():
    gc.collect()
    f = wave.open('test.wav')
    dac.write_timed(f.readframes(f.getnframes()), f.getframerate())
    f.close()
    del f
    gc.collect()

while(True):
    sound()
    time.sleep(5000)
    pyb.hard_reset()



User avatar
kwagyeman
Posts: 4457
Joined: Sun May 24, 2015 2:10 pm

Re: Audio Output on OpenMV Cam H7

Postby kwagyeman » Tue Feb 04, 2020 1:38 pm

We don't actually support audio output on a pin. I just gave some pointers on this but its not a feature we actually want or have a road map to support. The chip is technically capable of doing it and MicroPython has some basic support. However, it's not a focus and/or a goal of our product.

If you you have an order model and can verify the code worked on the older model and not on the new one then please make a GitHub issue with all the parts to re-produce and Ibrahim might fix it:

https://github.com/openmv/openmv/issues

The DAC pin should work correctly so we are inclined to support making sure the MicroPython HAL operates as it should.
Nyamekye,

Return to “Project Discussion”

Who is online

Users browsing this forum: No registered users and 1 guest