This week I received a brand new Arduino UNO R4 in my mail.It uses a Renesas 32 bit microprocessor and has 256 kB Flash and 32 kB RAM. It provides 1 DAC and 6 PWM pins. I got the version which also provides WIFI and a LED matrix.
Unfortunately there is no I2S support, but nevertheless I was wondering if I could get some audio from it.
I extended my AudioTools Library by implementing a timer and a PWM driver. For the DAC I could use the existing Arduino driver.
With this we can use the following:
“Audio Sources”:
- Analog Microphones – AnalogAudioStream
- Files on the Internet – URLStream
- Streaming Internet Radios – ICYStream
- Generated Sound – GeneratedSoundStream
- Encoded Audio – EncodedAudioStream
- A Timer based Source – TimerCallbackAudioStream
- Input using FIR, IIR Filters – FilteredStream
- Converting Streams
- Any other Arduino Classes implementing Streams: SD, Ethernet etc
“Audio Sinks”:
- Analog output e.g. to an Amplifier – AnalogAudioStream
- Output using PWM – PWMAudioOutput
- Encoded Audio – EncodedAudioStream
- Serial to display the data as CSV – CsvOutput
- Serial to display the data as hex dump – HexDumpOutput
- Encoding and Decoding of Audio EncodedAudioStream
- ID3 Metadata for MP3 – MetaDataID3
- A Timer based Sink – TimerCallbackAudioStream
- VS1053 Codec Module – VS1053Stream
- Callback integration e.g. with ESP8266Audio AudioOutputWithCallback
- Output using FIR, IRR Filters – FilteredStream
- Determine the Volume – VolumeOutput
- Split the Output to different Destinations – MultiOutput
- 3 Band Equilizer – Equilizer3Bands
- LED Strip/Matrix – LEDOutput
- FFT – AudioRealFFT and AudioKissFFT
- Converting Streams
- Multiuser-Webserver for PCM Output – AudioWAVServerEx
- Any other Arduino Classes implementing Streams: SD, Ethernet etc
Limitations
I noticed that a sample rate of 44100 is a bit too much for this processor so we need to use some lower sampling rates. Half this rate seemed to be quite stable. Here the resampling functionality of the library gets quite useful.
I also noticed that in many scenarios I was exceeding the available memory. e.g
- To run the FFT tests, I needed to decrease the number of buckets to 1024. I was comparing the FFT speed with the ESP32: the ESP32 was taking 1ms and the UNO 3ms – so the ESP32 is still much faster.
- MP3 decoding is only working when I deactivate the logging because it requires too much memory. So I did not test this scenario.
Arduino Setup
I was struggling quite some time because this processor was not showing up in Arduino and it took me quite some time to figure out that the following URL needed to be added to the Additional Board Manager URL: https://github.com/arduino/ArduinoCore-renesas
Conclusions
On the positive side, the URLStream was working w/o any changes.
In a nutshell we can use this processor for some simple audio projects e.g. together with some simple codecs or we can use it together with a ‘vs1053 codec module’ if we need to decode MP3 or AAC.
Example
Here is an example test sketch which just outputs a sine wave
#include "AudioTools.h"
AudioInfo info(8000, 1, 16);
SineWaveGenerator<int16_t> sineWave(32000);
GeneratedSoundStream<int16_t> sound(sineWave);
PWMAudioOutput pwm;
StreamCopy copier(pwm, sound); // copy in to out
void setup() {
Serial.begin(115200);
AudioLogger::instance().begin(Serial, AudioLogger::Warning);
// setup sine wave
sineWave.begin(info, N_B4);
// setup PWM output
auto config = pwm.defaultConfig();
config.copyFrom(info);
pwm.begin(config);
}
void loop(){
copier.copy();
}
The output goes to the D2 pin and if you change the channels to 2 you get the second channel on D4.
If you replace the PWMAudioOutput with the AnalogAudioStream class, the output will be available at the DAC pin A0.
To hear the audio you can connect your earphones to the indicated pins.
Here you can also find some of my other posts related to the Arduino Uno R4
1 Comment
Anonymous · 20. November 2024 at 7:05
Thanks !