Introduction: DIY MIDI Bookmark / Piano / Keyboard Using ESP32 and MPR-121 Capacitive Touch Sensor

About: I enjoy making unique creations out of everyday items. I joined Instructables in order to share my ideas with the world.

Introducing the innovative MIDI Bookmark - a fusion of practicality and creativity, designed to enhance your reading experience like never before! Imagine diving into the captivating realms of literature, and when the words on the page begin to blur, simply switch gears with a touch of music.

This creation is dedicated to all you book and music nerds out there. Feeling a bit weary of reading? No problemo! Just tap into your inner DJ and let the tunes flow. And when the music's done its job of recharging your imagination, simply pick up where you left off in your literary escapade. Plus, when your brain's had enough, this nifty bookmark ensures you can bookmark your place and bid adieu to exhaustion, ready to dive back into the adventure tomorrow.

So, whether you're craving a literary escape or a musical interlude, this ingenious bookmark has you covered. So what are you waiting for? Let's make this amazing bookmark.

Supplies

Materials / Tools required for the build :

  • Foam board:- 2mm and 2.5 mm
  • Aluminum / Copper tape
  • Super glue
  • Rubber based adhesive ( Fevibond )
  • Carbon fiber vinyl wrap ( Optional )
  • Craft knife
  • Sand paper [ 220 ]
  • Varnish

Materials for the circuit :

  • ESP32
  • MPR -121 Capacitive touch sensor
  • 3.7 volt lithium ion battery
  • TP4056 Battery charging module
  • 3.7V TO 5V Boost converter module
  • Mini SPST Switch
  • 10K Potentiometer with Knob
  • 330 ohm resistor
  • 3mm blue led
  • 3mm red / green led (Common Anode)

MIDI Bookmark

Step 1: Cutting the Templates

Using the provided template as reference, transfer its outline onto a foam board and carefully cut out the corresponding parts. For the keys and the back segment where the keys are situated, opt for a 2.5-mm foam board, as grooves need to be created to accommodate the wires of the keys. I utilized a craft knife to carve out the groove, followed by refining it with sandpaper, as demonstrated in the gifs provided. The remaining sections of the bookmark were crafted from a 2mm foam board.

Step 2: Al / Cu Wrapping

To create contact points for our MPR-121 capacitive sensor, we'll need to adhere either aluminum or copper tape onto the keys. I suggest using copper tape because it allows for soldering wires directly onto the keys, ensuring a secure connection. If aluminum tape is used, wires can only be stuck onto the keys, as shown in the gifs, which may lead to issues over time. Here, I used aluminum tape since I already had it on hand, and copper tape was a bit pricey to buy., Next, I covered the keys with a carbon fiber vinyl sheet to enhance their appearance; this step is entirely optional.

Step 3: Gluing the Keys

Now that we've created the contact points for the keys, we can attach the keys and their cover parts as shown in the above GIF. I opted for a rubber-based adhesive to affix the key segments and covers, as it provides some flexibility. Using super glue instead could make the key segments rigid, increasing the risk of cracking or breaking when used as a bookmark. For the remaining parts of the bookmark, we'll use super glue.

Step 4: Electronic Assembly

Following the circuit diagram provided, solder / connect the components accordingly. Then, affix the remaining parts of the bookmark in place using superglue, as demonstrated in the above gifs.

You can utilize the Fusion 360 CAD file provided in the supplies section as a guide for positioning and gluing the components in place

Step 5: The Code

We will be using Arduino IDE to upload the code.

