Kim_Minji_Final_Project


Pikachu Friend Mp3 Player

 

Design Point of View

This project’s purpose is to give those people who may feel lonely at times in the night or those who simply need a friend to snuggle with a small, customized plushie that can play music. For easier control, the plushie will have a Bluetooth connection to a remote (a laptop in this case due to limited time) that can allow the user to manipulate the Mp3 player easily. There is also a light attached to the plushie in case it is night time and the user wants a little bit of light before they go to sleep. All in all, the plushie is good company to have around during the night time because it can give you a small light, play soothing music, or simply be a friend to cuddle with. 

 

Features

In order to fulfill its purposes there are multiple features that have been implemented for this Mp3 player. First off, all of the small electrical components (such as the arduino micro, mp3 decoder, etc.) are stored inside of the plushie for a more aesthetically pleasing configuration. This also allows the user to cuddle with the pikachu like it is a regular plushie without having to be careful of messing up the electrical components that help it run. The pikachu also has a speaker attached to it which allows it to externally project all of the music that is stored in its SD card. There is also a red LED light attached to the pikachu that serves as the flashlight for the Mp3. Then, there is no external button system that must be manipulated because the pikachu mp3 player is controlled  by bluetooth and can be controlled by a device with bluetooth such as a laptop.

 

Verplank Diagram


Paper Prototype

 

State Diagram

 

Perfboard Planning

In order to have an easier time perfboarding, I decided to plan it all out before I actually began work with the soldering machine and my perfboard materials. I developed a small sketch on where I planned on placing all of my perfboard components and I made a checklist that told me which components I would need to connect via jumper wire. Although I didn't completely go with my initial layout that I sketched in the diagram below, sketching out my perfboard helped me organize my thoughts on component placement on my board. The checklist also helped me make sure that I had properly made all of my connections. 

 

Materials Needed

 

The Process (My Experience)

I can divide my entire process in making this pikachu into a couple of tasks which I will briefly describe below. The tasks consisted of planning, making the barebones Mp3 player with some customized features, perfboarding, getting the pikachu together, and connecting with bluetooth. 

 

Planning

During the planning process, I changed my plan multiple times. I had an idea of what I wanted to do but I wasn't sure how I was going to implement all of the features. Although I changed some of my plans during the actual process of making my final product, the planning helped me organize my thoughts and know what general direction I wanted to go with my project. Some of my planning included the Verplank diagram, the state diagram, the prototype, and even simply continuously making basic sketches on what component I wanted where and how that component would help me achieve what I wanted. From the experience, I learned that planning is essential in bringing ideas to reality (what can I actually create with my ideas) and helped prevent having to deal with hassles of dealing with certain ideas that didn't work after all. 

 

Barebones Mp3 with Customized Features

My next step was simply to finish Lab 6 on my breadboard which would get me started with actually developing a functioning Mp3 player. Upon completion I decided to add in a few extra features that I knew that I would need for my customized Mp3 player. For example, I put in the code that I would need to turn a light on and off by command, put the volume up or down, or go forward to the next song or go backwards to the previous song.

 

Perfboarding

This was probably the most challenging part of the entire process. Although I created plans as shown above, I still managed to mess up my perfboarding by not completely soldering all of my components correctly. First, I soldered on the female headers to where I thought all of my electrical components (such as the Mp3 decoder and the arduino micro) should go.

 

 

Upon completing that step, I took off the electrical components on my breadboard and plugged them into their appropriate female headers so that I would have a reference to where I would need to make my connections with jumper wires. I cut and stripped multiple jumper wires and soldered them one by one onto the breadboard while checking the connections off of my list. Unfortunately, I didn't completely solder on my headers and wires (improper connection between the solder and the wire) and so I had to use the multimeter and the multimeter probes to check for continuity throughout my circuit. Upon making quite a number of corrections, I finally managed to get my perfboard in working condition.

Extra connections that are not listed above: The LED light to pin 13 and ground and the battery powering device to voltage input and ground


 

Getting the Pikachu Together

I knew that I wanted to get my perfboard inside of my pikachu for a better aesthetic appearance. In order to do that, I went to room 36 to get the proper materials so that I could create a little zipper to cover the opening in which I could access my perfboard. I cut open the bottom of my pikachu with an

X-acto knife. Then, I pulled out quite a decent amount of stuffing so that there would be room for my perfboard. Then, I delicately placed my perfboard inside of my pikachu while using the remaining stuffing to act as a soft bordering cushion so that the perfboard would not get damaged while the pikachu was being handled. Then, I hand sewed a zipper onto the bottom of my pikachu so that I would be able to close the pikachu after I had put in the necessary components. Then, I simply attached my hamburger speaker (with the LED light looped through) to my pikachu using velcro. 


 

Connecting with Bluetooth

My final challenge was getting my pikachu to follow the necessary commands through bluetooth. First, I did the extra bluetooth special lab in order to learn the basics of how to get my bluetooth device to connect to my laptop. Then, I implemented bluetooth commands in my code that would result in different functions of the pikachu being called using a switch case statement. Then, using the Windows Bluetooth Serial Terminal app, I managed to successfully connect to my HC-05 device and send messages to my pikachu via bluetooth. 


 

The Video

 

The Code

#include <SD.h>

#include <EEPROM.h>

#include <SPI.h>

#include <SoftwareSerial.h> 

 

#include "mp3.h"

#include "mp3conf.h"

#include "memory.h"

 

// include the adafruit pcd8544 & gfx libraries for a nokia 5110 graphic lcd.

 

#include <Adafruit_GFX.h>

#include <Adafruit_PCD8544.h>

 

