I am working on a simple setup to play some mp3 files thru an onld rotary phone based on the number you dial. I have the number dialing part working but I am having difficulty getting the volume to play correctly. It works fine when I test on my MacBook Pro USB but when I diconnect from the computer and power it from an Anker USB Power Bank the volume is about 10 times as high! Any ideas why this might be happening?
Here is my code (just for playing a loop of different mp3 files):
#include <Arduino.h>
#include <SoftwareSerial.h>
#include <DFMiniMp3.h>
#define RX_PIN 10
#define TX_PIN 11
class Mp3Notify;
SoftwareSerial secondarySerial(RX_PIN, TX_PIN);
typedef DFMiniMp3<SoftwareSerial, Mp3Notify> DfMp3;
DfMp3 dfmp3(secondarySerial);
bool notPlaying = true;
uint8_t maxVolume = 3;
class Mp3Notify
{
public:
static void PrintlnSourceAction(DfMp3_PlaySources source, const char* action)
{
if (source & DfMp3_PlaySources_Sd)
{
Serial.print("SD Card, ");
}
if (source & DfMp3_PlaySources_Usb)
{
Serial.print("USB Disk, ");
}
if (source & DfMp3_PlaySources_Flash)
{
Serial.print("Flash, ");
}
Serial.println(action);
}
static void OnError(DfMp3& mp3, uint16_t errorCode)
{
// see DfMp3_Error for code meaning
Serial.println();
Serial.print("Com Error ");
Serial.println(errorCode);
}
static void OnPlayFinished(DfMp3& mp3, DfMp3_PlaySources source, uint16_t track)
{
Serial.print("Play finished for #");
Serial.println(track);
notPlaying = true;
}
static void OnPlaySourceOnline(DfMp3& mp3, DfMp3_PlaySources source)
{
PrintlnSourceAction(source, "online");
}
static void OnPlaySourceInserted(DfMp3& mp3, DfMp3_PlaySources source)
{
PrintlnSourceAction(source, "inserted");
}
static void OnPlaySourceRemoved(DfMp3& mp3, DfMp3_PlaySources source)
{
PrintlnSourceAction(source, "removed");
}
};
void waitMilliseconds(unsigned long maxWaitTime)
{
unsigned long start = millis();
while ((millis() - start) < maxWaitTime)
{
// calling mp3.loop() periodically allows for notifications to be handled without interrupts
dfmp3.loop();
delay(1);
}
}
void setup()
{
Serial.begin(9600);
Serial.println("initializing...");
dfmp3.begin();
waitMilliseconds(100);
uint16_t volume = dfmp3.getVolume();
waitMilliseconds(100);
Serial.print("start volume ");
Serial.println(volume);
dfmp3.setVolume(maxVolume);
waitMilliseconds(100);
volume = dfmp3.getVolume();
Serial.print("new volume ");
Serial.println(volume);
waitMilliseconds(100);
uint16_t count = dfmp3.getTotalTrackCount(DfMp3_PlaySource_Sd);
Serial.print("files ");
Serial.println(count);
waitMilliseconds(1000);
Serial.println("starting...");
}
void millisecondsLoop()
{
unsigned long maxWaitTime = 85000;
notPlaying = false;
unsigned long start = millis();
while ((millis() - start) < maxWaitTime)
{
// calling mp3.loop() periodically allows for notifications to be handled without interrupts
dfmp3.loop();
if (notPlaying)
{
return;
}
delay(1);
}
}
void loop()
{
uint16_t count = dfmp3.getTotalTrackCount(DfMp3_PlaySource_Sd);
for (uint16_t i = 1; i <= count; i++)
{
Serial.print("track: ");
Serial.println(i);
dfmp3.playMp3FolderTrack(i);
millisecondsLoop();
}
}
Her is the wiring, just a pic but it is very basic ...
Let me know if you have an idea when the volume would change when I change the power supply.
Thanks
Greg

