Monday, 30 July 2012

Makey-makey Raspberry PI Soundboard

I recently ordered a Makey-Makey and thought it would be fun to create a pencil-drawn soundboard with it. However it seemed limiting to drag around a computer to play the sounds. So why not use my raspberry pi?

The makey-makey isn't going to arrive until next month, but I've created the kiosk style setup for it on the pi already.

Hopefully when it arrives I'll be able to plug it in and go!

Starting from a base install of 2012-07-15-wheezy-raspian, logged in as 'pi':

$ sudo apt-get install git
$ cd /home/pi
$ git clone https://github.com/dalethatcher/piboard.git
Edit /etc/inittab:

$ sudo nano /etc/inittab
Make sure two is the default runlevel:

# The default runlevel.
id:2:initdefault:
Then replace the line:

1:2345:respawn:/sbin/getty --noclear 38400 tty1
with:

1:2345:respawn:/sbin/getty -a pi -l /home/pi/piboard/run.sh 38400 tty1
Reboot and verify that, after start up, the program is running on the first screen.

41 comments:

Sean said...

wheee thanks for this! i'm so excited for my makeymakey to arrive...

CruzMark said...

Cool! Totally got this working. Added python code to include the the pin out inputs on the MM and loaded up a bunch of spooky sound effects.

Plugged the MM directly into the Raspberry Pi (no mouse plugged in) and was able to trigger sound effects to my hearts content. Nice, too, because you can play more than one at a time and layer them.

I was worried that the Pi might not be able to power the MM and I'd have to add a powered USB hub, but it worked fine.

Outputting audio via the phono plug on the Pi to a PA system.

This is going to make a nice interactive Halloween display!

Thanks!

Dale said...

@CruzMark Glad it's working for you. You actually beat me to trying it! :)

Lauscher said...

hello, i'm a total noob in phyton, how do i link more sounds to other keys (like 'a' 'b' 'c') I understand the structure of the code. but when i try to add a new event i have no idea, how to define the new key.

elif event == curses.KEY_a: #for key 'a' didn't work

thy in advance
Bene

CruzMark said...

Bene,

Look at the bit of code for the 'q' key and use that syntax instead of curses.

Hope that helps.

CruzMark said...

Bene,
Sorry I was so brief last night. here you go:

elif event == ord('a'):

Dale said...

@CruzMark thanks for fielding the question!

djcutlet said...

Hey @Dale and @CruzMark,

I just got this working, but I'm having trouble with the sound quality from the 3.5mm jack. There's a low-level static constantly, and little blips here and there when the processor is working. Are you guys having this issue?

Thanks,

Michael

Lauscher said...

Thank you CruzMark, it works actually! Hurrei! ;>

Dale said...

@djcutlet I've not had problems with the sound from my PI. Maybe try a different USB power source?

CruzMark said...

I've also not had sound problems from the Pi. There are folks at the Pi Forums reporting sound issues, though.

CruzMark said...

http://youtu.be/wBvOMJ4TFWk

Dale said...

@CruzMark really nice video!

Goat said...

I'm struggling to get mine to run, all the steps went ok but it doesn't run. I have tried running it from idle but it says pygame doesn't exist, any ideas?

Dale said...

@Goat which distribution are you running?

K Knar said...

Hello...
Many thanks for your post, this is my first project on raspberry

for information, you can add :
pygame.mixer.pre_init(44100,-16,2, 512)
just before pygame.init()
to speed the action, otherwise, the play start with 2 seconds of delay.

Bonne Continuation.
K

Dale said...

@KKnar Interesting, I didn't have a problem with delays last time I tried, maybe something has been updated recently that breaks the code?

jaycuestu said...

I'm not getting any sound from the program, but I can make sound work from aplay for the same '.wav' files. The board.py script runs fine, responds to keyboard inputs, acts like it's playing sound files but nothing happens. I'm running Wheezy Raspian.
Any thoughts?
Thanks!

jaycuestu said...

Okay, not sure why this fixes it, but adding the following line before the init in 'board.py' makes it work.
pygame.mixer.pre_init(frequency=44100, size=-16, channels=2, buffer=256)

When I first added the line, the frequency was set to 22050, and I noticed that aplay was running at the higher rate. So I changed it and bingo!

Thanks for the blog.

Dale said...

@jaycuestu thanks for the tip and glad you got it working.

Germain said...

Thanks for the explanations.
Yet, it I can launch the soundboard from the terminal, It doesn't launch automatically despite the changes to the inittab file...

