Hi. I've got an Arduino Uno with Sparkfun's mp3 player shield working nicely- when the light level falls below a threshold it plays a track. Perfect. I've loaded the same code into a Lilypad mp3 unit, with additional code for the onboard amp, but it won't work. Appears to calibrate but no sound output.
LDR between A0 and 3.3V out, with 10k to ground also from A0
Here's the code that works on the shield. Modified from one of the arduino tuorials
Below it is the additional bits I added due to the onboard amp.
#include <SPI.h>
#include <SdFat.h>
#include <SdFatUtil.h>
#include <SFEMP3Shield.h>
SdFat sd;
SFEMP3Shield MP3player;
// These constants won't change:
const int sensorPin = A0; // pin that the sensor is attached to
const int calibratePin = 5; // pin that the calibrate LED is attached to
const int threshold = 10;
// variables:
int sensorValue = 0; // the sensor value
int sensorMin = 1023; // minimum sensor value
int sensorMax = 0; // maximum sensor value
void setup() {
// initialize serial communications:
Serial.begin(9600);
//start the shield
sd.begin(SD_SEL, SPI_HALF_SPEED);
MP3player.begin();
// turn on LED to signal the start of the calibration period:
pinMode(5, OUTPUT);
digitalWrite(5, LOW);
// calibrate during the first five seconds
digitalWrite(5, HIGH);
while (millis() < 5000) {
sensorValue = analogRead(sensorPin);
// record the maximum sensor value
if (sensorValue > sensorMax) {
sensorMax = sensorValue;
}
// record the minimum sensor value
if (sensorValue < sensorMin) {
sensorMin = sensorValue;
}
}
// signal the end of the calibration period
digitalWrite(5, LOW);
}
void loop() {
// read the sensor:
sensorValue = analogRead(sensorPin);
// apply the calibration to the sensor reading
sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 255);
// in case the sensor value is outside the range seen during calibration
sensorValue = constrain(sensorValue, 0, 255);
//if analogue value is low enough, play track
if (sensorValue > threshold) {
MP3player.playTrack(3);
Serial.println(F("THRESHOLD! playing track "));
}
else {
MP3player.stopTrack();
}
//print the value for ref:
Serial.println(sensorValue);
}
I have added
const int EN_GPIO1 = A2; // Amp enable + MIDI/MP3 mode select
const int SD_CS = 9; // Chip Select for SD card
and
pinMode(EN_GPIO1,OUTPUT);
digitalWrite(EN_GPIO1,LOW); // MP3 mode / amp off
// Turn on the amplifier chip:
digitalWrite(EN_GPIO1,HIGH);
delay(2);
// Set the VS1053 volume. 0 is loudest, 255 is lowest (off):
MP3player.setVolume(10,10);
Any suggestions gratefully accepted!