Music Box (X02)

From Microduino Wiki
Jump to: navigation, search
Music Box Project Build
Music Box X02 Angle View.jpg

About

This project uses the AudioPro module to decode and play music off of a MicroSD (with the use of the SD module). A microphone receives sounds levels and outputs the intensity as a simple sound visualizer to a LED Matrix module.

Three additional buttons are used for:

  • Play / Pause Track
  • Volume Up / Next Track
  • Volume Down / Previous Track

This project was designed for the second generation mCookie Maker kits (202 Advanced and 302 Expert kits).

Required Materials

  • 1 x mCookie Core
  • 1 x mBattery (202/302 Kit)
  • 1 x mCookie Sensor Hub
  • 1 x LED Matrix
    • OR 1x ColorLED (Expert Kit)
  • 1 x Audio Pro Module
  • 1 x MicroSD Module
  • 3 x Touch Button Sensor
  • 1 x Microphone Sensor
  • 4 x Sensor Cable
  • 1 x MicroSD Card
  • 2 x Speaker
  • 1 x MicroUSB Cable

Build

Sound File

  • There should be a MicroSD card and reader included in 202 and 302 kits.
  • Place MP3 files onto the MicroSD Card
    • Ensure MicroSD card is reformatted.
    • Only place MP3 files onto the MicroSD card. Other files types will not be read and may cause problems.
    • File names should follow the 8.3 filename convention which is up to 8 characters followed by the . and up to 3 characters for the extension (Example: 12345678.MP3). Not following the filename convention may cause file detection problems.

Assembly

NOTE: When connecting sensor wires, push on the plastic connector and not on the wires. Pushing on the wire can damage them.

  1. Connect a Touch Button to the Sensor Hub on Pin 2/3. This will be the Volume Up / Next Track button.
  2. Connect a Touch Button to the Sensor Hub on Pin 4/5. This will be the Play / Pause button.
  3. Connect a Touch Button to the Sensor Hub on Pin 6/7. This will be the Volume Down / Previous Track button.
  4. Connect a Microphone Sensor to the Sensor Hub on Pin A6/A7.
  5. Connect the Two Speakers to the Audio Pro Module.
  6. Insert the MicroSD card with the a.mp3 and b.mp3 file into the MicroSD Module.
  7. Create two stacks containing:
    1. (Bottom of Stack) MicroSD Module | Audio Pro Module | Sensor Hub (Top of Stack)
    2. (Bottom of Stack) Core | LED Matrix (Top of Stack)
  8. Stack the two stacks onto the mBattery
  9. Plug in the MicroUSB cable to the mBattery to a computer.

Program

1. Connect mCookie Core to the PC with the USB Cable. Open the Microduino IDE.

2. Download the project file and unzip: File:Music Box X02.zip.

  • Using the Microduino IDE and go to File > Open... and navigate to the unzipped folder. Open the Music_Box_X02.ino file.

3. Select the board, processor and port:

  • Go to Tools > Board and select Microduino/mCookie-Core (328p)
  • Go to Tools > Processor and select Atmega328P16M,5V
  • Go to Tools > Port and select the available port

4. Upload the program by clicking on the right arrow icon on the top left of the window. Or under Sketch > Upload.

NOTE: If not using the default Core module included in the kits, please follow the selecting the board and processor guide.

Debugging

  • Open the Serial monitor. Information on detecting the the Audio module (successfully or failed) and start / stop playing of music will be outputted.

Tweaking

DEBUG will enable debugging mode. Which outputs information to the Serial Port. Un-comment to and re-upload to enable debugging.

LEDMATRIX_PIN is the pin that the LED Matrix is connected to. LED Matrix is hardwired to A0 and shouldn't need to be modified. It is possible to replace the LED Matrix with Color LEDs instead. Simply, don't include the LED Matrix and connect a Color LED or a string of Color LEDs to this pin.

LED_NUM is the number of LEDs on the LED Matrix. 6 is default on the LED Matrix, but if using a Color LED or a string of Color LEDs then this value can be changed appropriately.

VOLUME_UP_PIN is the pin that a digital input sensor is connected to. This will control the volume up / next track functionalities. This can be replace with an digital input sensor, such as a touch button sensor, crash sensor, etc.

VOLUME_DOWN_PIN is the pin that a digital input sensor is connected to. This will control the volume down / previous track functionalities. This can be replace with an digital input sensor, such as a touch button sensor, crash sensor, etc.

VOLUME_PLAY_PAUSE_PIN is the pin that a digital input sensor is connected to. This will control the play / pause / random track functionalities. This can be replace with an digital input sensor, such as a touch button sensor, crash sensor, etc.

MIC_PIN is the pin that an analog input sensor is connected to. This will take in analog input and scale it to the LED Matrix or Color LED(s).

RANDOM_SEED_PIN should be an unused analog input pin. This will take the random-ish value using an analog read from this pin to seed the random number generator. Which is used for random track selection.

VOLUME_DEFAULT is the default volume value for the speaker output. Lower values = louder speaker. Default value is 30.

VOLUME_SCALER is the increment / decrements value used for increasing / decreasing the speaker volume when volume up or volume down button is pressed.

SKIP_TIME determines the time in milliseconds (1000 milliseconds = 1 second) in which to hold down the Volume Up / Skip Track touch button or Volume Down / Previous Track touch button in order to register as a Skip Track or Previous Track.

AUTO_PLAY_ENABLED is used to determine if the next song should be played. true = automatically play next song, false = don't automatically play next song.

PLAY_PLAYLIST is used to determine if playlist mode is activated. By default it is disabled (false), which means this program will automatically generate a playlist from all the files on the MicroSD card. Playlist mode (true) is a user defined playlist, the following values below, NUM_SONGS and SONGS[NUM_SONGS] needs to be defined in order to work properly.

NUM_SONGS determines the number of tracks the program will access.

SONGS[NUM_SONGS] is an array that contains the tracks the program will access. To add additional track add the track name to the array definition. Ensure that the files are in the MicroSD card. Ensure to update NUM_SONGS with the appropriate number of songs.

  • Example 1:
const int NUM_SONGS = 2;
const String SONGS[NUM_SONGS] = {"a.mp3", "b.mp3"};
  • Example 2:
const int NUM_SONGS = 5;
const String SONGS[NUM_SONGS] = {"a.mp3", "b.mp3", "TrackPi.mp3", "TrackIV.mp3", "Track5.mp3"};

AMBIENT_THRESHOLD determines the Microphone Sensor sound level which is ignored and is treated as ambient noise. Which means there values under this value will not produce an output to the LED Matrix.

  • Value range: 0~1023
  • Default: 15

MAX_THRESHOLD determines the Microphone Sensor sound level which is considered the max. This enables better scaling of the LED Matrix brightness output.

  • Value range: 0~1023
  • Default: 400

Troubleshooting

  • Sometimes the Audio Modules isn't detected. This can be fixed by restarting the project by disconnecting the modules and reconnecting or turning the battery off then on.

Usage

The first track should play automatically on start up. The Microphone picks up the sound levels and outputs them accordingly to the LED Matrix.

Control of the music box is as the following:

  • Play / Pause Button
    • Quick press to play or pause the current track.
    • Long press (hold for more than 1 second then release) to start a random track, long press again to stop randomization.
  • Volume Up / Skip Track Button
    • Quick press to increase volume.
    • Long press to skip to next track.
  • Volume Down / Previous Track Button
    • Quick press to decrease volume.
    • Long press and release to rewind or skip to previous track.