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?