A Simple Raspberry Pi Electronic Organ Based on MPR121

by Jaychouu in Circuits > Raspberry Pi

2226 Views, 9 Favorites, 0 Comments

A Simple Raspberry Pi Electronic Organ Based on MPR121

IMG_20201114_162544.jpg
Making a simple Raspberry Pi Electronic Organ

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.

Supplies

Hardware

Electronic Organ Key Connection

IMG_20201112_104053.jpg
6N]JV(JD9Y2`T{5B]$4J666.png
IMG_20201114_193242.jpg
qq_pic_merged_1605422009001.jpg
IMG_20201112_142217.jpg
IMG_20201113_103840.jpg
qq_pic_merged_1605422139677.jpg
IMG_20201113_111628.jpg
qq_pic_merged_1605422397691.jpg
qq_pic_merged_1605423349117.jpg
IMG_20201114_174809.jpg
qq_pic_merged_1605353718141.jpg

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.

Software Preparation

I used the MobaXterm here.

Operation

添加ku.gif
}5`G9AQ9`O]H3%N4RWO)XKD.png
_8]R7HG02X~N8`31J240T2B.png
W]APS}%@L04]VSMUX3TOB04.png
MYLS$T3_2HM~$CEU1`Z1H)C.png
IMG_20201114_184252.jpg
C9)R[24TMFSJ_55@N{P%~2B.png
路径.gif

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
sys.path.append('../')
import time
 
 
import Adafruit_MPR121.MPR121 as MPR121
 
import RPi.GPIO as GPIO
Buzzer = 22
GPIO.setmode(GPIO.BCM)
GPIO.setup(Buzzer,GPIO.OUT)
Buzz = GPIO.PWM(Buzzer,440)
Buzz.start(0)
 
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!')
    sys.exit(1)
     
print('Press Ctrl-C to quit.')
last_touched = cap.touched()
print(last_touched)
x = 0
y = 0
while True:
    global Buzz
    touch = []
    current_touched = cap.touched()
    n=current_touched
    print(n)
     
    #y=current_touched[1]
    for i in range(12):
        if n&1:
            touch.append(i)
        n = n >> 1
    if len(touch) == 2:
        x=touch[0]
        y=touch[1]-5
    print(x)
    print(y)
    if x==1:
        Buzz.start(50)
        Buzz.ChangeFrequency(CL[y])
    elif x==2:
        Buzz.start(50)
        Buzz.ChangeFrequency(CM[y])
    elif x==3:
        Buzz.start(50)
        Buzz.ChangeFrequency(CH[y])
    else:
        Buzz.stop()
    x = 0
    y = 0
    #last_touched = current_touched
 
    time.sleep(0.5)
     
    #GPIO.cleanup()

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

Effect Display

SWZ`R55C~{@F5`5Q2IY3BG8.png

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