adafruit-vs1053

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
roadshark
 
Posts: 652
Joined: Sun Nov 29, 2015 5:53 am

Re: adafruit-vs1053

Post by roadshark »

Hi Rick, I am trying to upload a video file for you. It is an video(a.v.i) file. When I choose file and then add file it uploads but then my post disappears. Do you have size restrictions on the file size allowed? I am starting to develop a marble rolling game for the children. They have to roll a marble through targets.(Holes in wood.) I would need a way of sensing when a marbles goes into a hole, thinking a light sensor or infra red sensor. When the beam is broken it will need to update a score display. What do you think and do you have the equipment I need. Again I would use the mp3 music maker to generate the sound effects.
Last edited by roadshark on Mon Jan 18, 2016 12:20 am, edited 1 time in total.

User avatar
roadshark
 
Posts: 652
Joined: Sun Nov 29, 2015 5:53 am

Re: adafruit-vs1053

Post by roadshark »

tried it as mpg still no luck (34.1 meg).

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: adafruit-vs1053

Post by adafruit_support_rick »

Sorry, you can't upload videos here. Only images. If you can upload it to a video sharing site, like youtube, you can post a link here.

You can use a break-beam sensors, like this:
https://www.adafruit.com/products/2167

User avatar
roadshark
 
Posts: 652
Joined: Sun Nov 29, 2015 5:53 am

Re: adafruit-vs1053

Post by roadshark »

Thx. I looked at the sensors they are I believe, exactly what I need. So a marble rolls through a hole to score points. There are 5 holes. When the marble rolls through a hole the following needs to happen. 1. a score is updated and displayed. 2. A sound is played ( a unique sound for each hole). 3. A L.E.D. flashes. A manual reset button to start the game again. I would not need as many digital read pins as my previous game so may be a mega is not needed. What hardware would you suggest? When the marble goes through the hole it goes down a slight incline so as not to stop in front of the sensor.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: adafruit-vs1053

Post by adafruit_support_rick »

So you need, what, 7 pins just for the Music Maker. 5 pins for the break-beams, and 5 pins for the LEDs. Two pins for an I2C display, and one pin for a reset. A Uno has 20 pins, so you can just squeeze it in. I guess if it were me, I might think about sticking with a Mega.

On the other hand, you could use an MCP23017 I2C port expander for the LEDs and break-beams, and stick with the Uno. That would be cheaper.
https://www.adafruit.com/products/732

User avatar
roadshark
 
Posts: 652
Joined: Sun Nov 29, 2015 5:53 am

Re: adafruit-vs1053

Post by roadshark »

Hi there,
Think I will stick with the mega. Have ordered the music shields and Ir sensors. Thx for the advice.

User avatar
roadshark
 
Posts: 652
Joined: Sun Nov 29, 2015 5:53 am

Re: adafruit-vs1053

Post by roadshark »

Hi Rick,
I was looking at your range of 7 segment displays. The one that I wanted (green) was out of stock. I put in a notify me when available. I downloaded the the libraries but am a bit confused.
"You can download the Adafruit LED Backpack library from github . To download click the DOWNLOADS button in the top right corner, rename the uncompressed folder Adafruit_LEDBackpack. Check that the Adafruit_LEDBackpack folder contains Adafruit_LEDBackpack.cpp and Adafruit_LEDBackpack.h.
Yep did this. I put the folder Adafruit_LEDBackpack in my arduino library.
Now the next part....Did this.

"You'll also need to download the Adafruit GFX library - rename it Adafruit_GFX and install it as the LED backpack library. Close all open IDE windows and restart the IDE."

HOWEVER do I put the folder Adafruit_GFX in the folder Adafruit LEDBackpack or do I put in the library as LED backpack library????? In other words should the word in the sentence be 'in' instead of 'as'???

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: adafruit-vs1053

Post by adafruit_support_rick »

Here, "as" means "in the same way". GFX just goes in as a regular library - it doesn't go inside of the LED backpack folder. Just put it at the top level of the libraries folder.

User avatar
roadshark
 
Posts: 652
Joined: Sun Nov 29, 2015 5:53 am

Re: adafruit-vs1053

Post by roadshark »

