Under the Hood: Arduino UNO R4 – Timers

I was wondering how to use the timers in the new Arduino UNO R4. Unfortunately I did not find any documentation, so I decided to document my findings here. The UNO R4 has two timer peripherals: the General PWM Timer (GPT) and the Asynchronous General Purpose Timer (AGT). There are only 2 16 bit AGT timers (but one is already used to provide the Arduino millis() and microseconds() methods) and there are 7 GPT timers Read more…

Under the Hood: Arduino UNO R4 – PWM

In Arduino we can use the analogWrite(pin, value) method to create a PWM signal on the digital pins. The value parameter is used to change the duty cycle but the PWM frequency which is fixed at usually 490 Hz and can not be changed. Here is a simple example sketch that also works with the UNO R4: void setup() { pinMode(D2, OUTPUT); // set 100% analogWrite(D2,255) } void loop() {} Fortunately the Arduino UNO R4 Read more…

Arduino UNO R4 with an Analog Microphone

The easiest way to “record” audio with an Arduino UNO R4 is by using an analog microphone which can be connected to any analog pin. For my test I was using a MCP6022 Microphone Sensor. Arduino Sketch There are no surprises here because we can use the AnalogAudioStream as audio source: #include “AudioTools.h” AnalogAudioStream in; AudioInfo info(8000, 1, 16); CsvOutput<int16_t> out(Serial); // ASCII output stream StreamCopy copier(out, in); // copy i2sStream to CsvOutput // Arduino Read more…

Audio with the new Arduino UNO R4

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 Read more…

Arduino 2.0: RP2040 Debugging with Linux

I thought it should be quite easy to use the new debugging functionality of Arduino 2.0 with the RP2040 using the official RP2040 debug probe in Earle Phil Hower’s core. I am using Arduino on my old Macbook running Linux: And Boy was I wrong! The first challenge was to figure out the correct wiring: The UART from the Debug Probe optinally goes to the UART and a GND pin of the RP2040. Here the Read more…

ADPCM and WAV Files

At the very beginning of my Arduino AudioTools project, I was providing a codec for WAV files. It was just handling PCM audio, so it just needed to read or write the header and then could just copy the audio data. In my last blog, I was writing that the ADPCM codec is perfectly suited for encoding and decoding audio on microcontrollers. So the next natural step is to provide a proper ADPCM support for Read more…

Fast Audio Codecs for Microcontrollers

My AudioTools project is supporting quite a few audio encoders and decoders. They are critical to reduce the storage or transmission volume of audio. Though I support the encoding of AAC and MP3, I can’t really recommend this: it requires a lot of memory and processing time. For an introduction how to use the codecs, please read the Wiki. Below you can find my short list of my favorite codecs which are fast and efficient. Read more…

ArduinoAudioTools: Playing Movies ?

In my last post I was writing about audio containers. But containers are usually also used to mux audio and video together in one file. This made me think, if we could play movies on an ESP32? In fact there are some projects out there that exactly do this: They used Motion-Jpeg to play the movie and store the audio in a separate file, so they actually avoided the complexity of containers. A mjpeg is Read more…

Arduino Audio Tools: Codecs and Containers

So far I have created quite a few posts about the supported codecs, but I never provided any detailed information how things work behind the scene. Audio codecs are used to compress and decompress PCM audio data. I tried to eliminate all the complexity but sometimes it helps to know how things are working, so from an API point of view you can just stream audio PCM data to an encoder and stream (compressed) encoded Read more…

ESP32 Memory Management: floats and MALLOC_CAP_32BIT

We can dynamically allocate memory with malloc() or use the dedicated ESP32 specific functions. In general we need to use byte aligned allocations (MALLOC_CAP_8BIT). When we have used up all available memory space, we still have 4 byte aligned memory available that we can use to store arrays of int32_t data. Unfortunately we can not use this to store floats. Here is the info from the documentation: Please note that on ESP32 series chips, MALLOC_CAP_32BIT Read more…