Visual echo on Raspberry Pi

This hack shows how to create an interactive “visual echo” using Raspberry Pi, the Pi camera and a projector. The camera grabs a photo in regular intervals and displays the scene onto a screen, overlaying older pictures that are fading out.

Ingredients

  • Raspberry Pi (used 3 B+ for the performance, older ones may be fine)
  • Raspberry Pi camera (used version 2, older one should be fine)
  • A projector (works with my LED projector, but better when brighter)
  • USB charger, HDMI cable, mount
  • Mouse and keyboard (to start)
  • Material for camera mount (optional, I used some wood) 

Basic setup

  • Install Raspbian
  • Connect the camera
  • sudo raspi-config
    • Interfacing options -> Enable camera
    • Boot options -> Console Autologin
    • Save and reboot
  • sudo apt-get install fbi imagemagick
  • raspistill -n -w 640 -h 480 -o out.jpg
  • touch play.sh
  • chmod +x play.sh
  • nano play.sh
#!/bin/bash
while [ true ]
do
# take picture with camera, store as grab.jpg
raspistill -n -w 640 -h 480 -o grab.jpg

# make it darker and store as grabdark.jpg
convert grab.jpg -modulate 50% grabdark.jpg

# take the previously shown picture out.jpg and make it darker
convert out.jpg -modulate 50% outdark.jpg

# combine both darkened pictures into one, save as out.jpg
convert grabdark.jpg outdark.jpg -compose Plus -composite out.jpg

# wait a bit and repeat
sleep 1

done

The shell script play.sh will take a picture (640×480 is the resolution of my projector, adapt to your own needs) and combine it with the previously shown picture, and repeat this in an endless loop. We start this script in the background, calling

./play.sh &

Now we have a script that takes photos, but we also want to show them. We use fbi, a command line viewer for pictures, and trick it into regularly reloading new pictures with the same name:

ln out.jpg ln1.jpg
ln out.jpg ln2.jpg
ln out.jpg ln3.jpg
fbi -noverbose -autozoom -t 1 -cachemem 0 ln1.jpg ln2.jpg ln3.jpg

These commands create 3 files that link to the same file (out.jpg). Then fbi will start displaying the picture endlessly, and regularly take into account the picture update that happens in the background.

To finish and shutdown, press Ctrl-c to exit fbi. Then on the command line, use fg to bring play.sh to the foreground, and press Ctrl-c to exit it as well. Then you can do a regular sudo shutdown -h now to switch everything off. After a restart of the Pi, the ln commands are not needed anymore, so this will do the next time:

./play.sh &
fbi -noverbose -autozoom -t 1 -cachemem 0 ln1.jpg ln2.jpg ln3.jpg

Mount

For the mount I used a mix of stuff from the hardware store and wood I had at home to build this multi-purpose setup, that can be used for the magnifier as well. To get a better effect than me in the video above, it’s worth to play with the positioning of camera and projector, and potentially the -roi setting of raspistill.

Conclusion

The effect shown here is very simple, but still fun. There are probably better ways to update the picture display, and there are definitely nicer effects that can be done with imagemagick. I’m glad to hear about any improvements, or links to more elaborate approaches.

Leave a Reply

Your email address will not be published.