Hi Rick,
I have some questions if you have the time. Do I need to start a new post?
I have purchased the following products...infra red break beam sensors, music player shield and 8 gig card, seven segment 1.2 inch 4 digit display with back pack, 3 watt 4ohm speakers and a AA battery pack. I will be using a mega. (Will this have enough power to run the display, play sounds and the 6 infra red sensors?)
This is the game I plan to develop. A two meter by 600mm wide table with sides. At the end of the table is a target. The target will have six mouse type holes cut. These will be painted as zombie grave stones. A zombie will be painted above each of the holes. The object is to roll a large marble down the table to go into a hole. The holes vary slightly in width with the narrower hole worth more points. So the points will be in order across the board 10, 50, 100, 500, 20, 5. The children will have 5 marbles to roll.
As the marble enters a hole there is a slope so the marble can not stay on the edge of the hole.(Block the Sensor). As the marble rolls down the slope to be collected at the end of the board it will roll past an infra red break beam sensor. When this happens 4 things need to happen. 1. The score will need to be calculated and sent to the display. 2. A zombie sound particular to that zombie needs to be played. (Or would it be more interesting if this was a random zombie sound) 3. LEDs lights will need to flash in the zombies eyes.. 4 The sensor will need to be reset. I have started to develop the code. I am using parts of the code from my Simpsons game so if you see code I do not need please delete.When I compile what I have done so far I get this message
Arduino: 1.6.5 (Windows 7), Board: "Arduino/Genuino Mega or Mega 2560"

zombie_game1.ino: In function 'void loop()':
zombie_game1:73: error: 'debounceRead' was not declared in this scope
zombie_game1:82: error: expected initializer before 'uint8_t'
zombie_game1:86: error: 'pin' was not declared in this scope
zombie_game1:86: error: 'pinState' was not declared in this scope
zombie_game1:93: error: 'pinState' was not declared in this scope
zombie_game1:93: error: return-statement with a value, in function returning 'void' [-fpermissive]
'debounceRead' was not declared in this scope
I am assuming this piece of code needs to be above the void setup??? (Do I need to debounce an infra red break beam?)
The display uses digital pins 20 and 21. Are these declared in the included library or do I have to declare them in the code?
I also need to declare some pins as out put for the L.E.Ds , blinking in the zombies eyes that was hit which will require two leds for each zombie 12 pins. Have I done this correctly? How do I get the leds to work off the pin like the music does. For example if zombie one was hit. The sound for zombie one plays but I need to blink its eyes as well!
At the end of the student rolling 5 marbles the game needs to be reset for the next student.

Code: Select all

 This is an example for the Adafruit VS1053 Codec Breakout

  Designed specifically to work with the Adafruit VS1053 Codec Breakout
  ----> https://www.adafruit.com/products/1381

  Written by Limor Fried/Ladyada for Adafruit Industries.
  BSD license, all text above must be included in any redistribution
 ****************************************************/

// 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)
#define CARDCS 4     // Card chip select pin
#define DREQ 3       // VS1053 Data request, ideally an Interrupt pin
//seven segment displays
// Conditional #include doesn't work due to Arduino IDE shenanigans.
#include <Wire.h> // Enable this line if using Arduino Uno, Mega, etc.

#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
Adafruit_7segment matrix = Adafruit_7segment();

Adafruit_VS1053_FilePlayer musicPlayer =
  // create shield-example object!
Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);
int gameScore = 0;
int sensorPins[] = {14, 15, 16, 17, 18, 19,22};//I.Red break beam sensors, reset.
#define pinCount (sizeof(sensorPins)/sizeof(int))
int ledPins[] = { 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,41};//led lights for zombies eyes.
#define pinCount2 (sizeof(ledPins)/sizeof(int))


char* zombieSounds [] = {"zombie001.mp3", "zombie002.mp3", "zombie003.mp3", "zombie004.mp3", "zombie005.mp3", "zombie006.mp3", "zomreset.mp3"};

//There are three other files on the card   wotd0001.mp3, wotd0002 and wotd0003.mp3 not part of the above array.
void setup() {
  Serial.begin(9600);
  
 SD.begin(CARDCS);    // initialise the SD card

   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"));

  // Set volume for left, right channels. lower numbers == louder volume!
  musicPlayer.setVolume(1, 1);
  musicPlayer.playFullFile("wotd0001.mp3");//Is it possible to play one of three random sounds here as the game starts?

  // Timer interrupts are not suggested, better to use DREQ interrupt!
  //musicPlayer.useInterrupt(VS1053_FILEPLAYER_TIMER0_INT); // timer int

  // If DREQ is on an interrupt pin (on uno, #2 or #3) we can do background
  // audio playing
  musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT);  // DREQ int
  for (int thisPin = 0; thisPin < pinCount; thisPin++) {
    pinMode(sensorPins[thisPin], INPUT_PULLUP);
    for (int thisPin = 0; thisPin< pinCount; thisPin++){
      pinMode(ledPins[thisPin], OUTPUT);
    }
  }

}


