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.
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.
Example to make the DAC do audio.
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.
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
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.
Thanks a lot for the help. I’ll probably have more questions in the future, so thank you in advance.
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…
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.
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()
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:
The DAC pin should work correctly so we are inclined to support making sure the MicroPython HAL operates as it should.