I wanted to make a device like microdrum. Basically, my aim is to make the RPi as a sound module or drum module. I read hits from piezo sensor and send the signal to my RPi with the help of Arduino Uno and RPi allows me to generate sound. I am using USB serial communication and Pygame for audio. The problem is when I hit the piezo, RPi generates sound but a little after the hit. My guess its 300 ms.
Here is my python code:
import serial import pygame pygame.mixer.pre_init(frequency=44100, size=-16, channels=2, buffer=1024) pygame.mixer.init() pygame.init() snare = pygame.mixer.Sound('snare.wav') arduino = serial.Serial('COM23', 115200) while True: data = arduino.readline()[:-2] #the last bit gets rid of the new-line chars if (data=='7575'): snare.play(loops=0, maxtime=0, fade_ms=0)