ECE 4180 Final Project

Dependencies:   mbed wave_player 4DGL-uLCD-SE SDFileSystem_OldbutworkswithRTOS PinDetect

Portable Surface Transducer Jukebox

ECE 4180 Final Project

Team members

  • Bruna Correa
  • Lance Hudson
  • Javier Rodriguez

Jukebox Overview

This unique jukebox uses a surface transducer to essentially turn any hard surface (table, etc) into a resonant speaker. The user has the option to select one of out ten songs which were preselected and loaded onto the SD card. To begin, the user types their song choice into the keypad and is prompted to press “START” to begin the song. The user can end the song at any time by pressing “STOP,” which will redirect them back to the original selection menu.

Parts Required

  • 1x Mbed (LPC1768)

Mbed

  • 1x MicroSD card breakout (Sparkfun)

MicroSD Breakout

  • 1x Class D Amp (Sparkfun TPA2005)

Class D Amp

  • 1x Surface conduction transducer speaker (Generic)

Surface Transducer

  • 1x Breadboard speaker

Speaker

  • 2x standard pushbuttons

Pushbutton

  • 1x uLCD (Sparkfun 4DGL)

uLCD Screen

  • 1x Touch capacitance keypad (Sparkfun MPR121)

Touch Pad

  • 2x 6-volt breadboard battery packs

Battery Pack

  • 1x Standard 8x4x4 project box

Project Box

Design Challenges and Tradeoffs

One of the major challenges experienced when developing the Jukebox user interface was the synchronous playback function of the music. This required several instances of interrupt handling and pin detects. More specifically, regarding the “STOP” button, we realized that it was initially not possible to perform any pushbutton polling while the waveplayer function play() is active; if the “STOP” button was pressed while a song is playing, it would only be recognized when the song was finished. Therefore, we looked into editing the waveplayer library itself by passing an extern bool named “play” that was switched to true when “START” is pressed and false when “STOP” is pressed. Inside the play() function we added a logical check to ensure that this play variable is true, and if switched to false, it immediately breaks from the loop, thereby stopping the playback.

Several design tradeoffs had to be made for the benefit of portability. For example, we chose to not implement the original RGB LED strip because it added too much weight and occupied too much space inside the housing for the portable implementation desired. We believe that portability was a more valuable feature for the end user than an LED light show.

Schematic

The schematic used is shown below. For more detailed information on connection declarations and classifications in the software, refer to the code repository.

/media/uploads/jrod1096/schematic.jpeg

Demonstration Video

