2019-05-05 ___O_n__b_u_i_l_d_i_n_g__a_n__a_u_d_i_o__p_l_a_y_e_r_________________ Today I want to share my experiences in building an audio player for a child that has not learned to read (yet). In the household we rip CDs as a backup or borrow media from friends to listen to. Audio plays are high in demand. But all these digital media need to be played somehow. So the idea has been to use a media playing device that blends well into a children's room, is easy to use without having to read. Does not snitch on its user due to software out of our control and plays back any audio file that's been fed to it. As you may guess, a research for ready made players has made me come back empty handed. So I have decided to build my own. Since I had a hastily bought Raspberry Pi 3 B+ already around I decided to use it. But how should I design the interface? I have seen ideas of using rfid tokens embedded in a 'cover card' that the child can hold on to the player to make it select the media but that seems wasteful to me. I don't want to add yet another physical item to the chain, also the cards would probably get lost soon. So I decided for a visual media selection mechanism by offering an image of the original CD cover, which means the device should feature a display of some sort. Touch interfaces are right out as they don't provide good tactile feedback, also it is not obvious that there is something available to act on. Hence buttons were added. Big, arcade buttons as they provide a nice click and come in colors. Volume should be capped off at a limit set by us, so the volume knob is an actual knob stuck on a rotary encoder. I have used an adafruit speaker bonnet and a pair of small 3W stereo speakers that go with it to handle the actual audio output. The device is just another sound card wrt the linux kernel, so no further action from our side was required. The device should be powered on and off by itself, so I added a pololu power switch which can turn on the device by grounding one pin on the switch and turn itself off by rasing another PWR pin. I have reused the same button to do the turning on, and hooked it also to a GPIO on the arduino to detect the power off. That in turn will shut down the player and pull the PWR pin. Diodes prevent current from going the wrong way. The display is a 3,4" HDMI display by waveshare which came in a reasonable size and prize ratio. The housing has been designed in OpenSCAD and I consider it to be in beta stage. The holes for the speakers are a bit off and the through holes for the Raspberry Pi's USB/Network ports were a bit too tiny, so I had to file both manually to make them fit. The player software itself has been a breeze to write. It's a smallish python script using pygame for image display and audio playing. Upon start it scans a media directory for cover images, which can be selected and the audio is played. The best design decision has been to separate the event generation from the actual event handling, so whether the player is designed by keyboard or actual GPIO is a matter of switching a dispatch dictionary. Determining the state transitions of the player as well as the non volatile config stathas been a bit trickier but all was done in a couple of hours. Then the debugging happened for some more hours. The most annoying part has been the GPIO handling of the buttons. I have used the gpiozero library for easy access and its callback mechanism has fit in perfectly in generating the correct events for the main event loop in my code. BUT it seems there's a bug in the debounce parameter when using it with the when_pressed event type. After a lo debugging session I have discovered that I can circumvent the whole issue by using the when_held event and configuring a small holding timeout. Now all the buttons are properly debounced and show exactly the effect I would have expected from when_pressed in the first place. What a relief as the release date was near! For the moment the device's wifi has been left turned on for syncthing source code and media files automagically. Once the source has stabilized I will probably add a auto load of media via usb and disable wifi. I will release the files as they stabilise under a CC-BY-NC-SA license available under link below Stay tuned, I will put up pictures of the finished device when I wake up again. ___References_________________________________________________________