// setup microsd and decoder chip select pins, and the decoder-specific pins.

 

#define sd_cs         17        // 'chip select' line for the microsd card

 

#define mp3_cs        A0        // 'command chip select' connect to cs pin

#define mp3_dcs       A1        // 'data chip select' connect to bsync pin

#define mp3_rst       -1        // 'reset' connects to decoder's reset pin

#define mp3_dreq      A2        // 'data request line' connect to dreq pin

 

#define read_buffer  512        // size (bytes) of the microsd read buffer        // default volume. range min=0 and max=254

 

#define max_name_len  13

#define max_num_songs 40

#define max_title_len 60

// ---- global variables ----------------------------------------------------

 

// 'File' is a wrapper of the 'SdFile' data type from the sd utility library.

 

File sd_file;                   // object to represent a file on a microsd

 

// store the number of songs in this directory, and the current song to play.

 

unsigned char num_songs = 0, current_song = 0;

 

// an array to hold the current_song's file name in ram. every file's name is

// stored longer-term in the eeprom. this array is used in 'sd_file.open()'.

 

char fn[max_name_len];

 

// an array to hold the current_song's title in ram. it needs 1 extra char to

// hold the '\0' that indicates the end of a character string. the song title

// is found in 'get_title_from_id3tag()'.

 

char title[max_title_len + 1];

 

//Variables used throughout the code

enum state { DIR_PLAY, MP3_PLAY, PAUSED };

state current_state = DIR_PLAY; 

int volume = 200;

char bluetoothData = 0;

int lightPin = 13;

 

SoftwareSerial mySerial(10,11);

 

void sd_file_open() {  

  get_current_song_as_fn();

  sd_file = SD.open(fn, FILE_READ);

}

 

void mp3_play() {

  unsigned char bytes[read_buffer]; 

  unsigned int bytes_to_read;        

 

  bytes_to_read = sd_file.read(bytes, read_buffer);

  Mp3.play(bytes, bytes_to_read);

 

  if (bytes_to_read < read_buffer) {

    sd_file.close();    

 

    if (current_state == MP3_PLAY) {

      current_state == PAUSED;

    }

  }

}

 

void dir_play() {

  if (sd_file) {

    mp3_play();

  }

  else {

    if (current_song < (num_songs - 1)) {

      current_song++;

      sd_file_open();

 

    }

    else {

      current_state = PAUSED;

    }

  }

}   

 

//Plays the song if it is in the paused state and pauses the

//song if it is playing

void pausePlay()

{

    if (current_state == MP3_PLAY) {

      current_state = PAUSED;

      Mp3.clear_buffer();

    }

    else if (current_state == DIR_PLAY){

      current_state = PAUSED;

      Mp3.clear_buffer();

    }

    else{

      current_state = DIR_PLAY;

      Mp3.clear_buffer();

    }

}

 

//turns up the volume

void volumeUp() {

    if(volume >= 250){

      return;

    }

    volume = volume + 10;

 

//Turns down the volume 

void volumeDown(){

    if (volume <= 0){

      return;

    }

    volume = volume - 10;

}

 

//moves forward to the next song

void forward(){

  if (current_song < (num_songs - 1)){

    Mp3.cancel_playback();

    sd_file.close();

    current_song++;

    sd_file_open();

  } 

}

 

//rewinds to the previous song

void backward(){

  if(current_song > 0){

    Mp3.cancel_playback();

    sd_file.close();

    current_song--;

    sd_file_open();

  }

}

 

void saveVolume(){

  EEPROM.put((max_num_songs * max_name_len), volume);

}

 

void getVolume(){

  EEPROM.get((max_num_songs * max_name_len), volume);

}

// ---- setup and loop ------------------------------------------------------

 

void setup() {

 

  mySerial.begin(9600);

  pinMode(lightPin,OUTPUT);

  getVolume();

 

  Mp3.begin(mp3_cs, mp3_dcs, mp3_rst, mp3_dreq);

  Mp3.volume(volume);

 

  sd_card_setup();

  sd_dir_setup();

  sd_file_open();

}

 

void loop() {

 

  if(mySerial.available()){

    bluetoothData = mySerial.read();

 

    switch(bluetoothData) {

 

      case 'p':

      pausePlay();

      break;

 

      case 'l':

      digitalWrite(lightPin, HIGH);

      break;

 

      case 'o':

      digitalWrite(lightPin, LOW);

      break;

 

      case 'f':

      forward();

      break;

 

      case 'b':

      backward();

      break;

 

      case 'u':

      volumeUp();

      break;

 

      case 'd':

      volumeDown();

      break;

    }

  }

  switch(current_state) {

 

    case DIR_PLAY:

      dir_play();

      break;

 

    case MP3_PLAY:

      mp3_play();

      break;

 

    case PAUSED:

      break;

  } 

  Mp3.volume(volume);

  saveVolume();

}

 

 

Future Plans

 

In the future, I hope to make improvements to my project that will make it more user-friendly. I would like to create a customized remote control that would control the Pikachu Mp3 player externally (using another aruduino and bluetooth device by Dr. Sirkin's suggestion). I would also like to add more features to my pikachu to make it more interesting. For example, I would want it to make a pikachu noise as the LED light turns off. All in all, my ultimate future goal is to simply make the Mp3 device more suited to the user's desires. 

 

Note of Thanks

 

I want to thank Dr. Sirkin and all of the TAs for all of the help that they gave me during the entire course and especially with my final project. They helped give me ideas on how to carry out my plans, debug my code, and resolve issues with the hardware whenever those issues arose. I would also like to thank the Room 36 staff for helping me learn how to sew and thus carry out my project as desired.