A Simple Raspberry Pi Electronic Organ Based on MPR121



Introduction: A Simple Raspberry Pi Electronic Organ Based on MPR121

About: Hi,I'm from DFRobot, a dream factory for robo-holics to make a better world.

I am a big fan of TwoSetViolin, they bring me a lot of fun and I start to appreciate the joy of music since I followed their channel last year. They have a program called LINGLING40HOURS, in which there are many linglings (talented fans) showing their music memes. Well, I know nothing about instruments, so it’s hard for me to come up with any good music memes. Okay, at last, I decided to utilize my expertise to DIY an electronic organ to join them.



Step 1: Electronic Organ Key Connection

1. First we have to figure out the logic before soldering: MPR121 can output 12 signals, but we need 3*7=21 signals. So here I am gonna divide the 12 signals into two groups: X (0-4), Y(5-11), then we can get 35 signal combinations.

Solder conductor wires onto the touch board(21 in total). I soldered the green and yellow points.

2. Prepare the organ plate

Cut cardboard of three layers and prepare some small cardboard strips for fix the organ keys.

Stick the touch board onto the middle layer of the cardboard. And drill holes on the boards, then pull out the conductor wires.

Organize the wires and cut out the extra parts.

3. Prepare the organ keys

Wrap the copper tapes around the ice cream sticks.

Stick them onto the cardboard.

Step 2: Software Preparation

I used the MobaXterm here.

Step 3: Operation

1. Hardware Connection

Connect the speaker module to P22 of the expansion board, the touch board to IIC port.

You can also select other pins, but please make sure it is a GPIO port.

At last, plug in the power cable and Ethernet cable.

2. Programming

1) Download libraries files. I have placed them into a zip, click the link to download them to your PC.

  • The unzipped files should be like that in the image above.
  • Drag the files to mobaxterm. (Please select Desktop path)
  • Create a python file in your computer and name it as 36.py.

2) Once a button is pressed, the speaker will play the corresponding note. The touch function in MPR121 library can only output 0~11, and we have to extend the 12 signals. So here I take 0~4 as X, 5~11 as Y, so there will be 5*7=35 combinations. I only set the G clef (treble clef), the F clef (bass clef), the C clef (alto clef). When x=1, bass clef, the frequency will be determined by the value of Y. When x=2, alto clef, the frequency will be determined by the value of Y, and so on.

Copy the following codes into 36.py file.

import sys
import time
import Adafruit_MPR121.MPR121 as MPR121
import RPi.GPIO as GPIO
Buzzer = 22
Buzz = GPIO.PWM(Buzzer,440)
print('Adafruit MPR121 Capacitive Touch Sensor Test')
# Create MPR121 instance.
cap = MPR121.MPR121()
CL = [131, 147, 165, 175, 196, 211, 248]
CM = [262, 294, 330, 350, 393, 441, 495]
CH = [523, 587, 659, 698, 784, 880, 988]
if not cap.begin():
    print('Error initializing MPR121.  Check your wiring!')
print('Press Ctrl-C to quit.')
last_touched = cap.touched()
x = 0
y = 0
while True:
    global Buzz
    touch = []
    current_touched = cap.touched()
    for i in range(12):
        if n&1:
        n = n >> 1
    if len(touch) == 2:
    if x==1:
    elif x==2:
    elif x==3:
    x = 0
    y = 0
    #last_touched = current_touched

3) Drag the 36.py file into the examples of mobaxterm.

Step 4: Effect Display

As shown above, I pressed the sixth note of the bass clef. That's all for my work, thanks for reading!

Be the First to Share


    • Photography Challenge

      Photography Challenge
    • Anything Goes Contest 2021

      Anything Goes Contest 2021
    • Jewelry Challenge

      Jewelry Challenge