Home

MP3 Player - RobotShop

image

Contents

1. Try playing a few different songs in the TEST directory Reading File Names In the next code example file names in the TEST directory are read and stored in an array This way file names can be displayed on the LCD and files can be referenced by their position in the directory Prior to this point you needed to specify the exact name of the file in order to play it Note that in the directory structure on the flash drive the first entry in any directory is always DIR This is a link back to the directory above the selected directory and will be important for later code Finelude mxapa h include usart h include mp3 h tinclyde Ied h ne mala vOsel a DURNA char count 0 Inmitralize a counter for keeping track of names 9 char name 931 Alena cela Zea string tot storing file names 10 char type Initialize a variable for storing file types 11 usart init C00 Imitialize the USART tO 9600 baud 12 13 14 15 16 We 18 19 20 Zil 22 23 lec init p initialize the LED mp3 command MP3 SHORT MODE initialize the module to short command mode mp3 file MP3 CHANGE DIRECTORY TEST Change to the TEST directory while 1 1 Mps tile name name Styoe count Read file in the count position and increment Count by il it count recount o fit count exceeds no of files in TEST set count to 0 ed text name Display name on the LCD dela
2. Brown 2 i t VCC Red RXD Orange Ce TXD Yellow PB4 MISO 18 CTS Green PB5 SCK H VMUSIC2 GND GND Figure 11 Schematic for adding buttons Figure 12 One way to wire the MP3 connection Adding New Files In order take advantage of the new code you will need to add a top level directory to your flash drive and additional lower level directories Insert your USB flash drive into your computer s USB port 2 Navigate to the flash drive s top level directory and add a new directory called MUSIC You may give this directory another name but this will require a small modification to the example code 3 Place your existing TEST directory into the MUSIC directory You may give the TEST directory a new title as long as it is less than nine characters 4 Create at least two additional directories and place them under the MUSIC directory 5 Add at least three MP3 files to each of your new directories Navigating to a Specific Directory The following code enables you to scroll through your MUSIC directory using one of the buttons on your board This code puts together features of the previous examples and allows you to have up to 128 different directories in MUSIC Two new custom functions are introduced display_next_item and initialize_directory The display_next_item function returns the name and type of the next file directory in the current directory and then display the name on the LCD The in
3. MP3 Player Add an MP3 module to the board and design a user interface Contents e Overview e Challenge 1 Control the MP3 Module with Your Computer o Collecting Your Components o Stocking the USB Flash Drive o Building the Circuit o Setting up a Terminal Emulator o Sending Commands to the MP3 Module e Challenge 2 Control the MP3 Module with the Microcontroller Collecting your Components Building the Circuit Playing Songs Changing Volume Using Custom MP3 Commands Playing a Specific File Reading File Names Playing Files by Variable Name o Counting the Files in a Directory e Challenge 3 Use Buttons to Control the MP3 Player o Adding the Buttons o Adding New Files o Navigating to a Specific Directory o Putting It All Together OQ Or OTG HO Or 0 Overview In this project you will build an MP3 player using the Vinculum VMUSIC2 MP3 module and a USB flash drive You will add the MP3 module to the Atmega board and then program it to play music files from the flash drive By adding additional buttons to the board you can create your own interface for the device with inputs for file selection play and pause fast forward and reverse and volume adjustment Figure 1 Vinculum VMusic2 MP3 Module Challenge 1 Control the MP3 Module with Your Computer The first challenge is to use your computer to send commands to and receive data from the Vinculum module The module is capable of responding to more than 100 different predefine
4. URN Send a Carriage return 9 usart text V3A telan all songs im the directory 10 usart write CARRIAGE RETURN Send a carriage return 11 while 1 1 Remain in an endless loop 12 Changing Volume The next code sample shows you how to change the volume on the MP3 module A value of 0 is the maximum volume and a value of 250 is the minimum volume I tanclude umapi AN 2 imclude usark h oe 4 int main void Si 6 musart anit 9600 gt initialize the USART to 9600 baud T usart rext YCD TESTY Change to the TEST directory 8 usart write CARRIAGE RETURN Send a Carriage return 9 usart text V3A Play all songs in the directory 10 usart write CARRIAGE RETURN Send a carriage return 11 Usart text vsy T p Send volume command 12 usart write 70 see volume to 70 13 usart write CARRIAGE RETURN Send a Carriage return 14 while 1 1 Remain in an endless loop I5 Note that there is a space after the V in VSV Try sending a few more commands from the Atmega to the MP3 module before moving on to the next section Using Custom MP3 Commands The following code introduces a few new functions developed by Machine Science to control the VMUSIC2 module They are included in the mp3 h header file To use any of these functions you will need to initialize short command mode using the function mp3_command MP3 SHORT MODE Note that when using the mp3_ vol
5. and MP3 SHORT MODE Enable short command mode on MP3 module 39 mp3 file MP3 CHANGE DIRECTORY MUSIC Change to the MUSIC directory 40 inicialize directory p Disolay first irem in Che oenedl directory 41 while 1 1 42 43 if pin value PORT D5 LOW Check if the button on Port D5 is pressed 44 45 display next item Display toe next item in the current directory 46 delay ms PDEBOUNCE 7 7 Debounce ENE button press 47 48 49 Putting It All Together amelde muim apa hn 2e lude usar i go DA Gi ss a G 10 LI tanelude imp soi include define define define define define D R R R eh EBOUNCE 500 EADING SONG TITLE 1 EADING DIR TITLE 2 LAYING SONG 3 EADING UP DIR 4 IDRC ickemta ite cule char name 9 char type Chiara COME 13 14 IS 16 Ie 1G LS 20 ZA 22 23 24 vote refresh directory char newcount count newcount Coat Nota les lee elear i z w3 tile name mame TYLE FTFECOWAL lied eet name Da vomd display next item 26 2E 28 29 30 ae 32 leel clear Nps tile name name hype coat if count gt total count 0 leel text name Si 34 36 Bie 38 30 40 41 42 43 44 int main Baus void usert iniw 9600 initralize the USART to 9600 baud leel imit p Taput PORT DS pullupe on PORT DS Input
6. d commands which can be sent directly from a terminal emulator window Likewise the module can return strings of text which are easier to view initially on a full computer screen than on the Atmega board s LCD screen Collecting Your Components In order to connect the MP3 module to your computer you will need the following components Part Quantity Description A 1 VMUSIC2 MP3 module B 1 Modified connector harness 6 pin C 1 Bent header 6 pin D 1 Bent header 4 pin E 1 USB flash drive thumb drive Stocking the USB Flash Drive You should save at least five MP3 music files on your USB flash drive before testing the MP3 module If you don t have any MP3 files on your computer you can purchase or find free downloads of MP3 files at a variety of Internet sites Note that when naming files or directories on the flash drive you may use any name you like but the module will only recognize the first eight characters of any title Insert your USB flash drive into any open USB port on your computer Navigate to the USB flash drive directory and delete all files on the drive Create a directory called TEST on your flash drive Copy at least five MP3 music files into the TEST directory Rename your MP3 files M1 mp3 M2 mp3 M3 mp3 M4 mp3 and M5 mp3 A mite O A Building the Circuit Using Figure 2 as a guide connect your MP3 module to your Machine Science programming board Figure 3 shows an example of a completed board for
7. eed the following components Part Quantity Description A 1 VMUSIC2 MP3 module B 1 Modified connector harness 6 pin C 1 Bent header 6 pin Building the Circuit Using the schematic in Figure 9 as a guide add your components to the breadboard Figure 10 shows an example of a completed breadboard layout You may use the picture as a guide but note that it demonstrates only one of many possible ways of wiring this circuit on a breadboard _ PC4 ADC4 SDA OSACS ADCS5 SCL PB2 SS OC 1B 16 RXD Orange PB3 MOSI OC2 H 2 TXD Yellow PB4 MISO 18 j CTS Green VMUSIC2 Figure 9 Schematic for the MP3 connection Figure 10 One way to wire the MP3 connection Playing Songs The following code example directs the the microcontroller to send commands to the MP3 module using the chip s Universal Synchronous amp Asynchronous Receiver Transmitter USART IMPORTANT The MP3 module and the Machine Science programming board both use the same pin for transmitting data to the Atmegal68 Before downloading your code you must disconnect the wire between Port DO RXD on the Atmega168 and pin 5 TXD on the MP3 module You can immediately reconnect this wire once the code has been downloaded include mxapi h Pune lude Weare Lae mara WoL Ios a EN Gi gS GIS 5 Usart int 9600 initialize the USART te 9600 baud te user text Kon AS Change to the TEST directory 8 usart write CARRIAGE RET
8. ile 0D Play a single file VRP file 8920 file OD Repeatedly play a single file VST 20 0D Stop playback V3A 21 0D Play all MP3 files in a directory VRA 8A 0D Repeatedly play all MP3 files VRR 8F 0D Repeatedly play random MP3 files VSF 25 0D Skip forward one track VSB 26 0D Skip back one track VSD 8E 0D Skip forward one whole directory VP 8B 0D Pause playback VF 8C 0D Fast forward 5 seconds VB 8D 0D Rewind 5 seconds VSV byte 88 20 byte OD Set playback volume 1 Connect headphones or external speakers to your MP3 module 2 Turn your battery pack on 3 Type CD TEST in your terminal window and press Enter to navigate into the TEST directory Again you may use either lower or upper case letters when you type your commands The module should acknowledge your command by returning the following characters D gt to your terminal window 4 Type V3A followed by the Enter key and the first MP3 file in your TEST directory should begin to play 5 Try sending a few other commands from the terminal window to to the MP3 module before moving on to the next section Challenge 2 Control the MP3 Module with the Microcontroller In this challenge you will construct a circuit to connect your MP3 module to your Atmega Board Then you will program the chip to send commands to the MP3 module and display data from the module on the Atmega Board s LCD Collecting your Components In order to connect the microcontroller to the MP3 module you will n
9. itialize_directory function determines the number of files in a directory and calls display_next_item M inelude mxapi h Zo tanelude usart h ao tanelude amps sin 4 Fincelude led h 5 6 define DEBOUNCE 500 7 define READING SONG TITLE 1 8 define READING DIR TITLE 2 9 define PLAYING SONG 3 10 define READING UP DIR 4 Li I2Q char totals The total number of songs im 42 directory Bechorani kok Storage for file and directory names 14 char state A record of the state of the program I5 Ghar file winders MAN imde OE les im the directories le In vord display next irem vorc its 19 leci elear Clear the LCD 20 mps file neme name Gertace rriiLle imez y Return the name and type of file directory Pil if file index gt total file _index 0 ITE the index is larger than the total reset 22 led text nane Display the name of the file directory VAS 24 25 VOL imitrialize directory vod Zok Pale file index 1 Roing CO ene first recorto in a directory 28 wol ana total sealers F G the total numoer Or records iam a directory 29 display neszt itemi Display the next Lren in the directory 30 Sale 322 ine matm Yoo Soe 34 usart Init So00 7 initialize the USART tO 9600 baud 35 lcd inict y Tnitialize the LCD 36 Oee EOR TEDS Set up Port gt ais van Input 37 pulLUp on FORT D5 Eneble pullip resistor Oa Bea 05 38 mp3 comm
10. nclude Led ni Tn marim VOLC Char total 0 Declare a variable to store the number of files usart init 9600 Initialize the Atmegal68 s USART to 9600 baud led meal OA In Tana re ze the LEB mp3 command MP3 SHORT MODE Initialize short command mode mp3 file MP3 CHANGE DIRECTORY TEST Change to the TEST directory total mp3 total files Read the number of files in TEST led _ decimal total Display the number on the LCD is while 1 Remain in an infinite loop 16 Try changing the number of files in your directory and then run the code again Challenge 3 Use Buttons to Control the MP3 Player In this challenge you will add two buttons to your MP3 player and use these buttons to scroll through and play selected songs stored on your flash drive The code for this challenge will use everything you have learned so far and is significantly more complex than the previous code samples Don t expect to understand everything at first Adding the Buttons Using the schematic in Figure 11 as a guide add two buttons to the breadboard Figure 12 shows an example of a completed board for this circuit You may use the picture as a guide but note that it demonstrates only one of many possible ways of wiring this circuit on a breadboard PC3 ADC3 4 ADC4 SDA NAN botADC5 SCL eee JP1 PDOIRXD i PD1 TXD PD2 INTO PD3 INT1 PD4 XCK TO 2 GND Black PBO ICP J l RTS
11. pint PORT Do Di eulblus von PORT Do mp3 command MP3 SHORT MODE mp3 file MP3 CHANGE DIRECTORY MUSIC j refresh Cirectory e 45 46 47 48 49 50 Sil 32 53 54 23 56 SI 58 59 60 Gl 62 63 64 65 66 67 68 69 70 Vil ees 13 74 Ya 76 E 78 79 80 81 82 83 84 85 86 while 1 1 Ane oa E ADIN CES ONC EE Lr pin yvaluvue PORT DE LOW ISS ta Ie MPI PLAY PILE NAME type PLAYING SONG delay ms DEBOUNCE LE pila value PORT PS hOw Grsplay next tem delay ms DEBOUNCE else if type PLAYING SONG LE pin yalue PORT D6 LON Mp2 command MP3_STOP type READING SONG TITLE delay ms DEBOUNCE else LE CYPESSREADING DIR TITLE LE pin value PORT D6 KO mp erie MPs ROCE NCEEDIRECHORM Amame refresh directory g delay ms DEBOUNCE Li pin yalue PORT D5 5LON Grep lay next tem delay ms DEBOUNCE else if type READING UP DIRI LE pin yalue PORT D6 LON Mp2 command MES UP DIRECTORY retresh drrectony li delay ms DEBOUNCE Lir pin yalue PORT DS LOW cisplay next Lrem p delay ms DEBOUNCE
12. this circuit You may use the picture as a guide but note that it demonstrates only one of many possible ways of wiring this circuit on a breadboard 5V Programming Board VMUSIC2 CTS Green TXD Yellow RXD Orange VCC Red RTS Brown GND Black GND GND Figure 2 Schematic for testing the MP3 module Figure 3 One possible configuration on the breadboard Setting up a Terminal Emulator Connected as shown in Figure 2 the MP3 module can receive commands from and return data directly to your computer To control the module this way you will need to run a terminal emulator a program that emulates an older style text only computer terminal Depending on your operating system your computer may already have a terminal emulator or you may need to download one from the Internet e Windows Vista TeraTerm Pro Web is available here http www ayera com teraterm e Windows pre Vista HyperTerminal is available in the Start menu under Programs gt Accessories gt Communication e Macintosh ZTerm comes pre installed with OSX and above e Linux CuteCom can be found at http cutecom sourceforge net The instructions in this section are for installing TeraTerm Pro Web but should give you enough information to help you set up any of the other programs listed above 1 Determine which COM port your Machine Science programming board is using by viewing the Options menu in the Programming Window 2 Do
13. ume function the minimum and maximum values are the reverse of the VSV command 0 is the minimum volume and 255 is the maximum volume ly anelude mxapa h 2 include usart h 3 finclude mp3 4 Sa oe mena Vore Ga T saran Bs Initialize the USART to 9600 baud 8 mp3 command MP3 SHORT MODE Initialize the module to short command mode 9 mp3 file MP3 CHANGE DIRECTORY TEST Change to the TEST directory 10 mp3 command MP3 PLAY ALL Play all files 11 mp3 volume 200 Change the volume to a value of 200 I2 wairkle I 51 Remain in an endless loop 13 Adjust the volume a few times by changing the value sent to the mp3_volume function Playing a Specific File Using the following code you can play a specific file stored on the flash drive As noted above you can name your files and directories however you want but the module will recognize only the first eight characters Finelude mxapi hh include usart h Fine lude mp3 sh SS wi SL int main void Gs 4 Te usart init 9600 Initialize the Atmegal68 s USART to 9600 baud 8 mp3 command MP3 SHORT MODE Initialize the module to short conmand mode 9 mp3 file MP3 CHANGE DIRECTORY TEST Change to the TEST directory 10 mp3 file MP3 PLAY FILE M2 mp3 Play the M2 mp3 file 11 mp3 volume 200 Change the volume to a value of 200 ie while 1 1 Remain in an endless loop NS
14. will allow you to see the commands you type to send to the MP3 module Click OK 9 Turn on your battery pack After about a two second delay your screen should look like Figure 7 Note that the version number may be different amp Tera Term Web 3 1 COM2 YT File Edit Setup Web Control Window Help Ver 03 66YMSC1F On Line Device Detected P2 Figure 7 Terminal emulator window 10 Turn off your battery pack Sending Commands to the MP3 Module The following table shows an abbreviated list of commands that can be used with the MP3 module For a more complete list download the Vinculum Firmware User Manual from the Vinculum website at http www vinculum com For each command in the table there is an extended command set version and a short command set version The extended commands are easier to read because they comprise ASCII characters The short commands which comprise hexadecimal codes are more difficult to read but more efficient The first few code examples in this document use the extended set while later examples use the short command set Note that a carriage return the Enter key is required after every command in the extended set Also note that the extended commands are not case sensitive DIR is equivalent to dir Extended Command Short Command Hex Codes Function DIR 01 0D Lists files in current directory CD file 02 20 file OD Change current directory CD 02 20 2E 2E 0D Move up one directory VPF file 1D 20 f
15. wnload TeraTerm Pro Web from http www ayera com teraterm 3 Unzip the zip file to a convenient location on your hard drive 4 Open the folder and double click on the file ttermpro exe You will see a dialog box like the one shown in Figure 4 Tera Term New connection TCP IP Host Neraka v Service Telnet TCP port 23 C SSH C Other Serial mei 10 Figure 4 New connection dialog box 5 Select Serial and the COM port being used by your Machine Science programming board Turn on your battery pack Your screen should be mostly blank with a few lines of text in the upper left as shown in Figure 5 Tera Term Web 3 1 COM2 VT File Edit Setup Web Control Window Help Il gt pgradeected P2 Line Figure 5 Terminal Window 1 6 Turn off your battery pack 7 Select Terminal from the Setup menu You should now see a dialog box like the one shown in Figure 6 Tera Term Terminal setup Terminal size New ine 80 x 24 Receive car Term size win size Transmit cr T Auto window resize Terminal ID yT100 v iv Local echo Answerback Auto switch VT lt gt TEK gta Help Figure 6 Serial port setup 8 Select CR LF for receive and Local Echo as shown in Figure 6 CR and LF stand for carriage return and line feed and will make sure that each new text string sent from the MP3 module is displayed on a new line Local echo
16. yims 1000 Display the name for 2 seconds led eleax Clear the LCD Add a new directory to your flash drive and try this code with the new directory Playing Files by Variable Name The following code plays a file based on the name retrieved by the mp3_ filename function SAMs SSE 10 He fFinelude mxapa h include usart h include mp3 h include lcd h iwe marn VOL char name 9 n miht alne a string tor storing file names Uas 9600 Initialize the Atmegal68 s USART to 9600 baud char type Initialize a variable for storing file types led init Imnicializs the LCD 12 18 14 15 16 es 18 19 mp3 command MP3 SHORT MODE Initialize the module to short command mode mp3 file MP3 CHANGE DIRECTORY TEST Change to the TEST directory mp3 file name name amp type 2 Retrieve the second file name from TEST led text name Display file name on the ECD mp3 file MP3 PLAY FILE name Play the file stored in name nips volume 200 ser tne volume tO value Ot ZOO while 1 Remain in an endless loop Counting the Files in a Directory As a next step a function is introduced for counting the number of files in a directory This way the code does not have to change to accommodate directories with different numbers of files SD SI oy Gi ss YS 10 11 12 13 14 rime luge kap NK include usart h include mp3 h i

Download Pdf Manuals

image

Related Search

Related Contents

instructions for use and maintenance  iMod User`s Manual ENG  User Manual Mode d`emploi  Untitled  User`s Manual - Amazon Web Services  Samsung SGH-I450 Benutzerhandbuch  piano di sicurezza e coordinamento    SRecord  取扱説明書(J)  

Copyright © All rights reserved.
Failed to retrieve file