Spark Core + Shield Shield + Seeedstudio Music Shield V2.0

I’m trying code an arduino project to Spark.

It’s Like Spark Core + Shield Shield + Seeedstudio Music Shield V2.0. And I has two problem.


One Problem is SPI pins not work.
I try used SparkCore-SD Library: https://github.com/technobly/SparkCore-SD to write thing to SD Card on Seeedstudio Music Shield bord, not work.

Shield Shield PIN MAPPING Like:
10 - A2
11 - A5
12 - A4
13 - A3

according seeedstudio wiki, Pins Used for SPI Interface:
D10 - SPI Chip Select;
D11 - SPI MOSI;
D12 - SPI MISO;
D13 - SPI SCK;

my use SparkCore-SD example code but get error:

Initializing SD card…Error: CMD0
Error: Sd2Card::init()
initialization failed!

my code like:

#include "application.h"
#include "SD.h"

File myFile;

// SOFTWARE SPI pin configuration - modify as required
// The default pins are the same as HARDWARE SPI
const uint8_t chipSelect = A2;    // Also used for HARDWARE SPI setup
const uint8_t mosiPin = A5;
const uint8_t misoPin = A4;
const uint8_t clockPin = A3;

void setup()
{
  Serial.begin(115200);
  while (!Serial.available());

  Serial.print("Initializing SD card...");
   
  // Initialize HARDWARE SPI with user defined chipSelect
  if (!SD.begin(chipSelect)) {
    Serial.println("initialization failed!");
    return;
  }

//  Comment out above lines and uncomment following lines to use SOFTWARE SPI
/*
  // Initialize SOFTWARE SPI
  if (!SD.begin(mosiPin, misoPin, clockPin, chipSelect)) {
    Serial.println("initialization failed!");
    return;
  }
*/

  Serial.println("initialization done.");
  
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("test.txt", FILE_WRITE);
  
  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to test.txt...");
    myFile.println("testing 1, 2, 3.");
  // close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
  
  // re-open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");
    
    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

void loop()
{
  // nothing happens after setup
}

It’s Pins Mapping problem?


And another problem:
I try Seeduino Music Shield library: https://github.com/mitallast/arduino-vs1053 but get some error like:
error: ‘SPDR’ was not declared in this scope
error: ‘SPSR’ was not declared in this scope
error: ‘_BV’ was not declared in this scope
error: ‘SdFat’ does not name a type

the application.cpp code is:

#if defined (SPARK)
#include "application.h"
#include "SdFat.h"
#include "vs1053.h"
#else
#include <SPI.h>
#include <SdFat.h>
#include <vs1053.h>  
#include <LiquidCrystal.h>
#endif

SdFat sd;
VS1053 vs1053;
// LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

void setup() {
  Serial.begin(115200);
  SPI.begin();
  if (!sd.begin(10, SPI_HALF_SPEED)) sd.initErrorHalt();
  vs1053.begin();
  // lcd.begin(16, 2);
}


char filename[32];
SdFile song;

void loop() {
  song.openNext(sd.vwd(), O_READ);
  playSong();
}
void playSong(){
  byte buf[32];
  Serial.println("soft reset");
  vs1053.softReset();
  
  song.getFilename(filename);
  Serial.println(filename);
  // lcd.setCursor(0, 1);
  // lcd.print(filename);
  int i=0;
  while(1){
    i = song.read(buf, 32);
    vs1053.write_data(buf, i);
    if(i<32){
      vs1053.write_register(SPI_MODE, SM_OUTOFWAV);
      vs1053.send_zeroes(2048);
      break;
    }
    vs1053.await_data_request();
  }  
  song.close();
  Serial.println("done");
  vs1053.printDetails();
}

Anyone can help, or I has something missing?

Could you try any of the examples provided with the library first.

As I see in the samples there is usually an SD/card object instance and a call to the <instance>.init() methode of the object which I can’t seem to find in your code.


OK, SD.begin() does it internally, but by trying out the samples or doing each of the individual steps, that SD.begin() bundles, seperately might help pin pointing the cause.

BTW: How is your SD formated? Is it FAT/FAT32 or any other format?

I had try simply use https://github.com/technobly/SparkCore-SD example, and it work.

I think my problem is wrong pins mapping? Or as Seeedstudio Music Shield I should link vs1053 chip first then control SD Card?

And there are no library work with Spark Core + Seeedstudio Music Shield…

When I suggested to use the examples, I thought of using it with the shield, to see if the shield works with the library.
Additionally you obviously tested the lib with an SD card adapter - is it the same microSD that you used in the shield?
Have you got the correct format on the microSD?

Another problem might be the lacking A3 pin on the Shield shield, since this would be required as Chip Select for the VS1053.

1 Like

@rhoulay, I ported an Adafruit_VS1053 breakout library. Using the SparkIntervalTimer library makes porting the Seeedstudio library relatively straight forward. I can do the porting over the next couple of days if you are interested :smile:

3 Likes

@peekay123
Yes, I checked the your adafruit vs1053 spark library.

I have experience with arduino but not spark core. And I think seeedstudio music shield library very different with adafruit. It’s lack document and office library hard work with Spark Core…

@ScruffR thanks for your suggestion.

I had worked with spark core SD library, so I think the SD formatting is OK.

And I will check A3 pin later…

Without intending to rob @peekay123 the pleasure to port this lib, I’d just like to point out some things you could look at, if you’d like to take a stab at porting it yourself.

VS1053.h

#define VS_RESET A0
#define VS_DREQ  A1
//// these need to be reassigned for the Core 
#if !defined(SPARK)
#define VS_DCS   A2
#define VS_CS    A3
#else
#define VS_DCS   A6    // A2 Shield shield maps to Core's A6
#define VS_CS    A3    // this needs hardware, since Core's A3 maps to
                       // D13/SPI-SCK on Shield shield
                       // You could use a jumper wire from a free pin to the 
                       // N/C A3 on the Shield shield
#endif
1 Like

!!! Crazy !!!

I get Seeedstudio Music Shield V2.0 work with Adafruit_VS1053_Library ( https://github.com/adafruit/Adafruit_VS1053_Library ) + Arduino Mega

Just change pins as:

#define SHIELD_RESET  A0      // VS1053 reset pin (unused!)
#define SHIELD_CS     A3      // VS1053 chip select pin (output)
#define SHIELD_DCS    A2      // VS1053 Data/command select pin (output)

// These are common pins between breakout and shield
#define CARDCS 10     // Card chip select pin
// DREQ should be an Int pin, see http://arduino.cc/en/Reference/attachInterrupt
#define DREQ A1       // VS1053 Data request, ideally an Interrupt pin

Adafruit_VS1053_FilePlayer musicPlayer = 
// create shield-example object!
Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);

and then I try @peekay123’s VS1053 Spark Library: https://github.com/pkourany/Adafruit_VS1053_Library:

// include SPI, MP3 and SD libraries
#if defined (SPARK)
#include "application.h"
#include "Adafruit_VS1053.h"
#include "SD.h"
#else
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>
#endif	//SPARK
// 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. 
// See http://arduino.cc/en/Reference/SPI "Connections"

#if defined (SPARK)
// These are the pins used for the breakout example
// #define BREAKOUT_RESET  D2      // VS1053 reset pin (output)
// #define BREAKOUT_CS     D3     // VS1053 chip select pin (output)
// #define BREAKOUT_DCS    D4      // VS1053 Data/command select pin (output)
// These are the pins used for the music maker shield
#define SHIELD_RESET  A0      // VS1053 reset pin (unused!)
#define SHIELD_CS     A3      // VS1053 chip select pin (output)
#define SHIELD_DCS    A6      // VS1053 Data/command select pin (output)

// These are common pins between breakout and shield
#define CARDCS A2     // Card chip select pin
// DREQ should be an Int pin, see http://arduino.cc/en/Reference/attachInterrupt
#define DREQ A1       // VS1053 Data request, ideally an Interrupt pin

#else //Arduino
// These are the pins used for the breakout example
#define BREAKOUT_RESET  9      // VS1053 reset pin (output)
#define BREAKOUT_CS     10     // VS1053 chip select pin (output)
#define BREAKOUT_DCS    8      // VS1053 Data/command select pin (output)
// These are the pins used for the music maker shield
#define SHIELD_CS     7      // VS1053 chip select pin (output)
#define SHIELD_DCS    6      // VS1053 Data/command select pin (output)

// These are common pins between breakout and shield
#define CARDCS 4     // Card chip select pin
// DREQ should be an Int pin, see http://arduino.cc/en/Reference/attachInterrupt
#define DREQ 3       // VS1053 Data request, ideally an Interrupt pin
#endif


Adafruit_VS1053_FilePlayer musicPlayer = 
  // create breakout-example object!
  // Adafruit_VS1053_FilePlayer(BREAKOUT_RESET, BREAKOUT_CS, BREAKOUT_DCS, DREQ, CARDCS);
  // create shield-example object!
  Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);
  
void setup() {
  Serial.begin(9600);
  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("007.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);
}

But get error:

Couldn't find VS1053, do you have the right pins defined?

@ScruffR above Spark code I jumper wire Spark A3 to Music Shield A3:

As pointed out in the comment in my code snippet above, you won’t have a lot of fun using the Core’s A3 pin, since this is also used as SPI-SCK.
Similarly you can’t use A2 in your code as SHIELD_DCS, since this is used by the Shield shield aswell - rather use A6 as pointed out in my snippet too. (Edit: Just seen in your second code, you’re using A6 :+1:)

You should find one pin that is not used for anything else in your code or any library you’re using and define this one in VS1053.h as your choice and then jumper wire it from the shield header to the shield header.

2 Likes