void loop() {
  

  for (int thisPin = 0; thisPin < pinCount; thisPin++)
  {
    if (debounceRead(sensorPins[thisPin]) == LOW)
    { 
      musicPlayer.playFullFile(zombieSounds[thisPin]);
        
      }

}

uint8_t debounceRead(int pin)
  uint8_t pinState = digitalRead(pin);
  uint32_t timeout = millis();
  while ((millis() - timeout) < 10)
  {
    if (digitalRead(pin) != pinState)
    {
      pinState = digitalRead(pin);
      timeout = millis();
    }
  }

  return pinState;
}


My problem how to instruct the mega to write a score to the seven segment 4 digit display and reset back to zero when game is over. To make the zombies eyes blink...

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: adafruit-vs1053

Post by adafruit_support_rick »

This compiles and is a little closer to what you want. Check it out:

Code: Select all

/****************************************************
 This is an example for the Adafruit VS1053 Codec Breakout

  Designed specifically to work with the Adafruit VS1053 Codec Breakout
  ----> https://www.adafruit.com/products/1381

  Written by Limor Fried/Ladyada for Adafruit Industries.
  BSD license, all text above must be included in any redistribution
 ****************************************************/

// 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)
#define CARDCS 4     // Card chip select pin
#define DREQ 3       // VS1053 Data request, ideally an Interrupt pin
//seven segment displays
// Conditional #include doesn't work due to Arduino IDE shenanigans.
#include <Wire.h> // Enable this line if using Arduino Uno, Mega, etc.

#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
Adafruit_7segment matrix = Adafruit_7segment();

Adafruit_VS1053_FilePlayer musicPlayer =
  // create shield-example object!
Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);
int gameScore = 0;
int ballCount = 0;

int sensorPins[] = {14, 15, 16, 17, 18, 19,22};//I.Red break beam sensors, reset.
#define sensorPinCount (sizeof(sensorPins)/sizeof(int))

int scores[sensorPinCount] = {5, 10, 50, 100, 500, 20, 5};

int ledPins[sensorPinCount][2] = { {30, 31}, {32, 33}, {34, 35}, {36, 37}, {38, 39}, {40,41}};//led lights for zombies eyes.

char* zombieSounds [sensorPinCount] = {"zombie001.mp3", "zombie002.mp3", "zombie003.mp3", "zombie004.mp3", "zombie005.mp3", "zombie006.mp3", "zomreset.mp3"};

uint8_t debounceRead(int pin)
{
  uint8_t pinState = digitalRead(pin);
  uint32_t timeout = millis();
  while ((millis() - timeout) < 10)
  {
    if (digitalRead(pin) != pinState)
    {
      pinState = digitalRead(pin);
      timeout = millis();
    }
  }

  return pinState;
}

void zombieBlink(int zombieID)
{
  for (int blinks = 0; blinks < 5; blinks++)
  {
    digitalWrite(ledPins[zombieID][0], HIGH);
    delay(200);
    digitalWrite(ledPins[zombieID][0], LOW);
    digitalWrite(ledPins[zombieID][1], HIGH);
    delay(200);
    digitalWrite(ledPins[zombieID][1], LOW);
  }

}

//There are three other files on the card   wotd0001.mp3, wotd0002 and wotd0003.mp3 not part of the above array.
void setup() {
  Serial.begin(9600);
  
 SD.begin(CARDCS);    // initialise the SD card

   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"));

  // Set volume for left, right channels. lower numbers == louder volume!
  musicPlayer.setVolume(1, 1);
  musicPlayer.playFullFile("wotd0001.mp3");//Is it possible to play one of three random sounds here as the game starts?

  // Timer interrupts are not suggested, better to use DREQ interrupt!
  //musicPlayer.useInterrupt(VS1053_FILEPLAYER_TIMER0_INT); // timer int

  // If DREQ is on an interrupt pin (on uno, #2 or #3) we can do background
  // audio playing
  musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT);  // DREQ int
  for (int thisPin = 0; thisPin < sensorPinCount; thisPin++) {
    pinMode(sensorPins[thisPin], INPUT_PULLUP);
  }
  for (int thisPin = 0; thisPin< sensorPinCount; thisPin++){
    pinMode(ledPins[thisPin][0], OUTPUT);
    pinMode(ledPins[thisPin][1], OUTPUT);
  }

  matrix.begin(0x70);
}