Any idea?

regards,

Germain

--


1:2345:respawn:/sbin/getty -a pi -l /home/pi/piboard/run.sh 38400 tty1
2:23:respawn:/sbin/getty 38400 tty2
3:23:respawn:/sbin/getty 38400 tty3
4:23:respawn:/sbin/getty 38400 tty4
5:23:respawn:/sbin/getty 38400 tty5
6:23:respawn:/sbin/getty 38400 tty6

Dale said...

@Germain I've just tested with that change in my inittab and it still works ok for me with the 2012-12-16-wheezy-raspbian.img. I've uploaded my working inittab to github. If you clone again please compare your file and see if there are any differences. The '-l' may be catching you out? (that's a lower case 'L')

Germain said...

Thanks Dave, this is now working!

Mallory Moyer said...

Hello.

Thanks for this tutorial. I just got my raspberry pi in the mail and formatted my SD chip but I cant figure out how to use this code. Can anyone give me some direction? Do I plug the code in the terminal?

Thanks,
Mal

Mallory Moyer said...

ps.

also, so far I have my makey makey hooked up to garare band but I want to be able to make my sounds portable. I was wondering if someone could explain how to use this code and put my sounds on the the rasberry?

Thanks,
Mal

Dale said...

@Mallory Moyer The lines that begin with a '$' are meant to be typed in at a command prompt. The other sections are some configuration files that need to be edited. It sounds like you don't have much unix experience so I'd suggest trying to find a friend that has who can help you. O'Reilly have a book that looks like it would get you started as well: http://shop.oreilly.com/product/0636920023371.do.

You'll need to convert any sounds that you want to play into WAV files. I expect you'll need to create a project in Garage Band and then export it as WAV.

Mallory Moyer said...

Hi Dale,

Thanks so for responding. Well it's true that I know very little about physical computing but so far I have been able to re-code the makey makey and program the SD chip and get the rasberry to work so i'm feeling ok with tackling this. Also I unfortunately have no friends that know how to do this. So i'm going to try and get it to work. Im also familiar with html if that helps. And my project is due in 2 weeks and I am dependent on this working :)

I entered this piece first:
sudo apt-get install git
and it worked
Then I entered this:
cd /home/pi
it says 404 NOT FOUND failed to fetch address

Do you know what maybe I did wrong?

Thanks,
Mallory

Mallory Moyer said...

oh wait im sorry. I enter in the first bit of code and it works. Than it asks me if i want to continue and use 306kb and I enter the letter Y. Then I get the error.

Mallory Moyer said...

I have a 16GB chip and the program says it only using 13.8MB. So I guess its not connecting to the internet to fetch the files it needs...

Mallory Moyer said...

I figured out how to get passed the error. I followed this great tutorial:
https://www.youtube.com/watch?v=3bOn0K8o8-4

Now its installing :D

I also downloaded the book too so i'll start reading up. Thanks Dale

Post it Art Creators said...

Hi, I am just trying to get your program but think the gitup adress is wrong now.

Post it Art Creators said...

I am trying to change the sounds but I only hear a clicking sound the sound files are also wav but bigger. What can I do?

Androo Hazy said...

hi there, i managed to get it all working ok, now just trying to figure out how to connect a video file to each sound. so instead of just being able to produce audio it plays a video on the screen at the same time? Any Ideas

Dale said...

No idea on video sorry.

Dale said...
This comment has been removed by the author.
Chris Pruski said...

Hi I just got this working, great. How do I get other sounds to replace the left right words?

Dale said...

@ChrisPruski You can add more WAV files if they're in a compatible format (16bit, mono 44100Hz works possibly others). Then you can edit the program in board.py to add them.

Johannes Dalenbäck said...

Hello Dale!
Thank you very much for this program. I have a question:
Is there any way to make the keyboard buttons act like clicks instead of press and hold. In other words, can I stop the keyboard from repeating commands if I press and hold a key down? If I press any of the arrow keys I want a sound to play only once, even if I hold the key down, and when i release the key and touch it again I wan´t it to play the sound once more and so forth. I would be really greatful for a reply.

Best regards
musicunlim@gmail.com
Thank you!

Dale said...

@Johannes The easiest way is probably to just turn off key repeat. Have a look here: http://www.tutorialspoint.com/unix_commands/setterm.htm.

I've not tried but it should work.

Alexa Trinidy said...

i cant get the 1.234 part to save. how do i do that?

Dale said...

@Alexa The "^X" at the bottom of the screen means you have to press Ctrl-X.