mbed Android Piano

This project uses the mbed RPC library to interface with a modified Adafruit Blutooth app. The application sends RPC calls to the mbed over the Adafruit Bluefruit LE UART Friend serial connection. The mbed then uses the Class D audio amp and speaker to generate the correct tone.

Hardware Assembly

mbedClass D Amp=Speaker=Bluetooth module
VUPWR +Vin
p21IN+
p27TXO
p28RXI
GNDPWR-GND
GNDIN-CTS
OUT++
OUT--

Optional potentiometer can placed on VOL pins of Class D amp.

mbed Code

//Code for mbed Android Piano project
//Based on RPC Example code

#include "mbed.h"
#include "mbed_rpc.h"

// Blutooth
Serial pc(p28, p27);

// Define RPC function
void moveTo(Arguments *in, Reply *out);
RPCFunction rpcMove(&moveTo, "moveTo");

// Speaker Control
double pwmVal;
PwmOut PWM(p21);

int main() {
    char buf[256], outbuf[256];
    while(1) {
        //Get Serial Arguments
        pc.gets(buf, 256);
        //Call the static call method on the RPC class
        RPC::call(buf, outbuf);  
    }
}

// Make sure the method takes in Arguments and Reply objects.
void moveTo (Arguments *in, Reply *out){
    pwmVal = in->getArg<float>();
    PWM.period(1.0/(pwmVal));//Set speaker Frequency
    PWM = 0.5;//Set speaker amplitude
}

Import libraryRPC_Function_Example

Android controlled

Blutooth Application

http://i.imgur.com/EG3dlt0.jpg

Modified in Android Studio as a Windows Forms application. You can download the project below.

https://www.mediafire.com/?n1ha56cdw1zf1ap

Running

  1. Compile and download the mbed code to the mbed
  2. Leave mbed connected
  3. Open the Adafruit application on your phone
  4. Connect to the module and tap UART
  5. Click the keys to play tones

Demo

https://vimeo.com/190509122


Please log in to post comments.