Pages: 1 ... 6 7 [8] 9 10
 71 
 on: Today at 08:27:29 pm 
Started by mike_plano - Last post by wbrokow1
Yes same issue with nano.
Worked 1 -2 times then no communication

 72 
 on: Today at 08:22:43 pm 
Started by Aero98 - Last post by Aero98
I first want to say I am new to Arduino and programming so I am having a little trouble grasping some of the concepts, or at least that is what I think I am doing wrong, amoung other things I am sure.  smiley-roll-sweat

I have gotten some help from a few places, but I have been given more of vague references that I do not understand full, but I have included a copy of my code below.

I am using a Adafruit "Music Maker" MP3 Shield for Arduino w/3W Stereo Amp and an Arduino Mega 2560. I am trying to get the Adafruit_VS1053, "player_interrupts" code to run and play a random MP3 stored on SD card inserted into a Adafruit "Music Maker" MP3 Shield. I have not been able to figure out how to tell the code to play a random file. I can only get it to play if I specify the file name specifically in the code. I have tried placing a txt file, (MP3s.txt) on the SD card and read that into an array to pass to the line but I have not been able to get that to work either. The latest version of my code tries to take advantage of the random() function to get the file names; I played around with it and got it to run without errors, but when I upload it to my Arduino, it plays the beep, lists the files on the SD card, and stops.

Code:
// include SPI, MP3 and SD libraries
#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, see http://arduino.cc/en/Reference/attachInterrupt
#define DREQ 3       // VS1053 Data request, ideally an Interrupt pin

Adafruit_VS1053_FilePlayer musicPlayer =
  Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);

void setup() {
  Serial.begin(9600);
  Serial.println("Adafruit VS1053 Library Test");
  // initialise the music player
  if (! musicPlayer.begin()) { // initialise the music player
    Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
    while (1);
  }
  Serial.println(F("VS1053 found"));

  musicPlayer.sineTest(0x44, 500);    // Make a tone to indicate VS1053 is working

  if (!SD.begin(CARDCS)) {
    Serial.println(F("SD failed, or not present"));
    while (1);  // don't do anything more
  }
  Serial.println("SD OK!");
 

// list files
  printDirectory(SD.open("/"), 0);
  // Set volume for left, right channels. lower numbers == louder volume!
  musicPlayer.setVolume(20, 20);

  if (! musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT))
    Serial.println(F("DREQ pin is not an interrupt pin"));
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void loop() {
  // put your main code here, to run repeatedly:
  File path = SD.open("/");
  File results;
  char* MP3 = selectRandomFileFrom( path, results );
  Serial.println(MP3);
  delay(1000);
// Start playing a file, then we can do stuff while waiting for it to finish
  if (! musicPlayer.startPlayingFile(MP3)) {
    Serial.println("Could not open file: ");
    //Serial.println(MP3);
    //while (1);
  }
  Serial.println(F("Started playing"));

  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 :)
    Serial.print(".");
    delay(1000);
  }
  Serial.println("Done playing music");
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// File listing helper
void printDirectory(File dir, int numTabs) {
  while (true) {

    File entry =  dir.openNextFile();
    if (! entry) {
      // no more files
      //Serial.println("**nomorefiles**");
      break;
    }
    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 {
      // files have sizes, directories do not
      Serial.print("\t\t");
      Serial.println(entry.size(), DEC);
    }
    entry.close();
  }
}

// Function to select random mp3
char* selectRandomFileFrom( File dir, File result ) {
  File entry;
  int count = 1;

  dir.rewindDirectory();

  while ( entry = dir.openNextFile() ) {
    if ( random( count ) == 0 ) {
      result = entry;
    }
    entry.close();
    count++;
  }
}

I am using this version of the code:
Code:
// Start playing a file, then we can do stuff while waiting for it to finish
  if (! musicPlayer.startPlayingFile(MP3)) {
    Serial.println("Could not open file: ");
    //Serial.println(MP3);
    //while (1);
  }
  Serial.println(F("Started playing"));

  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 :)
    Serial.print(".");
    delay(1000);

because I need to run a couple of servos while the MP3 are playing.

 73 
 on: Today at 08:22:25 pm 
Started by KhalifaGad - Last post by Qdeathstar
where did that code come from (post the code and links)

 74 
 on: Today at 08:21:18 pm 
Started by Qdeathstar - Last post by Qdeathstar
I was gonna ask paul for some advice.... your example gives me some ideas, but I think I would still need some for loops to use that.

The value for each address of the LED strip is stored in an array, which I've divided into four zones that need to be able to be controlled separately.

ideally, I'd like to be able to change the zone size easily without having to change all my functions, but that is not a requirement.

 75 
 on: Today at 08:21:06 pm 
Started by KhalifaGad - Last post by Delta_G
It looks like a function call.

 76 
 on: Today at 08:20:12 pm 
Started by Mashley - Last post by Delta_G
Mash
NO a for loop is NOT an interrupt routine. 

If you don't use attachInterrupt() in your code then the issue I mentioned is irrelevant.  Pay it no attention.

Another good reason to post all of your code.  So people don't have to try to guess how the rest of it works. 

 77 
 on: Today at 08:19:35 pm 
Started by shayo - Last post by shayo
Interesting. It is good to know I'm not the only one who experienced this problem.
I wrote to SainSmart. Let's see what they say. I hope they can reproduce the problem on their side as well.
If you have time to test the Oct 1st hypothesis, it would be great.
Were your boards also manufactured by SainSmart, or by other third party company?

Shay

 78 
 on: Today at 08:17:09 pm 
Started by electricviolin - Last post by electricviolin
I want to get it from TI because they also give 'free samples'

I want to test out how this works before I go full on. Is there anything that I can buy directly from TI from their website that will work just the same?

 79 
 on: Today at 08:16:25 pm 
Started by ChrisPSR - Last post by Peter_n
A test: Windows 10 Preview 64-bit installed. Arduino 1.5.8 BETA zip-file unzipped in Downloads folder. Drivers installed. Arduino started. There was a SmartScreen warning, but I choose "Run Anyway". Arduino was started in 4 seconds (slow harddisk, 5 years old computer). Also a firewall question popped up. The preferences.txt is in C:\Users\<name>\AppData\Roaming\Arduino15 and I chould change settings. The harddisk was tested a few weeks ago (it took 4 hours with GSmartControl in linux) and is in perfect condition.

As you can see, everything is working as it is supposed to.

 80 
 on: Today at 08:16:11 pm 
Started by CaptainBisquick - Last post by CaptainBisquick
R1 and C1 form a low pass filter to operate the transistor to vary the power. That's what I'm thinking of replacing with the MCP4725 DAC.

Pages: 1 ... 6 7 [8] 9 10