Hi people, I'm completely newbie to arduino and a need to create an eletronic system to a sculpture I'm developing. On the sculpture there will be a button that when pressed plays a random noise from my recorded songs. Once again, I'm completely virgin to this tool, do you guys think this project is easily doable on Arduino plataform for a newcomer? Is there any clue to which area should I start studying in order to develop a project like that? Any help will make me happy, THANKS!
Are you just playing a random music file and thats it? There are MP3 modules that are extremely easy to setup with an Arduino. There are also standalone MP3 modules that might do what you need that don't require an Arduino.
What have you searched for so far?
These modules are easy to use, just simple Serial.write(0x01); to 0xC7 to select a track from 1 to 199, or 0 for a random track.
HazardsMind:
Are you just playing a random music file and thats it? There are MP3 modules that are extremely easy to setup with an Arduino. There are also standalone MP3 modules that might do what you need that don't require an Arduino.What have you searched for so far?
Simple as that, first I thought about adapting a button to a music player but I couldn't program it to start playing in shuffle. As far as my knowledge in arduino goes, I've only learned on how to program the blinking LED on the mainboard. I've searched mp3 players made with Arduino but couldn't understand much of it. What standalone module you were talking about? Thank you
This chip can be used as both a standalone module, and be controlled by an arduino.
Hello again, I finally brought my tools to star the project.
Assembled both the sd card module and the vs1053 mp3 module in correct in correct order and when I've inserted the code:
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>
// 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 SPI - Arduino Reference "Connections"
// These can be any pins:
#define RESET 8 // VS1053 reset pin (output)
#define CS 9 // VS1053 chip select pin (output)
#define DCS 6 // VS1053 Data/command select pin (output)
#define CARDCS 4 // Card chip select pin arduino
#define DREQ 7 // VS1053 Data request, ideally an Interrupt pin
Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(RESET, CS, DCS, DREQ, CARDCS);
void setup() {
Serial.begin(9600);
Serial.println("Adafruit VS1053 Simple Test");
musicPlayer.begin(); // initialise the music player
SD.begin(CARDCS); // initialise the SD card
musicPlayer.dumpRegs();
// Set volume for left, right channels. lower numbers == louder volume!
musicPlayer.setVolume(00,00);
// musicPlayer.useInterrupt(VS1053_FILEPLAYER_TIMER0_ INT); // timer int
musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT ); // DREQ int
Serial.println("Calling playFullFile");
// Play one file, don't return until complete
musicPlayer.playFullFile("s1.mp3");
//musicPlayer.playFullFile("s2.mp3");
Serial.println("setup done");
// Play another file in the background, REQUIRES interrupts!
// musicPlayer.startPlayingFile("s1.mp3");
}
void loop() {
// File is playing in the background
if (! musicPlayer.playingMusic)
Serial.println("Done playing music");
delay(1000);
}
This is what I get on the serial monitor:
Adafruit VS1053 Simple Test
Mode = 0xFFFF
Stat = 0xFFFF
ClkF = 0xFFFF
Vol. = 0xFFFF
Calling playFullFile
setup done
Done playing music
Done playing music
Done playing music
Done playing music
Done playing music
Done playing music
Done playing music
Done playing music
I get no sound on the audio output jack, what's wrong??
Thank you all
Im not familiar with that MP3 model so I don't know what is needed to make it work. However from your code, I don't see where the MP3 library is talking to your SD card.
Did it come with any other sample codes to try out?
HazardsMind:
Im not familiar with that MP3 model so I don't know what is needed to make it work. However from your code, I don't see where the MP3 library is talking to your SD card.Did it come with any other sample codes to try out?
Yeah, it came with this one:
#include <SD.h>
#include <SPI.h>
//for sd test
File root;
int i=0;
int fileNumber=0;
//set vs1003 pins
int xCs=9;
int xReset=8;
int dreq= 7;
int xDcs=6;
int sspin=10; //sspin for mega
int volume=0x01;//set volume here
int DREQ=digitalRead(dreq);
char* playlist[]={
};
File mp3;
void setup(){
delay(10);
//set 1003
SPI.begin();
SPI.setBitOrder(MSBFIRST); //send most-significant bit first
SPI.setDataMode(SPI_MODE0);
SPI.setClockDivider(SPI_CLOCK_DIV16);
pinMode(7,INPUT);
pinMode(8,OUTPUT);
pinMode(6,OUTPUT);
pinMode(9,OUTPUT);
digitalWrite(sspin,HIGH);
Mp3Reset();
Serial.begin(9600);
Serial.print("Set SD card...");
while (!SD.begin()){
}
Serial.println("sd ready.");
root = SD.open("/");
printDirectory(root, 0);
Serial.print("Totally ");
Serial.print(fileNumber);
Serial.print(" file(s)");
Serial.println();
}
void loop(){
play("s1.mp3");
play("s2.mp3");
play("s3.mp3");
play("s4.mp3");
play("s5.mp3");
play("s6.mp3");
play("s8.mp3");
play("s9.mp3");
play("s10.mp3");
play("s11.mp3");
play("s12.mp3");
play("s13.mp3");
play("s14.mp3");
}
void play(char* playplay){
int val,i;
mp3=SD.open(playplay);
delay(10);
for(i=0;i<548;i++){
digitalWrite(sspin,HIGH);
val =mp3.read();
digitalWrite(xDcs,LOW);
SPI.transfer(val);
digitalWrite(xDcs,HIGH);
digitalWrite(sspin,LOW);
}
if(DREQ==HIGH){
while(mp3.available()){
for(i=0;i<32;i++){
digitalWrite(sspin,HIGH);
val =mp3.read();
digitalWrite(xDcs,LOW);
SPI.transfer(val);
digitalWrite(xDcs,HIGH);
digitalWrite(sspin,LOW);
}
delayMicroseconds(35);
}
}
mp3.close();
}
void Mp3Reset(){
digitalWrite(xReset,LOW);
delay(100);
digitalWrite(xCs,HIGH);
digitalWrite(xDcs,HIGH);
digitalWrite(xReset,HIGH);
commad(0X00,0X08,0X04); //write into mode
delay(10);
if(DREQ==HIGH){
commad(0X03,0XC0,0X00);//set VS1003 clock
delay(10);
commad(0X05,0XBB,0X81);//set VS1003 sample rate at 44kps stero
delay(10);
commad(0X02,0X00,0X55);//set duplicate sound? 重音
delay(10);
commad(0X0B,volume,volume);//highest volumn at 0x0000, and lowest at 0xFEFE
delay(10);
SPI.transfer(0);
SPI.transfer(0);
SPI.transfer(0);
SPI.transfer(0);
digitalWrite(xCs,HIGH);
digitalWrite(xReset,HIGH);
digitalWrite(xDcs,HIGH);
digitalWrite(sspin,LOW);
}
}
void commad(unsigned char addr,unsigned char hdat,unsigned char ldat )
{
int DREQ=digitalRead(dreq);
if(DREQ==HIGH){
digitalWrite(xCs,LOW);
SPI.transfer(0X02);
SPI.transfer(addr);
SPI.transfer(hdat);
SPI.transfer(ldat);
digitalWrite(xCs,HIGH);
}
}
void printDirectory(File dir, int numTabs) {
while(i<6){
File entry = dir.openNextFile();
if (! entry) { // no more files
i++;
}
for (uint8_t i=0; i<numTabs; i++) {
Serial.print('\t');
}
Serial.print(entry.name());
if (entry.isDirectory()){
Serial.println("/");
printDirectory(entry, numTabs+1);
}
else if(entry.size()) {// files have sizes, directories do not
Serial.print("\t\t");
Serial.println(entry.size(), DEC);
fileNumber++;
}
}
}
Suddenly It started playing music, guess it was something wrong with the audio jack. Now the only problem is that the audio is stuttering, anyone would know what could it be?