Committer:
jrod1096
Date:
Wed Dec 12 05:17:58 2018 +0000
Revision:
3:74066405c9fc
Surface Transducer Jukebox

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jrod1096 3:74066405c9fc 1 /*
jrod1096 3:74066405c9fc 2 Copyright (c) 2011 Anthony Buckton (abuckton [at] blackink [dot} net {dot} au)
jrod1096 3:74066405c9fc 3
jrod1096 3:74066405c9fc 4 Permission is hereby granted, free of charge, to any person obtaining a copy
jrod1096 3:74066405c9fc 5 of this software and associated documentation files (the "Software"), to deal
jrod1096 3:74066405c9fc 6 in the Software without restriction, including without limitation the rights
jrod1096 3:74066405c9fc 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
jrod1096 3:74066405c9fc 8 copies of the Software, and to permit persons to whom the Software is
jrod1096 3:74066405c9fc 9 furnished to do so, subject to the following conditions:
jrod1096 3:74066405c9fc 10
jrod1096 3:74066405c9fc 11 The above copyright notice and this permission notice shall be included in
jrod1096 3:74066405c9fc 12 all copies or substantial portions of the Software.
jrod1096 3:74066405c9fc 13
jrod1096 3:74066405c9fc 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
jrod1096 3:74066405c9fc 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
jrod1096 3:74066405c9fc 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
jrod1096 3:74066405c9fc 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
jrod1096 3:74066405c9fc 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
jrod1096 3:74066405c9fc 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
jrod1096 3:74066405c9fc 20 THE SOFTWARE.
jrod1096 3:74066405c9fc 21 */
jrod1096 3:74066405c9fc 22
jrod1096 3:74066405c9fc 23 #include <mbed.h>
jrod1096 3:74066405c9fc 24 #include <sstream>
jrod1096 3:74066405c9fc 25 #include <string>
jrod1096 3:74066405c9fc 26 #include <list>
jrod1096 3:74066405c9fc 27
jrod1096 3:74066405c9fc 28 #include <mpr121.h>
jrod1096 3:74066405c9fc 29
jrod1096 3:74066405c9fc 30 Mpr121::Mpr121(I2C *i2c, Address i2cAddress)
jrod1096 3:74066405c9fc 31 {
jrod1096 3:74066405c9fc 32 this->i2c = i2c;
jrod1096 3:74066405c9fc 33
jrod1096 3:74066405c9fc 34 address = i2cAddress;
jrod1096 3:74066405c9fc 35
jrod1096 3:74066405c9fc 36 // Configure the MPR121 settings to default
jrod1096 3:74066405c9fc 37 this->configureSettings();
jrod1096 3:74066405c9fc 38 }
jrod1096 3:74066405c9fc 39
jrod1096 3:74066405c9fc 40
jrod1096 3:74066405c9fc 41 void Mpr121::configureSettings()
jrod1096 3:74066405c9fc 42 {
jrod1096 3:74066405c9fc 43 // Put the MPR into setup mode
jrod1096 3:74066405c9fc 44 this->write(ELE_CFG,0x00);
jrod1096 3:74066405c9fc 45
jrod1096 3:74066405c9fc 46 // Electrode filters for when data is > baseline
jrod1096 3:74066405c9fc 47 unsigned char gtBaseline[] = {
jrod1096 3:74066405c9fc 48 0x01, //MHD_R
jrod1096 3:74066405c9fc 49 0x01, //NHD_R
jrod1096 3:74066405c9fc 50 0x00, //NCL_R
jrod1096 3:74066405c9fc 51 0x00 //FDL_R
jrod1096 3:74066405c9fc 52 };
jrod1096 3:74066405c9fc 53
jrod1096 3:74066405c9fc 54 writeMany(MHD_R,gtBaseline,4);
jrod1096 3:74066405c9fc 55
jrod1096 3:74066405c9fc 56 // Electrode filters for when data is < baseline
jrod1096 3:74066405c9fc 57 unsigned char ltBaseline[] = {
jrod1096 3:74066405c9fc 58 0x01, //MHD_F
jrod1096 3:74066405c9fc 59 0x01, //NHD_F
jrod1096 3:74066405c9fc 60 0xFF, //NCL_F
jrod1096 3:74066405c9fc 61 0x02 //FDL_F
jrod1096 3:74066405c9fc 62 };
jrod1096 3:74066405c9fc 63
jrod1096 3:74066405c9fc 64 writeMany(MHD_F,ltBaseline,4);
jrod1096 3:74066405c9fc 65
jrod1096 3:74066405c9fc 66 // Electrode touch and release thresholds
jrod1096 3:74066405c9fc 67 unsigned char electrodeThresholds[] = {
jrod1096 3:74066405c9fc 68 E_THR_T, // Touch Threshhold
jrod1096 3:74066405c9fc 69 E_THR_R // Release Threshold
jrod1096 3:74066405c9fc 70 };
jrod1096 3:74066405c9fc 71
jrod1096 3:74066405c9fc 72 for(int i=0; i<12; i++){
jrod1096 3:74066405c9fc 73 int result = writeMany((ELE0_T+(i*2)),electrodeThresholds,2);
jrod1096 3:74066405c9fc 74 }
jrod1096 3:74066405c9fc 75
jrod1096 3:74066405c9fc 76 // Proximity Settings
jrod1096 3:74066405c9fc 77 unsigned char proximitySettings[] = {
jrod1096 3:74066405c9fc 78 0xff, //MHD_Prox_R
jrod1096 3:74066405c9fc 79 0xff, //NHD_Prox_R
jrod1096 3:74066405c9fc 80 0x00, //NCL_Prox_R
jrod1096 3:74066405c9fc 81 0x00, //FDL_Prox_R
jrod1096 3:74066405c9fc 82 0x01, //MHD_Prox_F
jrod1096 3:74066405c9fc 83 0x01, //NHD_Prox_F
jrod1096 3:74066405c9fc 84 0xFF, //NCL_Prox_F
jrod1096 3:74066405c9fc 85 0xff, //FDL_Prox_F
jrod1096 3:74066405c9fc 86 0x00, //NHD_Prox_T
jrod1096 3:74066405c9fc 87 0x00, //NCL_Prox_T
jrod1096 3:74066405c9fc 88 0x00 //NFD_Prox_T
jrod1096 3:74066405c9fc 89 };
jrod1096 3:74066405c9fc 90 writeMany(MHDPROXR,proximitySettings,11);
jrod1096 3:74066405c9fc 91
jrod1096 3:74066405c9fc 92 unsigned char proxThresh[] = {
jrod1096 3:74066405c9fc 93 PROX_THR_T, // Touch Threshold
jrod1096 3:74066405c9fc 94 PROX_THR_R // Release Threshold
jrod1096 3:74066405c9fc 95 };
jrod1096 3:74066405c9fc 96 writeMany(EPROXTTH,proxThresh,2);
jrod1096 3:74066405c9fc 97
jrod1096 3:74066405c9fc 98 this->write(FIL_CFG,0x04);
jrod1096 3:74066405c9fc 99
jrod1096 3:74066405c9fc 100 // Set the electrode config to transition to active mode
jrod1096 3:74066405c9fc 101 this->write(ELE_CFG,0x0c);
jrod1096 3:74066405c9fc 102 }
jrod1096 3:74066405c9fc 103
jrod1096 3:74066405c9fc 104 void Mpr121::setElectrodeThreshold(int electrode, unsigned char touch, unsigned char release){
jrod1096 3:74066405c9fc 105
jrod1096 3:74066405c9fc 106 if(electrode > 11) return;
jrod1096 3:74066405c9fc 107
jrod1096 3:74066405c9fc 108 // Get the current mode
jrod1096 3:74066405c9fc 109 unsigned char mode = this->read(ELE_CFG);
jrod1096 3:74066405c9fc 110
jrod1096 3:74066405c9fc 111 // Put the MPR into setup mode
jrod1096 3:74066405c9fc 112 this->write(ELE_CFG,0x00);
jrod1096 3:74066405c9fc 113
jrod1096 3:74066405c9fc 114 // Write the new threshold
jrod1096 3:74066405c9fc 115 this->write((ELE0_T+(electrode*2)), touch);
jrod1096 3:74066405c9fc 116 this->write((ELE0_T+(electrode*2)+1), release);
jrod1096 3:74066405c9fc 117
jrod1096 3:74066405c9fc 118 //Restore the operating mode
jrod1096 3:74066405c9fc 119 this->write(ELE_CFG, mode);
jrod1096 3:74066405c9fc 120 }
jrod1096 3:74066405c9fc 121
jrod1096 3:74066405c9fc 122
jrod1096 3:74066405c9fc 123 unsigned char Mpr121::read(int key){
jrod1096 3:74066405c9fc 124
jrod1096 3:74066405c9fc 125 unsigned char data[2];
jrod1096 3:74066405c9fc 126
jrod1096 3:74066405c9fc 127 //Start the command
jrod1096 3:74066405c9fc 128 i2c->start();
jrod1096 3:74066405c9fc 129
jrod1096 3:74066405c9fc 130 // Address the target (Write mode)
jrod1096 3:74066405c9fc 131 int ack1= i2c->write(address);
jrod1096 3:74066405c9fc 132
jrod1096 3:74066405c9fc 133 // Set the register key to read
jrod1096 3:74066405c9fc 134 int ack2 = i2c->write(key);
jrod1096 3:74066405c9fc 135
jrod1096 3:74066405c9fc 136 // Re-start for read of data
jrod1096 3:74066405c9fc 137 i2c->start();
jrod1096 3:74066405c9fc 138
jrod1096 3:74066405c9fc 139 // Re-send the target address in read mode
jrod1096 3:74066405c9fc 140 int ack3 = i2c->write(address+1);
jrod1096 3:74066405c9fc 141
jrod1096 3:74066405c9fc 142 // Read in the result
jrod1096 3:74066405c9fc 143 data[0] = i2c->read(0);
jrod1096 3:74066405c9fc 144
jrod1096 3:74066405c9fc 145 // Reset the bus
jrod1096 3:74066405c9fc 146 i2c->stop();
jrod1096 3:74066405c9fc 147
jrod1096 3:74066405c9fc 148 return data[0];
jrod1096 3:74066405c9fc 149 }
jrod1096 3:74066405c9fc 150
jrod1096 3:74066405c9fc 151
jrod1096 3:74066405c9fc 152 int Mpr121::write(int key, unsigned char value){
jrod1096 3:74066405c9fc 153
jrod1096 3:74066405c9fc 154 //Start the command
jrod1096 3:74066405c9fc 155 i2c->start();
jrod1096 3:74066405c9fc 156
jrod1096 3:74066405c9fc 157 // Address the target (Write mode)
jrod1096 3:74066405c9fc 158 int ack1= i2c->write(address);
jrod1096 3:74066405c9fc 159
jrod1096 3:74066405c9fc 160 // Set the register key to write
jrod1096 3:74066405c9fc 161 int ack2 = i2c->write(key);
jrod1096 3:74066405c9fc 162
jrod1096 3:74066405c9fc 163 // Read in the result
jrod1096 3:74066405c9fc 164 int ack3 = i2c->write(value);
jrod1096 3:74066405c9fc 165
jrod1096 3:74066405c9fc 166 // Reset the bus
jrod1096 3:74066405c9fc 167 i2c->stop();
jrod1096 3:74066405c9fc 168
jrod1096 3:74066405c9fc 169 return (ack1+ack2+ack3)-3;
jrod1096 3:74066405c9fc 170 }
jrod1096 3:74066405c9fc 171
jrod1096 3:74066405c9fc 172
jrod1096 3:74066405c9fc 173 int Mpr121::writeMany(int start, unsigned char* dataSet, int length){
jrod1096 3:74066405c9fc 174 //Start the command
jrod1096 3:74066405c9fc 175 i2c->start();
jrod1096 3:74066405c9fc 176
jrod1096 3:74066405c9fc 177 // Address the target (Write mode)
jrod1096 3:74066405c9fc 178 int ack= i2c->write(address);
jrod1096 3:74066405c9fc 179 if(ack!=1){
jrod1096 3:74066405c9fc 180 return -1;
jrod1096 3:74066405c9fc 181 }
jrod1096 3:74066405c9fc 182
jrod1096 3:74066405c9fc 183 // Set the register key to write
jrod1096 3:74066405c9fc 184 ack = i2c->write(start);
jrod1096 3:74066405c9fc 185 if(ack!=1){
jrod1096 3:74066405c9fc 186 return -1;
jrod1096 3:74066405c9fc 187 }
jrod1096 3:74066405c9fc 188
jrod1096 3:74066405c9fc 189 // Write the date set
jrod1096 3:74066405c9fc 190 int count = 0;
jrod1096 3:74066405c9fc 191 while(ack==1 && (count < length)){
jrod1096 3:74066405c9fc 192 ack = i2c->write(dataSet[count]);
jrod1096 3:74066405c9fc 193 count++;
jrod1096 3:74066405c9fc 194 }
jrod1096 3:74066405c9fc 195 // Stop the cmd
jrod1096 3:74066405c9fc 196 i2c->stop();
jrod1096 3:74066405c9fc 197
jrod1096 3:74066405c9fc 198 return count;
jrod1096 3:74066405c9fc 199 }
jrod1096 3:74066405c9fc 200
jrod1096 3:74066405c9fc 201
jrod1096 3:74066405c9fc 202 bool Mpr121::getProximityMode(){
jrod1096 3:74066405c9fc 203 if(this->read(ELE_CFG) > 0x0c)
jrod1096 3:74066405c9fc 204 return true;
jrod1096 3:74066405c9fc 205 else
jrod1096 3:74066405c9fc 206 return false;
jrod1096 3:74066405c9fc 207 }
jrod1096 3:74066405c9fc 208
jrod1096 3:74066405c9fc 209 void Mpr121::setProximityMode(bool mode){
jrod1096 3:74066405c9fc 210 this->write(ELE_CFG,0x00);
jrod1096 3:74066405c9fc 211 if(mode){
jrod1096 3:74066405c9fc 212 this->write(ELE_CFG,0x30); //Sense proximity from ALL pads
jrod1096 3:74066405c9fc 213 } else {
jrod1096 3:74066405c9fc 214 this->write(ELE_CFG,0x0c); //Sense touch, all 12 pads active.
jrod1096 3:74066405c9fc 215 }
jrod1096 3:74066405c9fc 216 }
jrod1096 3:74066405c9fc 217
jrod1096 3:74066405c9fc 218
jrod1096 3:74066405c9fc 219 int Mpr121::readTouchData(){
jrod1096 3:74066405c9fc 220 return this->read(0x00);
jrod1096 3:74066405c9fc 221 }