Before you upload the code, ensure that you've installed the ESP32 board package for Arduino. If it's not already installed, navigate to Tools => Board => Board Manager, then search for "esp32" and install the package provided by Espressif Systems [If you can't find ESP32 in the board manager, you'll need to paste the following link: (https://dl.espressif.com/dl/package_esp32_index.json ) into the Additional Boards Manager URL section found in File > Preferences.].

Additionally, we'll need to install the BLE-MIDI library. To do so, head to Tools => Manage Libraries, search for "BLE-MIDI," and install the library from there.

Once you have installed everything, copy and paste the below code and upload it to the esp32 board. (Make sure to set the upload speed to 115200, and you may need to press the boot button in your esp32 for about 2 seconds during the initial upload.) 

// MIDI Bookmark by Misfit Maker
#include <Wire.h>
#include <Adafruit_MPR121.h>
#include <BLE2902.h>
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEServer.h>
#include <BLEMIDI_Transport.h>
#include <hardware/BLEMIDI_ESP32.h>


BLEMIDI_CREATE_INSTANCE("MISFIT_MIDI", MIDI)


Adafruit_MPR121 cap = Adafruit_MPR121();
const int ledPin = 2; // LED pin for connection status
const int potPin = 13;
// Not a pin, define it for clarity
#define NOT_A_PIN 0xFF


// MIDI notes for each of the 12 keys, will be dynamically assigned
uint8_t midiNotes[12];


void setup() {
  Serial.begin(115200);
  pinMode(ledPin, OUTPUT);
  pinMode(potPin, INPUT);
  digitalWrite(ledPin, HIGH); // Start with LED on


  if (!cap.begin(0x5A)) {
    Serial.println("MPR121 not found, check wiring?");
    while (1);
  }


  BLEMIDI.setHandleConnected(onConnected);
  BLEMIDI.setHandleDisconnected(onDisconnected);
  MIDI.begin(MIDI_CHANNEL_OMNI);
}


void loop() {
  static uint16_t lasttouched = 0;
  uint16_t currtouched = cap.touched();


  // Read the potentiometer value and map it to the range of MIDI octaves
  int potValue = analogRead(potPin);
  int octaveShift = map(potValue, 0, 4095, 0, 5); // Map to 5 octaves range (0-5)
  int noteStart = 36 + (octaveShift * 12); // Calculate starting note based on octave shift


  // Assign MIDI notes based on potentiometer value
  for (int i = 0; i < 12; i++) {
    midiNotes[i] = noteStart + i;
  }


  for (uint8_t i = 0; i < 12; i++) {
    // if it *is* touched and *wasn't* touched before, send MIDI note on
    if ((currtouched & (1 << i)) && !(lasttouched & (1 << i))) {
      MIDI.sendNoteOn(midiNotes[i], 127, 1); // Send MIDI note on with velocity 127 on channel 1
    }
    // if it *was* touched and now *isn't*, send MIDI note off
    if (!(currtouched & (1 << i)) && (lasttouched & (1 << i))) {
      MIDI.sendNoteOff(midiNotes[i], 0, 1); // Send MIDI note off on channel 1
    }
  }


  lasttouched = currtouched;
}


void onConnected() {
  digitalWrite(ledPin, LOW); // Turn OFF LED to indicate connection
}


void onDisconnected() {
  digitalWrite(ledPin, HIGH); // Turn ON LED to indicate disconnection
}


Next, on your mobile device, navigate to the Play Store and search for the Synprezfm app. Install it; this will serve as our synthesizer application. To ensure a proper connection between our MIDI bookmark and the app, make sure that both Bluetooth and location services are enabled on your phone.

Step 6: Finishing Touches

For the final touches, I covered the air vents of our bookmark with a small mesh net fabric and also affixed the logo to its cover. This step is entirely optional, so feel free to skip it. 

To safeguard our bookmark from external elements, I applied a water-based gloss varnish coating. With this, our build is complete, and now it's time to enjoy your creation.

Step 7: Our Bookmark Is Ready

And there you have it, folks! We have successfully created our MIDI bookmark. Whether you're escaping into the pages of a novel or immersing yourself in a symphony of sounds, this innovative creation guarantees endless hours of entertainment and joy.

I hope you enjoyed following along with my project. Don't forget to show your support by liking and leaving a comment.

Stay tuned for more exciting projects !

Thanks for reading.


Books and Bookshelves Contest

Participated in the
Books and Bookshelves Contest