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”:

“Audio Sinks”:

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

Categories: ArduinoMachine Sound

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *