Teensy 3.0 + Ada FRuit VS1053 Audio Breakout Board Problems

Status
Not open for further replies.

brandonlynne

New member
Hi. I'm trying to use the ada fruit VS1053B breakout board (http://www.adafruit.com/products/1381).

It's pretty cool, as it has the VS1053 and a micro sd breakout on the same card. It works great with my Arduino Uno r3 and Teensy 2.0 boards, but I've been transiutionaing to the Teensy 3.0 board fro a project, and the code no longer compiles (presumably b/c the processor is different on the Teensy 3.0). Here's a link to the github code/examples: https://github.com/adafruit/Adafruit_VS1053_Library

I'm not sure if there is something "simple" that can be done to adapt the Adafruit code to work on the Teensy3 board (it's above my head at this point). Does anyone have an idea? (Bonus Question: does anyone know if I can turn on line numbers in the arduino IDE?)

Here's the specific error list from the arduino IDE:
/Users/brandon/Documents/Arduino/libraries/Adafruit_VS1053_Library/Adafruit_VS1053.cpp:20:7: error: expected constructor, destructor, or type conversion before '(' token
/Users/brandon/Documents/Arduino/libraries/Adafruit_VS1053_Library/Adafruit_VS1053.cpp: In member function 'boolean Adafruit_VS1053_FilePlayer::useInterrupt(uint8_t)':
/Users/brandon/Documents/Arduino/libraries/Adafruit_VS1053_Library/Adafruit_VS1053.cpp:54:5: error: 'OCR0A' was not declared in this scope
/Users/brandon/Documents/Arduino/libraries/Adafruit_VS1053_Library/Adafruit_VS1053.cpp:55:5: error: 'TIMSK0' was not declared in this scope
/Users/brandon/Documents/Arduino/libraries/Adafruit_VS1053_Library/Adafruit_VS1053.cpp:55:15: error: 'OCIE0A' was not declared in this scope
 
This compiles without error! I'll let you know how if there are any issues once I breadboard the VS1053 breakout to the Teensy3.0. Thanks so much for building in support for the amazing Teensy 3.0 and this library!
 
Paul, it worked great. The Teensy3.0 now compiles and works with the Adafruit VS1053B breakout. Nice work! This should give Teensy3.0 users access to sound (mp3, wav, ogg, etc) and an SD card reader in one board. On a side note, the SPI SCLK pin on the teensy also has the LED on it (pin 13). At first I couldn't figure out why the LED was blinking so erratically, and then I realized I was seeing the SCLK signal on the LED. Is there any way to disable the LED on the teensy? Not a deal breaker, just curious. Thanks again for your help Paul!
 
Thanks for the followup. :)

I've submitted a pull request to Adafruit, so hopefully these edits will become part of the official version.
 
Can you confirm if the modified code still works on Arduino Uno or other normal Arduino boards?

Adafruit is asking for a verification before they accept the change into the official version of this library. I don't actually have one of these VS1053 boards for testing.
 
Sorry to revive an old thread, but quick question:

what pin did you/should I use as the data request/interrupt pin? (t3)

Thanks,
David
 
Last edited:
Never mind the interrupt pin question...I see that the t3 can use any pin as the interrupt pin (yeah t3!). I chose pin 7...just because it felt right.

I'm having troubles, however. If I use the method for playing sounds from beginning to end with no interrupt (playFullFile) everything seems to behave OK. If I use the interrupt method (startPlayingFile) (which would allow the t3 to do other things at the same time), playback is very questionable. If I set up a simple loop with a 1s delay, the playback often craps out after about 10 or so loops (and the LED on the t3, which shares the SPI clock pin, becomes pretty sporadic, then finally stops blinking). In the sketch below I have a method where key presses will trigger sound files. With the startplayingfile method I can interrupt the playback of one sound file with another...but this often lasts for only a few tries before playback stops/freezes.

@Brandon: did you ever have much luck with the startPlayingFile method? Just curious before I start pestering the adafruit folks.

I also don't have much luck with playing back 44/16 wav files. It'll play the file once, with a bit of distortion, then all playback stops.

And if I could find a method that would stop playback that worked (setting playingMusic to false doesn't seem to work as suggested on the adafruit board)...well that would be lovely.

And setting the volume doesn't seem to work at all.

Paul, when is that fancy audio board of yours going to be finished?!?! ;)

Attached is my code for testing/observing the above in case that helps. btw: which SD library should I be using? I don't recall installing anything special for the T3.

Thanks in advance for any advice!
David

Code:
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>

// define the pins used
//#define CLK 13       // SPI Clock, shared with SD card
//#define MISO 12      // Input data, from VS1053/SD card
//#define MOSI 11      // Output data, to VS1053/SD card
// Connect CLK, MISO and MOSI to hardware SPI pins. 

// These can be any pins:
#define RESET 9      // VS1053 reset pin (output)
#define CS 10        // VS1053 chip select pin (output)
#define DCS 8        // VS1053 Data/command select pin (output)
#define CARDCS 4     // Card chip select pin
// DREQ should be an Int pin, see http://arduino.cc/en/Reference/attachInterrupt
#define DREQ 7       // VS1053 Data request, ideally an Interrupt pin


Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(RESET, CS, DCS, DREQ, CARDCS);

byte serialIn;
byte playbacknumber;

void setup() {
  Serial.begin(9600);

  musicPlayer.begin(); // initialise the music player
  SD.begin(CARDCS);    // initialise the SD card

  musicPlayer.setVolume(0,0);

  musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT);  // DREQ int
}

void loop() {

  while (Serial.available() > 0) { // mail call
    serialIn = Serial.read();
    if (serialIn == '1') {
      playbacknumber = 1;
    }
    if (serialIn == '2') { 
      playbacknumber = 2;
    }
    if (serialIn == '3') {
      playbacknumber = 3;
    }    
  } // end while

  // options below allow input via serial (1, 2, 3)
  if (playbacknumber == 1) {
    //musicPlayer.startPlayingFile("track001.mp3");
    musicPlayer.playFullFile("track001.mp3");
    playbacknumber = 0;
  }
  if (playbacknumber == 2) {
    //musicPlayer.startPlayingFile("track002.mp3");
    musicPlayer.playFullFile("track002.mp3");
    playbacknumber = 0;
  }
  if (playbacknumber == 3) {
    // can't get this to work...in theory should only work when "startplayingfile" has been called
    musicPlayer.playingMusic = false;
    playbacknumber = 0;
  }

  // uncomment below to loop playback of a sound file
  
  //musicPlayer.playFullFile("track001.mp3");
  //delay(1000);
  

}
 
Last edited:
OK, I'm not sure the adafruit library is fully cooked. Playing a sound file seems pretty hit or miss (especially after a power cycle), and volume control even doubly so. Playing wav files is all miss. Is the standard SD library adequate for the T3? That's the main thing I'm thinking could be an issue (having never worked with SD cards on a T3 or any other micro for that matter).

Thanks,
David
 
how about the 3.1?

I took a quick look and added code for Teensy.

