Example Code for Arduino-Play WAV via IIS
Last revision 2026/01/24
This article offers an example code for using Arduino with Bluno M0 to play WAV audio via IIS, detailing hardware and software setup, including necessary libraries and sample code for SD card initialization and audio playback.
Hardware Preparation
- Bluno M0 Mainboard(SKU: DFR0416) ×1
- Micro USB Cable ×1
- Advanced IIS chip ×1
- SD Card (with "test.wav" file) ×1
Software Preparation
- Download Arduino IDE: Click to download Arduino IDE
- Install Bluno M0 board URL: https://raw.githubusercontent.com/DFRobot/DFRobotDuinoBoard/master/package_dfrobot_index.json
- Libraries: SPI, Wire, SD, WAV (included with Bluno M0 board package)
Sample Code
Bluno M0 will initialize the SD card, load "test.wav", and play it via the connected IIS chip. Serial monitor will display initialization status.
#include <SPI.h>
#include <Wire.h>
#include <SD.h>
#include <WAV.h>
// set up variables using the SD utility library functions:
Sd2Card card;
const int chipSelect = 4;
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.print("\nInitializing SD card...");
// we'll use the initialization code from the utility libraries
// since we're just testing if the card is working!
if (!card.init(SPI_HALF_SPEED, chipSelect)) {
Serial.println("initialization failed. Things to check:");
Serial.println("* is a card inserted?");
Serial.println("* is your wiring correct?");
Serial.println("* did you change the chipSelect pin to match your shield or module?");
return;
} else {
Serial.println("Wiring is correct and a card is present.");
}
}
void loop()
{
int ret=WAV_DECODING;
wav.begin("test.wav");
wav.play();
while(ret == WAV_DECODING){
ret = wav.decode();
}
}
Result
Play audio in loop if SD card works, print error info via Serial if failed.
Additional Information
Tested Platform:
- Windows: win7 32bit/64bit, win8 32bit/64bit, win10 32bit
- Linux: Ubuntu 12.04 32bit
- Mac book: OSX 10.11
Was this article helpful?