void loop() {

  for (int thisPin = 0; thisPin < sensorPinCount; thisPin++)
  {
    if (debounceRead(sensorPins[thisPin]) == LOW)
    { 
      
      gameScore = gameScore + scores[thisPin];
      ballCount++;

      matrix.print(gameScore, DEC);
      matrix.writeDisplay();

      musicPlayer.playFullFile(zombieSounds[thisPin]);
      zombieBlink(thisPin);

      if (ballCount == 5)  //game over
      {
        ballCount = 0;
        gameScore = 0;
        delay(5000);
        matrix.print(gameScore, DEC);
        matrix.writeDisplay();
      }
        
    }
  }

}

User avatar
roadshark
 
Posts: 652
Joined: Sun Nov 29, 2015 5:53 am

Re: adafruit-vs1053

Post by roadshark »

Hi Rick,
Thank you heaps. I will work on temporarily wiring the hardware to see if it works the way that I hope. In the game the children will roll 5 balls however they may or may not go in a hole. So I do not need to keep score of how many balls have been rolled just the score of ones that went in the holes. A manual reset button would then be pushed to reset the score. SOrry for my ambiguous description. (In some instances when I want children to work on their fine motor skills they might roll 10 balls,) The game will finish when the child has use all the allocated balls.
I really wanted to use a green display but they were out of stock so I ordered yellow ones. I was just informed today that green ones are now in stock. I do believe my order is already on the way so I guess that is life some times. If yellow does not look good I will order the green ones. I have 3 start up tracks that can be used when the game is turned on. Is there any way I can randomly choose which track is played? (wotd0001.mp3, wotd0002.mp3, wotd0003.mp3)
Also will the mega be able to handle all the power requirements of the displays, sensors and sounds???

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: adafruit-vs1053

Post by adafruit_support_rick »

The Mega can handle the displays and sensors, but it won't have enough oomph to power your amplifier. You'll need a separate supply for that.
Or, run everything on a single 5V supply and split the power between the amp and the Mega.

To play a random sound, add another array with your sound file names, then use the random function to pick one.

Code: Select all

char* startupSounds[] = {"wotd0001.mp3", "wotd0002.mp3", "wotd0003.mp3"};
#define numStartupSounds  (sizeof(startupSounds)/sizeof(char*))
In setup, add this:

Code: Select all

  matrix.begin(0x70);

  //init score display
  matrix.print(0);
  matrix.writeDisplay();

  //initialize random number generator (only do this once)
  randomSeed(analogRead(A0)); 

  //play random startup sound
  musicPlayer.playFullFile(startupSounds[random(numStartupSounds)]);
 

User avatar
roadshark
 
Posts: 652
Joined: Sun Nov 29, 2015 5:53 am

Re: adafruit-vs1053

Post by roadshark »

Hi Rick,
The music player shield sits on the mega. I assume I would make sure the pin that draws the 5 volts and the ground are not connected (to the mega) and run these to the shared power supply. The power supply I was planning to use is 6 AA batteries. this gives me 9 v. I assume the mega has some sort of power regulator built in to drop the power to 5 volts. Would it be safe to power the music maker shield (with the inbuilt 3 watt amplifier) with this voltage or should I use a separate 5 volt power supply?
With thanks.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: adafruit-vs1053

Post by adafruit_support_rick »

Oh, you're using the shield with amp? In that case, it's fine to run it directly off the Mega. It's designed to work that way. So you should be good to go.
I checked the voltage regulator on the mega, and it's good for up to 1A, so you can run everything from the Mega. Your 9V battery pack should be fine.

User avatar
roadshark
 
Posts: 652
Joined: Sun Nov 29, 2015 5:53 am

Re: adafruit-vs1053

Post by roadshark »

Great. I will get to work when I get all the parts from u guys and let you know how it goes. The simpsons game is going well.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”