Please give this copy a try, and let me know if it works? (I don't have the actual VS1053 board here for testing)

https://github.com/PaulStoffregen/Adafruit_VS1053_Library

Hi Paul - first and foremost thanks for everything so far - your teensy board is my favorite toy.
now - I've been trying to operate the vs1053B as an ogg recorder with the teensy 3.1 (aruino ide 1.0.5 and teensiduino 1.19) and this very library.
and I've noticed I'm missing bits on the reading from the chip.
if I read the raw data in an OGG file that I recorded using an arduino mega (using notepad++) the file starts with OggS, but with the teensy is starts with '33)...
OggS
0x4f 0x67 0x67 0x53
01001111011001110110011101010011

'33)
0x27 0x33 0x33 0x29
00100111001100110011001100101001

or if we put them next to each other:
01001111011001110110011101010011
00100111001100110011001100101001

it looks as if I shifted the words one bit too much (and lost an LSB 1 too)...
I've dug deep into the library itself and I'm still not sure how you defined the interrupts or the timers for __arm__ processors

I'm fairly sure it's just a matter of a simple timer change that ruins recording.

p.s. also trying to compile to lower speeds 16/8/4/2 give: Sd2Card.cpp:77:2: error: #error "MK20DX128 bus frequency must be 48 or 24 MHz"
is it a 1.0.5 problem?

thanks a bunch.
 
Well - I'll answer my own post. seems the problem was in the SPI.
I used the record example so I knew it worked (plus tested on UNO and mega properly).
the SD was easily verifiable with various tests (though no SdFat), seems the SPI needed: SPI.setClockDivider(SPI_CLOCK_DIVx); (and many thanks to t3andy - http://forum.pjrc.com/threads/1156-Teensy-3-SPI-Basic-Clock-Questions?p=2344&viewfull=1#post2344).
it took a while to figure out the only real difference between the Arduino and teensy for this board was the clock rate. so that set me up on the path for SPI discovery. it still seems to freeze every now and then for no good reason but for now it at least records some ogg.
 
Well - I'll answer my own post. seems the problem was in the SPI.
I used the record example so I knew it worked (plus tested on UNO and mega properly).
the SD was easily verifiable with various tests (though no SdFat), seems the SPI needed: SPI.setClockDivider(SPI_CLOCK_DIVx); (and many thanks to t3andy - http://forum.pjrc.com/threads/1156-Teensy-3-SPI-Basic-Clock-Questions?p=2344&viewfull=1#post2344).
it took a while to figure out the only real difference between the Arduino and teensy for this board was the clock rate. so that set me up on the path for SPI discovery. it still seems to freeze every now and then for no good reason but for now it at least records some ogg.
[/I]

Hi! I tried every combintation of x in SPI.setClockDivider(SPI_CLOCK_DIVx); using the most recent version of the VS1053 library from Adafruit. but I still can't get any MP3-Played using this breakout board and a Teensy 3.1. Anybody an idea how to fix this?
Thanks!
 
more data?

[/I]

Hi! I tried every combintation of x in SPI.setClockDivider(SPI_CLOCK_DIVx); using the most recent version of the VS1053 library from Adafruit. but I still can't get any MP3-Played using this breakout board and a Teensy 3.1. Anybody an idea how to fix this?
Thanks!

could you please post your code?
how did you set up the SPI control legs? because the example in adafruit is for uno and the teensy has other SPI legs:
#define RESET 17 // VS1053 reset pin (output)
#define CS 10 // VS1053 chip select pin (output)
#define DCS 16 // VS1053 Data/command select pin (output)
#define CARDCS A0 // Card chip select pin
#define DREQ A1 // VS1053 Data request, ideally an Interrupt pin

let me know how that turned out for you.
 
could you please post your code?
how did you set up the SPI control legs? because the example in adafruit is for uno and the teensy has other SPI legs:
#define RESET 17 // VS1053 reset pin (output)
#define CS 10 // VS1053 chip select pin (output)
#define DCS 16 // VS1053 Data/command select pin (output)
#define CARDCS A0 // Card chip select pin
#define DREQ A1 // VS1053 Data request, ideally an Interrupt pin

let me know how that turned out for you.

HI,

Thank you for your fast reply!

I measured the SPI-Clock @ 8 MHz on the teensy 3.1, which might be to high since the max SPI-Clock of the VS1053 is listed @ 5 MHz. Nevertheless, even changing the SPI_CLOCK_DIV in the adafruit lib didn't change much.

To answer your questions:

Pin-Setup on Teensy 3.1:
VS1053-AdafruitBreakout ==> Teensy 3.1​
CLK ==> 13​
MISO ==> 12​
MOSI ==> 11​
DREQ ==> 5​
CS ==> 20​
Reset ==>23​
DCS(XDCS) ==> 22​
CARDSCS(SDCS) ==> 21​

Sourcecode:
I didn't modify much in the end starting from the Adafruit exemple code...

Code:
/*************************************************** 
  This is an example for the Adafruit VS1053 Codec Breakout

  Designed specifically to work with the Adafruit VS1053 Codec Breakout 
  ----> https://www.adafruit.com/products/1381

  Adafruit invests time and resources providing this open source code, 
  please support Adafruit and open-source hardware by purchasing 
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.  
  BSD license, all text above must be included in any redistribution
 ****************************************************/

// include SPI, MP3 and SD libraries
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>

#define CORE_TEENSY 1
//SPI.setClockDivider(SPI_CLOCK_DIV2);

#define CLK 13 // SPI Clock, shared with SD card
#define MISO 12 // Input data, from VS1053/SD card
#define MOSI 11 // Output data, to VS1053/SD card
#define RESET 23 // VS1053 reset pin (output)
#define CS 20 // VS1053 chip select pin (output)
#define DCS 22 // VS1053 Data/command select pin (output)
#define DREQ 5 // VS1053 Data request pin (into Arduino)
#define CARDCS 21 // Card chip select pin
Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(RESET, CS, DCS, DREQ, CARDCS);

void setup() {
  Serial.begin(9600);
 // pinMode(RESET, OUTPUT);
 // digitalWrite(RESET, HIGH);
  Serial.println("Adafruit VS1053 Simple Test");

  if (! musicPlayer.begin()) { // initialise the music player
     Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
     while (1);
  }
  Serial.println(F("VS1053 found"));
  
  SD.begin(CARDCS);    // initialise the SD card
  
  // Set volume for left, right channels. lower numbers == louder volume!
  musicPlayer.setVolume(20,20);

  // Timer interrupts are not suggested, better to use DREQ interrupt!
  //musicPlayer.useInterrupt(VS1053_FILEPLAYER_TIMER0_INT); // timer int

  // If DREQ is on an interrupt pin (on uno, #2 or #3) we can do background
  // audio playing
  musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT);  // DREQ int
  
  // Play one file, don't return until complete
  Serial.println(F("Playing track 001"));
  musicPlayer.playFullFile("track001.mp3");
  // Play another file in the background, REQUIRES interrupts!
  Serial.println(F("Playing track 002"));
  musicPlayer.startPlayingFile("track002.mp3");
}

void loop() {
  // File is playing in the background
  if (musicPlayer.stopped()) {
    Serial.println("Done playing music");
    while (1);
  }
  if (Serial.available()) {
    char c = Serial.read();
    
    // if we get an 's' on the serial console, stop!
    if (c == 's') {
      musicPlayer.stopPlaying();
    }
    
    // if we get an 'p' on the serial console, pause/unpause!
    if (c == 'p') {
      if (! musicPlayer.paused()) {
        Serial.println("Paused");
        musicPlayer.pausePlaying(true);
      } else { 
        Serial.println("Resumed");
        musicPlayer.pausePlaying(false);
      }
    }
  }

  delay(100);
}

Thank you a lot for your time!
 
Last edited:
testing again.

HI,

Thank you for your fast reply!

I measured the SPI-Clock @ 8 MHz on the teensy 3.1, which might be to high since the max SPI-Clock of the VS1053 is listed @ 5 MHz. Nevertheless, even changing the SPI_CLOCK_DIV in the adafruit lib didn't change much.

since it's a code from adafruit it's probably very well tested. you changed little in it but leg numbers I trust.
so here is what I'd try next:

SPI.setClockDivider(SPI_CLOCK_DIV4 );
at the end if the setup.

and check for full path to the mp3 file.
 
I measured the SPI-Clock @ 8 MHz on the teensy 3.1, which might be to high since the max SPI-Clock of the VS1053 is listed @ 5 MHz. Nevertheless, even changing the SPI_CLOCK_DIV in the adafruit lib didn't change much.

You don't need to mess about with clock dividers (which can be complex, when implementations try to second-guess what that might mean to get some sort of AVR-compatibility). Instead, if you want a 5MHz clock (or 4Mhz or whatever you decide to use) just set that explicitly with SPISettings.

See
http://www.pjrc.com/teensy/td_libs_SPI.html
 
Last edited:
temporary workaround: underclock to 24 MHz

[/I]

Hi! I tried every combintation of x in SPI.setClockDivider(SPI_CLOCK_DIVx); using the most recent version of the VS1053 library from Adafruit. but I still can't get any MP3-Played using this breakout board and a Teensy 3.1. Anybody an idea how to fix this?
Thanks!

I have a temporary solution of under clocking the Teensy to 24 MHz. (http://www.shashankteotia.in/vs1053b-teensy-3-1)
 
Thanks Paul,

I have a couple of these from last Christmas, will have to pull them out and give this a go again. Cheers
 
Reviving this old thread..........
I am trying out the Adafruit VS1053 Breakout with the Teensy 3.1
I am using the library for the post above and the Player_simple example
I have problems understanding which pins of breakout to connect to the Teensy...???
First I un-commented the lines
#define CLK 13 and connected SCLK to Teensy pin 13..the LED one
#define MISO 12 and connected MISO to Teensy pin 12
#define MOSI 11 and connected MOSI to Teensy pin 11
Then connected.....
RST to teensy pin 9
CS to teensy pin 10
SDCS to teensy pin 8
SDCD to teensy pin 4
DREQ to teensy pin 3
VCC to teensy 5 v pin
GND to teensy GND
Using Rout and Lout and AGND for audio output

Sketch compiles without error
Uploads to teensy OK and appears to run with the following Serial Monitor output

Adafruit VS1053 Simple Test
VS1053 found
Playing track 001
Playing track 002
Done playing music

But no sound ......I do get a click in headphones or speakers

My confusion is the proper use of the pins of VS1053 breakout

CS, SDCD, XDCS, SDCS, DREQ, RST ..........

would be grateful for any help please................
 
Finally worked out a combination of connections that works...........

VS1053 Breakout >>>>> Teensy 3.1 pin

MOSI >>>>>>>> Pin11
MISO >>>>>>>> Pin12
SCLK >>>>>>>> Pin13
DREQ >>>>>>>> Pin3
XDCS >>>>>>>> Pin8
SDCS >>>>>>>> Pin4
CS >>>>>>>>> Pin10
RST >>>>>>>>> Pin9

Have only played MP3 and WAV files

Both play OK.

But if critical about tail ends of files and how file starts to play, delays gaps etc.......Then....
MP3 files long fade out tail end of file that is playing and a short fade in of next file to play.....??? Results in gaps of about 15 milliseconds ++.
WAV files....the tail end of the file playing gets distorted for approx the last 1 - 2 milliseconds. Start of next to play is OK.
This was just tested on successive startPlayingFile playing in a loop. And the WAV file did not always start to play, some starts missed.

Teensy3.1 and Audio Adaptor board would seem to be faster and cleaner at playing fast transition between sound files than the Adafruit VS1052 Breakout...???
 
Paul wrote...........

Please give this copy a try and let me know how it works for you?

https://github.com/PaulStoffregen/Ad...VS1053_Library


Paul, You were wanting some feedback on this so I gave it a go using Teensy3.1 and got it working as per my last 2 posts....with a bit of "pin fiddling"

But as described I am getting a similar problem as I was getting a few weeks ago when trying out the teensy with the Audio adaptor in that there was distortion as a file stopped playing and another one started. You sorted that with your fix to the Teensy audio library PlaySDwav etc last week.

I am wondering is this the same type of problem although now using the Adafruit/Arduino library for the VS1053 BOB.

If so do you think this is a library software problem or a problem in the chip internal routines.??

I assume the Teensy Audio Library reads the file from the SD over SPI and sends it over I2S to the Audio Adaptor Board and then to output.

With the VS1053 BOB I assume the Teensy reads the file from the SD over SPI and sends it to the VS1052 chip by sharing the SPI bus. Is that controlled by DREQ.?

If I were to use the Teensy Audio Library etc instead, might that sort the distortion problem, but are there any routines already in teensy libraries for sharing the SPI etc that would work with the VS1053. OR how do I go about it.?

The advantage of using this BOB is that it can decode "if it works properly" several types of audio MP3, WAV etc and has MIDI sounds on board and also stereo analog out. I think the I2S is only for output to another I2S device.? I would just like to get it working without the distortion on the SD files.

I tried the MIDI and it worked....I let it boot into MIDI mode and with a sketch sending some MIDI commands was able to play various sounds on demand etc.

Thanks for your help and I look forward to getting this sorted..............
 
I have got this Adafruit board playing with Teensy3.1. It plays OK but I have found somethig perculiar when trying to play in a loop and wait for playingMusic to stop and then go round the loop again. The while statement does not seem to see the change to false when playing comes to end of file except I have something in the While eg a delay of something. And it is the same for using if statement....simplified example of loop code below. Each behave the same. Using the first while it just plays the file to the end once and waits indefinately. The second and third do same if no delay in loop. With the delay it works OK and repeats the loop. This is still using the play_simple example from the VS1053 library.


void loop() {

musicPlayer.startPlayingFile("KHz1.wav");

//xxx 1 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

while (musicPlayer.playingMusic);

//xxxx 2 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

/*

while (musicPlayer.playingMusic)
{
delay(1);
}

*/

//xxxx 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

/*

doagain:
if (musicPlayer.playingMusic)
{
delay(1);
goto doagain;
}

*/

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


}
 
Status
Not open for further replies.
Back
Top