Posts: 2
Joined: Sun Sep 30, 2018 1:26 pm

RasPi Drum Sound Module

Sun Sep 30, 2018 2:16 pm

Hello everybody,

I'm currently building my first project with a RasPi 3b.
The goal is to play a sound file (drum, cymbal, beep...) using a piezo plate as the trigger.
In the end I want to use 2 triggers to play a bass drum and a snare or cymbal with my feet.

I wanted to document my progress so far and ask some questions at the end, maybe someone can help.

1 Raspberry Pi 3b
1 ADS1115 16-bit I2C ADC (Analog-Digital Converter)
1 Piezo plate
1 1M Ohm resistor
1 3,3V Z-Diode

Piezo-Wiring2.jpg (40.17 KiB) Viewed 786 times
The ADC is wired to the RasPi via the I2C pins and 5V VDD.
The 1M resistor reduces the voltage transmitted from the piezo to the ADC. If it still goes higher, the Z-Diode should limit the voltage going to the ADC to 3,3V. The ADC can't handle more voltage than VDD and I wanted to be on the save side, that's why I set the 3,3V limit.


Code: Select all

import time
import board
import busio
from adafruit_ads1x15.single_ended import ADS1115
import pygame

#initialise pygame with low latency
pygame.init(44100, -16, 1, 512)

bass = pygame.mixer.sound('/home/pi/drum-module/samples/bass.wav')

#create the I2C bus, be sure to enable I2C on the Pi first
i2c = busio.I2C(board.SCL, board.SDA)

adc = ADS1115(i2c)

#read adc value and play soundfile then wait
if adc[0].value > 5000:
You can read two basic value from the ADC: adc[x].voltage and adc[x].value (for x is the analog input you use)
I think .value is easier to use cause it's in whole numbers (for example 125, 5819, 12854...) compared to voltage (0.142, 1.634, 3.174...). And I noticed that sometimes the change in value is mor correct than the voltage (don't know why).

1. If I don't put the time.sleep after .play it can happen to trigger the sound multiple times cause the .vlaue might not fall below the 5000 instantly.
2. If I want to add multiple inputs I's always limited to play one file at once cause of the time.sleep.
3. No matter how hard I hit the piezo the sound always plays at the same volume
4. You need to apply preassure long enough on the piezo. If you just hit it hard once and fast it might not register.

1. Can I change the output volume based on the trigger value?
2. Can I play multiple sounds at once when using multiple triggers at the same time?
3. Can I let the file just play once without needing the time.sleep somehow?

I'm open for every input you guys have on this. I'm learning with every step I make.

Return to “Graphics, sound and multimedia”