Code Monkey home page Code Monkey logo

music_shield's Introduction

Music Shield V2.0 Build Status

Music Shield V2.0

Music Shield is an audio encoder/decoder compatible with Arduino, Seeeduino,
Seeeduino Mega and Arduino Mega. It is based on the VC1053B chip, which enabled
it to play sound files from SD card and do short-time recording as well.

This library is for MusicShield hardware version 2.0.

For hardware version 1.0, please visit the wiki page for demo codes.

The music player reads data from SD card and then feed into the VS1053 chip via SPI bus. This is done in TIMER1's ISR with a interval of 2ms. This job has a high priority and uses the cpu exclusively. In the spare cpu time, player does some process control, like play/pause.

Usage:

  1. Downlaod this library. Two way to do this:
    a. click the "Download ZIP" link right down at this page;
    b. use a git client to make a clone of "https://github.com/Seeed-Studio/Music_Shield.git";

  2. Copy files(unzip if you downloaded a zip) into a dir named "MusicPlayer";

  3. Copy dir "MusicPlayer" into Arduino IDE's library dir;

  4. Coding guide:
    (1) make sure SD lib and SPI lib was installed;
    (2) include header files like example do;
    (3) call player.begin() in setup() function;
    (4) call other setup APIs or config APIs in setup() function;
    (5) call player.play() in loop() function;
    (6) call other config APIs in loop() function;
    (7) then forget the music player and insert your own routine into setup() or loop() function, your own routine will be executed in available cpu time.

  5. Three different ways to play music:
    a. play a song with its name by calling the function player.playOne(songfile);
    b. add some songs into the default empty playlist(player.addToPlaylist());
    c. play all the songs in SD card root dir by calling the function player.scanAndPlayAll().

Notice PLS:

a. Libs dependency: SD lib, SPI lib;
b. TIMER1 is used;
c. As the player need handling some control event(e.g.: key control, playlist processing ) circularly, you should call player.play() in the arduino loop function. Otherwise, the player will not play;
d. ALL THE SONGS TO PLAY SHOULD BE IN THE ROOT DIRECTORY AND SONG NAME CAN NOT CONTAIN WIDE CHAR;
e. setup APIs can only be called in setup() function.

Control:

short press - toggle play and pause
long press (more than 2 seconds) - stop
long press in stop mode - record short press in record mode - stop recording
short press left in play mode - shift to previous song
long press left in play mode - fast rewind
short press right in play mode - shift to next song
long press right in play mode - fast forward
short press up - volume plus 6
press up and hold - volume up continuously
short press up - volume minus 6
press down and hold - volume down continuously

Default setting:
play mode = NORMAL play
keys = ENBALE
scan available digit pins = DISABLE
scan available analog pins= DISABLE
create an empty playlist

API:

-- global variables --
MusicPlayer player                          -- MusicPlayer class instance

-- setup APIs --
void        MusicPlayer::begin(void)        -- Music player initialization routine
void        MusicPlayer::playOne(char *songName)
                                            -- Add a song to play list , equivalent to call addToPlaylist once
boolean     addToPlaylist(char *songName)   -- Add a song to play list
void        scanAndPlayAll(void)            -- Scan all the songs in TF card and add them to play list
void        attachDigitOperation(int pinNum, void (*userFunc)(void), int mode)
                                            -- attach a callback to digital pin event
void        attachAnalogOperation(int pinNum, void (*userFunc)(void))
                                            -- attach a callback to analog pin event

-- config APIs --
void        setVolume(unsigned char volume) -- setup volume (range: 0x00 - 0xfe )
void        adjustVolume(boolean UpOrDown, unsigned char NumSteps = 6)
                                            -- adjust volume up or down by step (UpOrDown=true for up)
void        setPlayMode(playMode_t playmode)-- set play mode (modes: refer to keywords.txt Constants)
boolean     deleteSong(char *songName)      -- delete a song from play list
void        keyEnable(void)                 
void        keyDisable(void)
void        analogControlEnable(void)
void        digitalControlEnable(void)

-- operate APIs --
void        play(void)
void        opPlay(void)  
void        opPause(void) 
void        opResume(void)
void        opStop(void)  
void        opVolumeUp(void)  
void        opVolumeDown(void)  
void        opNextSong(void)    
void        opPreviousSong(void)
void        opFastForward(void)
void        opFastRewind(void) 

For more information, please refer to wiki page.


This software is written by Jack Shao ([email protected]) for seeed studio
and is licensed under The MIT License. Check License.txt for more information.

Contributing to this software is warmly welcomed. You can do this basically by
forking, committing modifications and then pulling requests (follow the links above
for operating guide). Adding change log and your contact into file header is encouraged.
Thanks for your contribution.

Seeed Studio is an open hardware facilitation company based in Shenzhen, China.
Benefiting from local manufacture power and convenient global logistic system,
we integrate resources to serve new era of innovation. Seeed also works with
global distributors and partners to push open hardware movement.

Analytics

music_shield's People

Contributors

baorepo avatar hansen0314 avatar killingjacky avatar lanselambor avatar per1234 avatar pillar1989 avatar yexiaobo-seeedstudio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

music_shield's Issues

Playlist is empty

Hello,

I am trying to get the "creatList" example to work. However, the serial monitor just keeps saying "Playlist is empty". I am using a Kingston 2GB Micro SD Card formatted as FAT16. I have 11 mp3 files in the root folder of the sd card. Can you provide any insight as to what is going on?

Thanks

Error Types

I am getting error types in my arduino IDE. The errors are pointing to the MusicPlayer.h file

error: 'playingstatetype playingState', declared using anonymous type, is used but never defined [-fpermissive]
extern playingstatetype playingState;

error: 'typedef volatile enum playingstatetype' does not refer to the unqualified type, so it is not used for linkage [-fpermissive]
playingstatetype;

error: 'ctrlState_t ctrlState', declared using anonymous type, is used but never defined [-fpermissive]
extern ctrlState_t ctrlState;

error: 'typedef volatile enum ctrlState_t' does not refer to the unqualified type, so it is not used for linkage [-fpermissive]
ctrlState_t;

do you know why this may be ?

Arduino freezes during setVolume call

Hi

I'm using this library with the LinkSprite Music Shield v1.2 (https://www.maplin.co.uk/p/music-shield-for-arduino-n99dg) and an Arduino Mega. I'm using multiple calls to setVolume with a short delay between them (~40ms) to fade the volume of playing tracks up and down.

This works, but quite frequently the whole unit freezes up (sound stops and serial output stops). I've narrowed this as happening during the call to VS10XX::writeRegister in the middle of the SPI.transfer calls. If I place Serial.prints between each line the debug output looks like the call is getting interrupted and a second call is started?

Is there any way that some sort of interrupt could be being serviced that is calling the same method while it is mid-way through? (Presumably sending a dodgy command to the shield and causing everything to crash/freeze?)

Any suggestions gratefully received!

Andy...

Adding external button for controlling recording doesn't work after recording.

Hi,

I've wired up and set up a second switch to pin 22 of the arduino mega. I set it up to set the same flag as the pause/play button. It works to pause and play the music, and begin the recording. Once the recording starts, the new button no longer has any input.

Is there an additional initialization setup during/after the recording stage that re-initializes the IO differently than during normal startup?

Edit: my own answer lies in the DigitalInputControl.ino that I missed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.