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

  • Social distancing? Try a better way to work remotely on your online files. Dokkio, a new product from PBworks, can help your team find, organize, and collaborate on your Drive, Gmail, Dropbox, Box, and Slack files. Sign up for free.

View
 

Lab6_JoseOchoa

Page history last edited by Benjamin Tee 8 years, 9 months ago

Lab 6



Barebones MP3 Player

 

Assignment

Work your way through Parts A through D

 

In The Report

Answer the questions in green below, and

show a video of your MP3 player playing a song! Your responses, code, and video are due one week after your lab session.

 

Part A. Audio Jack

Done. Audio jack is connected just fine and I can hear the tone.

 

Part B. Connect And Test Your Decoder

Your second task is to wire up and test your mp3 decoder.

 

1. Install this updated Mp3 library in the Arduino IDE "libraries" folder.

Done. I deleted the original library and am using the latest that David and the teaching team updated and utilizes non-blocking code.

2. Wire up the decoder and your audio jack to your breadboard.

3. Load the test program in Examples->MP3->SineTest. Be sure your system clock is set to 8 Mhz in Tools -> CPU Speed -> 8 Mhz

 

Describe the tone pattern you hear (ie, high or low? how long? Etc)

There is a constant drone in the background. But above that are three distinct tones each lasting about one second. The first tone is the highest, with the second lower in tone, and the third is the lowest of the three.

 

Now, uncomment the #define DEBUG line in the SineTest code, reflash the Teensy, reboot, and check the serial monitor. (If you do this, it will take 15-20 seconds for the SineTest tones to start.) The program should report the following:

 

Wrote 820 to address 0

Wrote 0 to address 3

Wrote 8181 to address B

 

Read SCI_MODE: 820

Read CLOCK_F: 0

Read SCI_VOL: 8181

 

Done. Check the following screenshot:

 

Edit the following line in the SineTest code to change the DEFAULT_VOL to 0x6565 (or something similar) to make it louder:

 

A snippet of my code that increases the volume of playback:

void setup() {

#ifdef DEBUG

Serial.begin(9600);

delay(100);

#endif

 

spi_init();

 

write_sci(SCI_MODE, DEFAULT_MODE);

delay(10);

write_sci(SCI_CLOCKF, DEFAULT_CLOCKF);

delay(100);

// write_sci(SCI_VOL, DEFAULT_VOL);

write_sci(SCI_VOL, 0x6060);

delay(10);

 

#ifdef DEBUG

Serial.print(" Read SCI_MODE: "); Serial.println(read_sci(SCI_MODE), HEX); delay(10);

Serial.print(" Read CLOCK_F: "); Serial.println(read_sci(SCI_CLOCKF), HEX); delay(10);

Serial.print(" Read SCI_VOL: "); Serial.println(read_sci(SCI_VOL), HEX); delay(10);

#endif

}

 

Part C. Play Some Music!

Tell a member of the teaching team what your song is:

The song is Mahna Mahna, and more info about it here:

http://en.wikipedia.org/wiki/Mah_N%C3%A0_Mah_N%C3%A0

 

Does this code play all the songs in all the directories of the SD card? If not, which songs does it play? How does it keep from playing the text file?

  1. This code only plays songs from the root directory.

  2. And it only plays up to 40 of them.

  3. And it checks the file extension to determine if it is a song file, a text file, or something else.

 

✔ What lines of the code checks whether it is a text file?

 

Change the 'song' code to save the current volume setting in your EEPROM and fetch and set that value during initialization. Note that the first MAX_FILE_COUNT*MAX_NAME_LENGTH (in this case, 520) bytes of the EEPROM are used to store file names, so don't overwrite those.

 

 

?

If you're confused, look at the top of the 'song' example code.

 

 

Part D. Pause to Learn About Interrupts

What if you want to play or stop playing a song on command?

 

The Teensy has 4 pins with external interrupts built in, on pins 5, 6, 7 and 8 (which correspond with interrupt 0, 1, 2, and 3 respectively). You can use them by using theattachInterrupt() function, which is part of the extended Arduino language.

 

Try the sample code from the attachInterrupt reference page with a button circuit that is tied high with a 10K resistor and that gets pulled to ground when the button is depressed.

 

In general (as in the sample code), when you set or change a variable within an interrupt service routine (ISR), you should declare that variable as volatile, to tell the compiler to load its value from RAM instead of storing it in a register to optimize.

 

Draw us a quick sketch of what your circuit looks like.

 

 

What happens when you press the button? What happens when you press the button 15 times in a row?

The LED turns on every time the button is pressed. If the button is pressed 15 times in a row, it will light up fifteen times in a row.

 

✔ Actually it stalls the processor if you do it really fast

 

To debounce the button in software, you can create a "bouncer" object that waits a bit before reading the button: http://www.arduino.cc/playground/Code/Bounce

What are the pros and cons of using this method?

Pros is that no extra hardware must be added to electrically debounce the button. A drawback of using this method however is that it uses blocking code. The Teensy cannot perform any other functions until the wait period is over.

 

Now, take what you learned to make an interrupt driven pause function for your Barebones MP3 player!

 

 

 

Comments (0)

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