| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • Get control of your email attachments. Connect all your Gmail accounts and in less than 2 minutes, Dokkio will automatically organize your file attachments. You can also connect Dokkio to Drive, Dropbox, and Slack. Sign up for free.

View
 

Michelle lab 6

Page history last edited by Michelle Lee 9 years, 1 month ago



Describe the tone pattern you hear.

Three notes. Low, medium, high.

 

 

Part C. Play Some Music!

Once the sine test is working, your third task is to jam! Er, to play a file from the microSD card. Think of it like this: in Lab 5, we read a block of bytes from a file, then streamed them to the serial terminal or the Graphical LCD. The read() function automatically advanced the read/write pointer for us, so we could loop over these 2 steps until there were no more bytes to be read. Well, we're doing the same thing now, only we're streaming the block of bytes to the decoder instead of the terminal or the LCD. That's it!

 

You should have a file titled song.mp3 on your microSD card already. Open the test program in Examples->MP3->Song. If everything is wired correctly to the MP3 decoder above *and* your SD card is working, this code should play song.mp3.

 

*Potential Problems*

If you are experiencing problems with connecting both the audio decoder and your SD card (if it is not reading the SD card) it is either because you have a small wiring error, or that the SD card you have isn't able to catch the rising edges of your signals because the resistors have added too much noise. To solve the latter case you can remove all but the 10kOhm resistor on the SO pin of the decoder and see if the SD card DumpFile example works. If so you're golden, other wise try putting a 100Ohm resistor between your MISO line to the SD card and the 10kOhm resistor between MISO and SO pin on the decoder. If this still doesn't work, get a level shifter (should be in the lab on Monday) and convert the signals through the level shifter, which won't add the noise which the resistors can contribute.

 

If all goes well, you should be able to share audio bliss with your labmates, friends and family. Congratulations!

 

Tell a member of the teaching team what your song is (or better yet, play it for us). If you don't know the name, just decipher some of the lyrics.

 

Now look at the example code a bit: specifically the play_dir() and loop() functions.

 

How would you alter the code to play a second song? How does it keep from playing the text file?

 

Look at the third example, CardInfo to see how to look inside a directory and print out useful information about it.

 

Here are some useful file management functions that can be used on a SdFile object (see here for comments on each of these functions):

void dirName(const dir_t& dir, char* name)

uint8_t openRoot(SdVolume* vol)

void ls(uint8_t flags, uint8_t indent)

uint8_t makeDir(SdFile* dir, const char* dirName)

uint8_t remove(void)

uint8_t remove(SdFile* dirFile, const char* fileName)

uint8_t rmDir(void)

uint8_t rmRfStar(void)

int16_t read(void* buf, uint16_t nbyte)

uint8_t open(SdFile* dirFile, const char* fileName, uint8_t oflag)

uint8_t open(SdFile* dirFile, uint16_t index, uint8_t oflag)

uint8_t seekSet(uint32_t pos)

int16_t write(const void* buf, uint16_t nbyte)

void write(const char* str)

void write_P(PGM_P str)

void writeln_P(PGM_P str)

int8_t readDir(dir_t* dir)

uint8_t sync(void)

uint8_t timestamp(uint8_t flags, uint16_t year, uint8_t month,
         uint8_t day, uint8_t hour, uint8_t minute, uint8_t second)

 

Also note that in this example's setup(), we're using the Mp3 library's volume() function. This function re-inverts the decoder's volume setting back to what seems more natural: 0 is nearly silent, while 254 (which equals 0xFE) is full volume.

 

Change the code to save the current volume setting in your EEPROM and fetch and set that value during initialization.

 

To add other audio files to your microSD card, you can use the Lab's USB card reader, which usually resides in the storage cabinet. The card should auto-mount on your computer, so you can copy over files and check the root directory and make sure the new files are, in fact, there (along with song.mp3 and any files you used and created during Lab 5). When you're done, just re-insert the card into your adapter, the adapter into your player, and return the reader to its home in the cabinet.

 

But wait, there's more...

Comments (0)

You don't have permission to comment on this page.