Due to a lack of time and resources, I was looking into how to play audio from the Arduino Nano without an SD card, inspired by this post I found while researching: https://github.com/charliegerard/dev-notes/blob/master/arduino/wavFilesWithoutSdCard.md

In the post, it says that if the audio file is small enough it’s possible to play it on the microcontroller without an SD card module. I followed the instructions on the github but I stumbled into a lot of issues mostly because the libraries and code samples were last updated in ~2007. The other issue I ran into was that I was using a Mac and the software was Windows-only. Here’s what I tried, in order, before giving up:

  1. EncodeAudio, the software the post mentions for encoding audio into a raw text file, is windows only and very outdated, so I used homebrew to try to run the .exe file—homebrew couldn’t unpack it

  2. I installed Wine, another program to run Windows apps on a Mac—Wine couldn’t open it either, and would just crash

  3. I couldn’t find a good Mac alternative to EncodeAudio but I found this post on how to convert an audio file into a headerless file using Audacity

  4. I’m not familiar with headerless audio files but I got a lot of negative numbers, including [-inf] ****values from the Audacity export, and I’m getting a bad feeling

    Negative numbers in the .raw audio file

    Negative numbers in the .raw audio file

  5. I soldiered on and next I tried to install the PCM library in the Arduino IDE—the code was last updated 11 years ago, and the documentation doesn’t exist, it’s also a .pde file which is not a file supported by my version of Arduino IDE, 2.0.0

  6. I tried to force run it by changing the extension to .ino—it ran into library import issues with avr/io.h and util/atomic.h (both of which I manually imported by copying and pasting the source code I found online and into the arduino/libraries folder, but it seemed like I was falling deeper into a rabbit hole of more issues with deprecated libraries)

  7. I downloaded IDE version 1.8.13 (based on this video I found) but the .pde file still errored out

    Errors on the Arduino 1.8.13 IDE

    Errors on the Arduino 1.8.13 IDE

After that deep-dive, I found this post a few days later: https://www.reddit.com/r/arduino/comments/rqee0v/audio_on_nano_iot_33/ and I decided to follow these instructions

Screenshot of Reddit post on headerless audio files

Screenshot of Reddit post on headerless audio files

To continue feeding my obsession, here’s what I tried in my 2nd attempt:

  1. The first issue I ran into was again due to a Win/Mac conflict—the user used Notepad++, which is only available in Windows so I used the terminal utility xxd to convert the headerless .raw file I exported from Audacity into HEX, which looked promising

    xxd command

    xxd command

  2. And then I gave up again because all the code for converting hexadecimals to a byte array in C I wrote and it’s been a minute since I’ve coded in C so I couldn’t make it do what I wanted without spending more time. Then I found this amazing library: ‣

  3. Then I found this amazing article: https://andykong.org/blog/arduinodirect2wav/ that led me to this amazing online .wav to C array converter that would’ve been really helpful to me earlier: https://guilhermerodrigues680.github.io/wav2c-online/

In the end I found the doom song and thought it was very suitable for our halloween midterm project, so I included it into my code with the distance sensor and Neopixels. It’s not perfect, and very low volume but I hope that people will be able to hear it play when they step close to the project.

Final code

Final code