The Raspberry Pi Message Frame is a pair of photo frames that can record, send, receive and play audio messages between each other. The frames can be anywhere in the world once they are connected to the Internet. In the background the messages are sent and received over email. Scroll to the very end of this post for a video demo
I have small children in the UK and close family in Ireland. I wanted an easy way for my small children to send sweet short voice messages to their family in Ireland without having to log in, launch an app or even be under my supervision. I also wanted them to be able to send the messages at 6am when they wake up but to be played at 11am when Uncle Al rolls out of bed. And vice versa!
I failed a lot with this project, which is fantastic because I learnt a lot.
Notable fail/learning points:
- Pulling out the wires from the button spade connectors. You need the strength of the Incredible Hulk to crimp spade connectors onto wires correctly.
- Soldering pins onto the Voice HAT THE.WRONG.WAY.ROUND. Ha, that was a fun one! I learnt how to de-solder after that 🙂
- Trying to do the whole project on my own. To start with I had LEDs and resistors attached to breadboards and buttons badly embedded into the frame… then I presented my project to the Preston Raspberry Pi Jam and Ivan from CPC told me about some cool LEDs with built in resistors and some lovely buttons with a longer body and satisfying CLICK. Raspberry Pi is a really great community. I recommend putting your project out there early and asking for help/suggestions.
- Trying to do the whole project on the cheap. As I was building 2 frames I really wanted to make everything as cheap as possible. Good quality sound is not easy to add to a raspberry pi zero without an expensive hat. At first I had a cheap 50p speaker with an amp, an audio adapter and a microphone. The speaker was no way loud enough so I was using code to increase the volume which also increased the background noise. It was “good enough” but I was reluctant to finish this project without really good sound. And out of the 3 audio adapters I have, 2 were not working – grrr.
- Then the wonderful people at the MagPi released the Voice HAT for FREE with issue 57 of their magazine! So for £5.99 x 2 I was able to get everything I needed for awesome sound. What did I learn: how to mess around with sound and microphones on the pi and how to increase sound using code.
- I really enjoyed learning how to use imap on python – that’s going to be useful for future projects.
- I kept mixing up SD cards and connecting to the wrong frame. Proper labelling really helps with a project with multiple pis!
- A drill
- A soldering iron
- Pliers or a crimping tool
- A mini HDMI adapter
- A HDMI TV
- Wifi Internet
Parts (multiply everything by two to make two frames!)
- IKEA Ribba Frame £3.50
- MagPi Issue 57 Voice Hat Kit £5.99
- Eight female to female jumper wires
- Two buttons – red and green
- Four spade connectors
- Two LEDs – red and green
- Raspberry Pi Zero W £9.60
- SD Card £5
- Power cable and plug for the Pi Zero £2
- Header Pins for the Pi Zero £1
Total cost is just under £30.00 per frame. Luckily I had a lot of the tech lying around my house like the USB cables/plug to power the Pi and the jumper wires.
Build: The Pi and the Hat
- Setup the Voice Hat, speaker and microphone following step 1 from the Google AIY project: https://aiyprojects.withgoogle.com/voice/#assembly-guide-1-assemble-the-hardware
- Ignore step 1.5 – adding the button wire
- Setup the SD card following steps 4 and 5 from the Google AIY project: https://aiyprojects.withgoogle.com/voice/#assembly-guide-4-get-the-voice-kit-sd-image
- Split the Voice Hat pin strip into sets of 3
- Solder the pins onto the Voice Hat Servo holes
- While the iron is hot, solder the pins onto the PiZero
- Unleash your inner hulk and crimp the spade connectors onto the buttons. I’m told a crimping tool can help with this
- Connect the female to female jumper wires to the servo pins 1, 2, 3 and 4. DON’T connect to the buttons or LEDs yet as these need to go in the front of the frame first.
The Google AIY page shows an image of which pins are which: https://aiyprojects.withgoogle.com/voice/#makers-guide-4-1–connecting-additional-sensors
Build: The Frame
- Take apart the frame into its five pieces: the mount, the inner box, the outer frame, the backing card and the glass. You won’t need the glass, dispose of it safely.
- Drill two 9mm holes into the mount for the buttons
- Drill two 3mm holes into the mount for the LEDS
- Push the buttons into the 9mm holes – my buttons are too long so actually stick out a little bit.
- Push the LEDs into the 3mm holes
- Place the mount into the frame box first, then the inner box. This holds the mount to the front of the frame.
- Place the Voice Hat into the frame box.
- Place the LEDs and buttons into the front of the mount.
- Attach the other end of the female to female jumper wires to the buttons and the LEDs as follows:
- Servo1 (GPIO 6) and GND – Red button
- Servo2 (GPIO13) and GND – Green button
- Servo3 (GPIO 5) – Green LED long leg
- GND – Green LED short leg
- Servo4 (GPIO 12) – Red LED long leg
- GND – Red LED short leg
- For now leave the backing card off
Code – Testing
- Login to the PiZero and add the file button_test.py to /home/pi
- Run button_test.py:
- Press the red button, make sure the red LED comes on and check the screen for “RED Button Pressed”
- Press the green button, make sure the green LED comes on and check the screen for “Green Button Pressed”
If any of the buttons/LEDs don’t work: check the connections from the button/light, check the connections to the voice HAT, make sure you’ve connected the short leg of the LED to GND.
Code – Setup Gmail
You don’t have to create a gmail email account especially for this project, once the messages are downloaded they are deleted from your email. But if it’s not fast enough you might get notifications of new emails.
To use imap from the raspberry pi you need to turn on 2 step authentication for your Google account and then get a special application password. This keeps everything really secure.
- Turn on 2 step authentication. Go here: https://www.google.com/landing/2step/ and follow the steps to turn on 2 step authentication for your Google account
- Get an application password by going here: https://security.google.com/settings/security/apppasswords and selecting “Select app” > Other. Enter your own name for the application, e.g. myframe and select “Generate”
- Make a record of the password
Code – Frame
- On the Pi create two folders in home/pi called piframe_in and piframe_out
- Add these files to home/pi: frame_in.py, frame_out.py, settings.py
- Create two blank files called last_id and errors.log
- Change the text in settings.py
- toaddr – the email address of the other frame/person you want to send the voice messages to
- me – the email address you just setup
- The application password you generated above
- Add the following lines to crontab so they run all the time and on reboot. Make sure you run
sudo crontab -e
Code: How it works
frame_out runs all the time waiting for a button press or new voice messages. When you press the red button, the red LED turns on to indicate recording. Record your message by speaking at the frame. Press the red button to stop recording. After around 20 seconds the green light will flash to indicate the message has been sent. frame_out creates a wav file of your recording and gives it a unique name of the current date/time. It saves it into piframe_out folder then it emails it. Once the file has been emailed it is deleted from the piframe_out folder.
frame_in runs every minute, checking gmail for new messages. It looks for the unique subject word “piFrame” and it keeps track of the ID of the last email it downloaded in the file last_id; so it doesn’t download old messages that it has already played. When it finds a new message it downloads the attachment to the piframe_in folder and deletes it from the email account.
frame_out also checks the piframe_in folder for new messages. Once a new message appears, it lights up the green LED. When you press the green button it will play the message through the speaker then it will delete the file from the folder.
I recommend having the to and from address the same to start off, so you can do all your testing on one frame by sending messages to yourself.
None of the out files or in files are kept on the raspberry pi, but they are still in the email accounts in both the sent folder and the trash of each account.
Once everything is working, put a lovely picture in the mount. The frame is not a standard UK photo size. It’s 5×5. I had to chop up a 7×5 inch photo to fit it in the mount. I stuck the microphone to the back of the mount, facing outwards but it got loose and wandered around. It didn’t seem to affect the quality of the recording. Everything does fit in between the mount and the backing card, but can be quite fiddly to get it to close. And the damn jumper wires like to wander too – run button_test.py when you’ve sealed it to make sure everything is still connected behind the photo!
Seal up the frame. The back board has a handy hole in it for the power cable to run out:
Make another frame, set it up in your grandma’s house in Australia and start sending her voice messages!
With more money you could add a camera and a screen to the frames and send each other video messages (don’t get weird)
What about three frames – one for you, one for grandma and one for nana? Your frame has a toggle switch between grandma and nana that allows you to choose which favourite grandmother (nana) you want to send your message to. Grandma and nana’s frames can only talk to your frame.