This is not a new project to the Raspberry Pi world, but since I gave myself a new Raspberry Pi model A+ for Christmas, I wanted to do a simple and fun project. I have actually been engaged in a couple of more complicated projects on the Raspberry Pi that I don’t completely understand yet. So this one is just a learning exercise to better understand how to control physical devices with the Raspberry Pi.
Setup and Code
I got my start in this project by watching a video by XtraPerianer and then reading his writeup about it. I don’t go into any details here about how to accomplish the task, I just wanted to show you my project and a couple of things I learned in the process. You need to visit XtraPerianer’s video and site to get the details.
I did run into one problem that should be noted. When I copied the C++ code for the song from the Raspberry Pi forum, there were 4 extra lines at the beginning of the code block that my compiler choked on. Make sure you don’t included these 4 lines when you make your own .cpp file.
# -------------------------------------- # Written by Scott Vincent # 16 Feb 2014 # --------------------------------------
Of course the code author should get credit, but for the purposes of compiling the code you should eliminate these lines. At least it did not work for me to have these included. Admittedly, I am clueless as to proper C++ formatting. There may be something that I did wrong.
UPDATE: The problem is the use of # as a comment marker. Thanks to Tnwheeler for pointing out in the comments below the proper comment notation for C++ code.
Here’s my video of the project with some annotations included.
What I Learned
I have done some GPIO programming with the Pi in the past. It has been a bit over a year and I don’t remember all the details. But, this was a simple refresher to get the software I needed for my new Raspberry Pi. The programming I did in the past (and what I have been studying for a few months) is Python. However, this project uses C++. The code has enough comments in it that I pretty much understand what is happening. Now I want to modify it and have my floppy play other songs.
One of my future projects will make heavy use of stepper motors. This is a good reminder of how they work and how to program them.