Use ‘Headless’ Raspberry Pi to Enhance a Display

Year 4 have a great ‘Charlie and the Chocolate Factory’ display. It takes up half of their practical area and welcomes visitors in with a variety of 3D objects and things to do. All it lacks is sound, which gave me an idea…

What if I could make a machine that would play a ‘random’ sound effect or quotation from the book / film(s) when someone entered the area. This is easy to do in Scratch but I’d need some kind of sensor to activate the script and would need a device to run it.

We’ve got some Raspberry Pies (Pis?) kicking around that are somewhat under-used so I wondered if I could use one of those. My idea was to use the Pi to run the program ‘headless’, that is to say without a monitor, keyboard or mouse. The sensor could be a Lego WeDo ‘distance’ sensor which simply plugs into a Lego hub which itself plugs into the Pi’s USB port – so no need to mess around with breakout boards etc. It took a bit of working out how to make this work ‘in the field’, as it were, so I thought I’d document the process in case anyone else would like to try it out. Here goes…

  1. I downloaded and installed the latest Raspian build onto the Pi using the ‘Noobs’ route. See here.
  2. I grabbed a load of sound effects from the internet and used Audacity to turn them into AIFF files. I tried WAVs first but the Pi had difficulty with them.
  3. I imported the sound effects and renamed them as the numbers 1 to 19
  4. I plugged in the Lego sensor and wrote the following program…
  5. choc
  6. The program activates a random sound effect if someone comes within the range of the sensor. This is about 10cm so you have to think carefully about where to place it.
  7. Now came the tricky bit – how to make it run by just plugging it in and switching it on, without a keyboard, mouse or monitor. I must admit it took a bit of research and experimentation to get it to work but, in the end, this was the easiest way to achieve it… To work, you need to edit the /etc/profile file on the Pi. In laymen’s terms, it’s a file called ‘profile’ in a folder called ‘etc’ which is, itself, in the root directory of the Pi. If you click on the file manager in a Pi it defaults to your ‘home’ folder, so to get to the root, keep pressing the ‘up one directory’ button until you find ‘etc’.
  8. Once you’ve found the ‘profile’ file you’ll need to open it as administrator in order to edit it. To do that, go to the ‘terminal’ and type sudo leafpad. This will open the Leafpad text editor in admin mode.
  9. Then, drag and drop the ‘profile’ file onto the open Leafpad window. If this doesn’t work, just go to ‘file / open’ in Leafpad and load it from there.
  10. Once the ‘profile’ has loaded, add the line: scratch presentation /home/pi/Documents/ to the end to load your Scratch program and make it auto-run. Mine was called ‘’ and was stored in the ‘Document’ folder but yours might be elsewhere. ‘Presentation’ mode (in the command) has the effect of running the program at full screen and activating the ‘green flag’ to run it. The former wasn’t important to me, but the latter was. Here’s the finished ‘profile’ file with the line added…
  11. prof
  12. Save the file
  13. If your program is controlling audio, as mine was, you might need to make sure that audio is set to ‘analog’ so you can plug in speakers. To do this, find the relevant setting by going to terminal again and typing sudo raspi-config. You might also need to use this to set the Pi to auto login and run the GUI rarther than command line, if it doesn’t already. Settings are relatively easy to find but, if you’re stuck, let me know.

That’s it! Now unplug the Pi, move it to it’s destination. Leave the Lego hub and distance sensor plugged in, plug in some speakers and off you go!

Leave a Reply

Your email address will not be published. Required fields are marked *