2017-01-02 (M) Tough Pi-ano

Getting sound files to play from Python without a lot of overhead wasn’t easy but it was simplified by Pygame. “Pygame is a set of Python modules designed for writing games.” This was chosen because a forum reply said that Pygame would make music playing simple. It was also important that it not take a lot of processing power since the Pi Zero didn’t have a lot to spare.

Several examples were necessary to find the cleanest and correct way to play a sound. The technique used by Pimoroni in the Piano Hat was difficult for me to understand but it seemed that the code was able to index all the files in a directory and play the XXth file from that directory regardless of name. That’s more than I need to worry about since I can name my files in a consistent manner. It is also worth noting that the Pimoroni code is far more bulletproof than what will be written for the Tough Pi-ano. Since all naming and code is controlled before use it shouldn’t be a problem.

Once it was possible to play a sound file by inputting the file name it was possible to play a tune. At first a single sound was played at the boot. Then ten files were played in ascending order, then all 61 files that were included with the Pimoroni Piano Hat download.

Video of the Pi booting and playing all 61 notes

To do:
  • Figure out GPIO recognition in Python
  • Figure out how to play .wav files from Python
  • Write Python code to play audio when triggered by GPIO
  • Add code to change octaves based on GPIO input

The rest of the posts for this project have been arranged by date.

First time here?

Completed projects from year 1.
Completed projects from year 2



This disclaimer must be intact and whole. This disclaimer must be included if a project is distributed.

All information in this blog, or linked by this blog, are not to be taken as advice or solicitation. Anyone attempting to replicate, in whole or in part, is responsible for the outcome and procedure. Any loss of functionality, money, property or similar, is the responsibility of those involved in the replication.

All digital communication regarding the email address 24hourengineer@gmail.com becomes the intellectual property of Brian McEvoy. Any information contained within these messages may be distributed or retained at the discretion of Brian McEvoy. Any email sent to this address, or any email account owned by Brian McEvoy, cannot be used to claim property or assets.

Comments to the blog may be utilized or erased at the discretion of the owner. No one posting may claim claim property or assets based on their post.

This blog, including pictures and text, is copyright to Brian McEvoy.


2016-06-04 (Sa)

Comments