Sound files for this project need to be in WAV format, uncompressed (PCM), 8- or 16-bit resolution. Mono, stereo or multi-channel are all acceptable…the software we’ll use in a moment will automatically convert to 8-bit mono if needed.
If your audio is in a different format, you can convert it with a tool like Audacity (free), Adobe Audition ($$$) or you may already have a utility on your computer that can produce something. Even iTunes can do this, if you tweak the import settings:
If your audio is in a different format, you can convert it with a tool like Audacity (free), Adobe Audition ($$$) or you may already have a utility on your computer that can produce something. Even iTunes can do this, if you tweak the import settings:
For voice recordings, 8 KHz is often a sufficient sample rate. For music, 16 KHz or more. Generally, higher sampling rates will produce better-sounding audio, but it requires more space. Also, the way the playback circuit works, there’s diminishing returns above 25 KHz. Experiment!
The Winbond flash chip we’re using has a capacity of 1,048,576 bytes (1 megabyte, often called “8 megabit” because marketing). Six bytes are used to store data about the length and sampling rate of the audio, leaving 1,048,570 bytes for the audio data itself. Each byte is one audio sample.
To estimate the maximum duration of audio you can store on the chip:
e.g. with 16,000 Hz (16 KHz) music:
If your source audio file is too big for the available space, the end will be truncated to fit.
The Winbond flash chip we’re using has a capacity of 1,048,576 bytes (1 megabyte, often called “8 megabit” because marketing). Six bytes are used to store data about the length and sampling rate of the audio, leaving 1,048,570 bytes for the audio data itself. Each byte is one audio sample.
To estimate the maximum duration of audio you can store on the chip:
Max. duration (in seconds) = 1,048,570 ÷ sampling rate
e.g. with 16,000 Hz (16 KHz) music:
1,048,570 ÷ 16,000 = ~65.5 seconds
If your source audio file is too big for the available space, the end will be truncated to fit.
Chip Loading Circuit
Because the Trinket can’t support traditional serial I/O, we’ll make temporary use of a regular Arduino board to help transfer data to the Winbond chip. Later we move it to a playback circuit.
We suggest using an Arduino Uno, because it has easy access to the SPI pins used to communicate with the flash chip. This can be done with a Leonardo, Mega or other board, but you’ll need to adapt the wiring to use the 6-pin ICSP header (MISO, MOSI and SCK pins, specifically).
The serial flash chip is a 3.3 Volt device, whereas the Arduino is 5 Volts. To avoid unleashing the Blue Smoke Monster, it’s necessary to power the chip from the Arduino’s 3.3V (not 5V) pin, and then use level-shifting circuitry to drive the control lines. There are chips that do this; use ’em if you got ’em, or a simple approximation can be made using resistors to create a voltage divider: output signal pins from the Arduino each connect to a 470 Ohm resistor, the other end connected both to an input pin on the flash chip and a 1K resistor to ground (see diagrams below). If you don’t have exactly these values of resistors on-hand, that’s okay, it’s not rocket surgery…you can substitute other values with approximately a 1:2 ratio, for example 1K and 2.2K (or use two 1K resistors in series for the latter). 1K/2.2K is about the upper limit on values; don’t go higher than this. Won’t harm anything, just won’t work very reliably. Also, note that the data output line back into the Arduino (pin 12, blue wire) connects directly, there are no resistors on this line.
An LED and 220 Ohm resistor can be added between pin A0 and GND to provide a simple status display. The LED will blink to indicate an error, or flickers during the data transfer. This is not essential and can be left out of the circuit if you don’t have the parts.
Finally, there’s a 0.1 μF capacitor between the flash chip’s VCC supply and GND. In a pinch you can get by without this, but it’s good form to have it there, keeps electrical gremlins away.
Breadboarding works fine for occasional use. Knowing I’d be programming a whole lot of chips while debugging this project, I put all the components on an Arduino proto shield, with a socket so the flash chip can be easily swapped out:
Now launch the Arduino IDE and load the AudioLoader sketch:
File→Sketchbook→Libraries→Adafruit_TinyFlash→AudioLoader
Select the board type and serial port from the Tools menu, and upload this code to the board. If you don’t have the flash memory chip installed (or if it's positioned incorrectly, or turned around), the status LED should blink. If it’s working properly, you won’t see anything from the LED, but you can check the serial monitor (at 57600 baud). It should display:
File→Sketchbook→Libraries→Adafruit_TinyFlash→AudioLoader
Select the board type and serial port from the Tools menu, and upload this code to the board. If you don’t have the flash memory chip installed (or if it's positioned incorrectly, or turned around), the status LED should blink. If it’s working properly, you won’t see anything from the LED, but you can check the serial monitor (at 57600 baud). It should display:
HELLO 1048576
If not, something may be amiss with your wiring. Double-check all the connections against the schematic.
Transferring Audio
Close the Arduino serial monitor if you still have it open; the other code won’t work if it’s there.Launch Processing and load the AudioXfer sketch. It’s inside the Adafruit_TinyFlash folder that you downloaded earlier, in a sub-folder called “Processing.” Sorry to make you hunt through the Arduino folder for this, but it was less troublesome that requiring a separate download.
Processing and the Arduino IDE look very similar. If you encounter strange errors, make sure you’re loading the right code in the right environment.
When you run the AudioXfer sketch, all serial ports on the system are scanned until an Arduino running the AudioLoader sketch is identified. If you already know the name of the port (previously selected from the Tools→Serial Port menu in the Arduino IDE), there’s a line you can uncomment to open this port directly and bypass the whole lengthy port scan:
portname = "/dev/tty.usbmodem1a1331"; // bypass scan
(That’s just an example port name one might see on Mac. In Windows it might be something like "COM6".)
If the software detects an Arduino running the AudioLoader sketch, and if it reports a flash memory chip is connected, you’ll be prompted to select a WAV file to transfer. When you select a WAV file and click “Open,” the chip is erased at that point. There is no undo.
AudioXfer is a pretty barebones program…other than the file selection, there is no fancy GUI, it just prints text to the console. You’ll see a long line of dots (and the LED will flicker) as data is transferred to the Arduino and written to the chip. It can take several minutes to load a 1 megabyte chip to capacity. So you may want to test with just a short sound at first.
If all goes well, the software reports “done!” If an error was encountered, you’ll instead see a message with some indication of the problem.
Once a sound is successfully loaded, disconnect the Arduino from USB, remove the flash memory chip from the breadboard or socket, and then we’ll move it over to the playback circuit…
AudioXfer is a pretty barebones program…other than the file selection, there is no fancy GUI, it just prints text to the console. You’ll see a long line of dots (and the LED will flicker) as data is transferred to the Arduino and written to the chip. It can take several minutes to load a 1 megabyte chip to capacity. So you may want to test with just a short sound at first.
If all goes well, the software reports “done!” If an error was encountered, you’ll instead see a message with some indication of the problem.
Once a sound is successfully loaded, disconnect the Arduino from USB, remove the flash memory chip from the breadboard or socket, and then we’ll move it over to the playback circuit…
Page last edited October 11, 2013
Text editor powered by tinymce.