I am using a Mega 2560 with the Adafruit Music Maker shield stacked on the Mega and an IR sensor to pick up IR signals. Both items work well apart but when I combine them my IR values are received but are 8(mostly) digit hex gibberish. The repeats still come through as FFFFFFFF in hex. The MP3 player plays randomly from my SD card. This is my first project with arduino and I have cobbled this code together from the sources listed below. I have figured out a lot of bugs and hardware issues on my journey so far but I think that this one is over my head. I can't find anything on the surface that is causing it and digging into the libraries leaves me reeling. Can anyone help by telling me, or better, showing me what I am doing wrong here. I'd be happy to share the larger code which works without the addition of the MP3 if anyone is interested.
I have removed all of the nonessential code that causes no issues as the process of debugging has continued.( capacitive touch, volume motor control, relays, remote codes, input modes --these all work)
Thank you for taking the time to read this. Any help would be appreciated.
Luke
/*
This code is to control an audio tube amp. Arduino Mega2560 will be turned on by switch, and it activates a relay that provides 5VDC (via wallwart) to a block of relays that control the input signal that the tube amp sees and AC power to the tube amp. Interface with the arduino is with; 5 capacitive touch input buttons, one power(amp), mute, as well as an up button and a down button for FM tuning. These are controlled by an adafruit 12 input capacitive touch MPR121 breakout. This part works and meshes nicely with the others. I have removed the code, as well as all of the rest that doens't cause any problems. Oh yeah, the arduino will be running a TEA5767 FM breakout (haven't tackled that one yet) and a MP3 shield. An IR sensor (arduino brand 38Khz) will recieve signals from a simple Apple remote for power(amp), volume up and down, a left arrow and down arrow for FM tuning and/or MP3 functions TBD... The volume is controlled manually at the amp by a Bourns motorized potentiometer or by remote.
IR library and code http://www.righto.com/2009/08/multi-protocol-infrared-remote-library.html A big thank you to Ken Shirriff!
// MPR121 cap. touch sensor breakout from Adafruit. Library and code https://learn.adafruit.com/adafruit-mpr121-12-key-capacitive-touch-sensor-breakout-tutorial/wiring
// The code ideas for motor control came from http://www.hifivision.com/diy/44275-simple-ir-remote-motorized-alps-pot-directly-using-arduino.html
Code for MP3 VS1053 shield from Adafruit https://learn.adafruit.com/adafruit-music-maker-shield-vs1053-mp3-wav-wave-ogg-vorbis-player/installing-software
Code for MP3 Random play lifted from this forum page. See last entry. https://forums.adafruit.com/viewtopic.php?f=31&t=60742&hilit=music+maker+track
*/
#include <IRremote.h>
#include <IRremoteInt.h>
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>
// These are the pins used for the music maker shield
#define SHIELD_RESET -1 // VS1053 reset pin (unused!)
#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
#define DREQ 3 // VS1053 Data request
Adafruit_VS1053_FilePlayer musicPlayer =
Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);
File path;
//remote
int RECV_PIN = 27;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600); //initialize the serial monitor
uint32_t seed = 0; // Generate random seed
for ( uint8_t i = 10 ; i ; i-- )
{
seed = ( seed << 5 ) + ( analogRead( 0 ) * 3 );
}
randomSeed( seed ); //set random seed
irrecv.enableIRIn(); // Start the IR receiver
musicPlayer.begin(); // initialise the music player
SD.begin(CARDCS); // initialise the SD card
musicPlayer.setVolume(40, 40); // Set volume for left, right channels. lower numbers == louder volume!
musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT); //I tried the timer0 interupt and it works the same so I don't think that this is the problem.
}
void loop()
{
path = SD.open("/");
File result2;
char* MP3 = selectRandomFileFrom( path, result2 );
musicPlayer.startPlayingFile(MP3); // Start playing a file.
delay(1000);
while (musicPlayer.playingMusic)
{
// file is now playing in the 'background' so now's a good time
// to do something else like handling LEDs or buttons :)
int i = random(255);
if (irrecv.decode(&results))
{
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}
}
}
// Function to select random mp3
char* selectRandomFileFrom( File dir, File result2 )
{
File entry;
int count = 0;
dir.rewindDirectory();
while ( entry = dir.openNextFile() )
{
if ( random( count ) == 0 ) {
result2 = entry;
}
entry.close();
count++;
}
return result2.name(); // returns the randomly selected file name
}