I am working on a project to demonstrate some of the things you can do with a Raspberry Pi. I am doing thisÂ for our local library. One of the things I thought about building is aÂ drum machine or a piano. The premise is when you touch a switch it causes the Raspberry Pi to play a sound. Very easily done in Python (the language I know best).
However, since this project is to target new users of the Raspberry Pi, I thought it would be nice to useÂ the Scratch programming language. This is a visual programming language that is very powerful and really kid friendly.
The problem with using Scratch though is that it doesn’t natively handle the GPIO interface (General Purpose Input Output). These are 40 pins (or 26 on the older models) coming out of the Raspberry Pi that you can use to control hardware such as robots.
There is a project called ScratchGPIO that gives me the control I need. However, I had a problem with playing sound out of the computer when using the GPIO pins. Each time I would make the program play a sound, Scratch would exit (force quit). Looking through several forum threads did not turn up aÂ solution quickly.
Finally, I found a forum post that gave an answerÂ that solved the problem for me. I wanted to include it here in case it may be a help to others (and because I will probably forget the answer the next time I need it). Hopefully no one will have to dig as long as I did to find a solution.
The steps below assume that you have already read the instructions for getting the program installed. It is also probably a good idea to run the basic first program. Having said that, you probably wouldn’t have come here unless you already had the program up and running and fell into the same problem I had with sound.
- Start the ScratchGPIO program. When you install it, it will place an icon right on your desktop. Just double click the icon.
- After it is loaded, simply close it.
- Open a terminal window. I do this by typing “alt+F2” that will open a start program box. Inside that boxÂ type “lxterminal” and hit enter. Don’t actually type any of the quotation marks in this step.
- Inside the terminal window type “/usr/bin/scratch.old &” then hit enter. Again, no quotes.
- Scratch will re-open. Go to File | Open and select the “rsc” program (which is installed when you install ScratchGPIO).
That should make it so you can now use sound in your programs when using the GPIO interface.
I really don’t know if all those steps are necessary. I know I have opened aÂ program I was working on in step 5 without opening the rsc program. It worked fine without doing that final step.
I would think that some of this can be automated with a script if someone wants to try and think that through. For me, the steps aren’t too cumbersome.
This is another one of the many things I have written up so that I can find the answer for myself when I need itÂ in the future. I hope it is a help to others.
Buy a Raspberry Pi
If you don’t have a Raspberry Pi, head on over to MCM Electronics and buy one from the official US distributor.
2 thoughts on “ScratchGPIO Sound Problem”
I’ve automated this in the dev version – it creates a desktop folder that selects the older Scratch version
Thanks for replying here. I will give it a try tomorrow.