Skip to content

Mirror your frame in your house using old cheap hardware

rafik24 edited this page Oct 2, 2020 · 4 revisions

How to mirror your photoframe pictures in multiple locations using old/cheap hardware interfacing with an RPI Zero W

Concept:                                                                                                             

   SLAVE_1 <----------------|MASTER Photoframe|----------------> SLAVE_2
                                                                   |
                                                                   |
                                                                   |
                                                                   |
                                                                   V
                                                        SLAVE_N

This will allow you to have a main photoframe plugged to a screen via HDMI and one or more slave frames on a budget which unfortunately do not have an HDMI connector and can only display pictures from a USB stick or SD Card.

However these frames would most of the time have a decent screen that can be used to do what we want which avoids buying monitors, or laptop screens with a display adapter which cost dosh.

In order to re-use the hardware we can interface it over USB by making an RPI Zero act like usb storage and push over wifi the picture displayed by the master photoframe.

There is only one down side when updating the picture, as USB storage need to be unmounted and remounted when a new picture is pushed over wifi (at least for the frames I used whic are very old)
however, a little hack has been put in place so when we push the picture over Wifi we dismount and remount USB then the frame can catchup (Different frames behave differently here).

Enough talk, lets get our hands dirty :-)

  1. Download Raspbian Buster from https://www.raspberrypi.org/downloads/raspberry-pi-os/
    (I used the light version any version would do, tried Jessy before but kernel modules where missing to enable USB OTG so I tried Buster which just worked out of the box)

  2. Burn the image to your SD card using Balena Etcher, win32disimager or else ...

  3. Add your Wifi ESSID and creds by following the Wifi headless tutorial https://www.raspberrypi.org/documentation/configuration/wireless/headless.md

  4. Create a new file named ssh on the SD card so to enable ssh access on your headless RPI

  5. Create a storage file and enable usb mass storage

(Instructions taken from https://magpi.raspberrypi.org/articles/pi-zero-w-smart-usb-flash-drive credit to Russell Barnes)

sudo echo "dtoverlay=dwc2"  >> /boot/config.txt
sudo echo "dwc2" >> /etc/modules
sudo dd bs=1M if=/dev/zero of=/piusb.bin count=128 
sudo mkdosfs /piusb.bin -F 32 -I
sudo mkdir /mnt/usb_share
sudo echo "/piusb.bin /mnt/usb_share vfat users,umask=000 0 2" >> /etc/fstab

sudo reboot

When the slave reboots connect the usb port to your computer and run

sudo modprobe g_mass_storage file=/piusb.bin stall=0 ro=0

Windows should see a volume, be asked to put and MBR and you would need to create a partition using diskmgmt.msc

Once the partition is created, on the slave RPI run sync and the state of the volume will be frozen.

Now you can upload a jpeg file using your computer via ssh and check if the file can be seen by your computer first then if yes check the file is also seen by the frame via USB.

  1. On the MASTER frame you need to create an ssh shared keys

sudo -s

ssh-keygen -f /root/.ssh/id_rsa -q -P ""
ssh-copy-id pi@$YOUR_SLAVE_IP_ADDRESS   ### then you will be prompted for the slave pi user creds

Now try to ssh from the master to the slave, if all the above worked well you should not need to enter a password as ssh key sharing should now be working for you.

  1. Test the push script

On the master frame, create a script /root/sync_frame.sh with the below content
(You will need to change the ip address to match your slave IP and potentially the supported picture mime types in SUPP_EXT)

#!/bin/bash

FOLDER="/root/history/"
SLAVE1_IP='192.168.1.237'
SUPP_EXTS="jpeg"

while $(watch -g -t -n1 ls -rtlh $FOLDER | tail -2 | head -1 | awk '{print $9}' >/dev/null)
        do
        for i in $( ls -rtlh $FOLDER | tail -2 | head -1 | awk '{print $9}' )
                do
                EXT=$(file --mime-type $FOLDER$i | awk -F"/" '{print $5}')
                if [[ "$EXT" == "$SUPP_EXTS" ]] ; then

                        echo -e "Found new picture $FOLDER$i\n"
                        echo -e "Found supported extension $EXT, shipping.\n"

                        ssh pi@$SLAVE1_IP 'rm -f /mnt/usb_share/.'
                        scp $FOLDER$i pi@$SLAVE1_IP:/mnt/usb_share/$i.$EXT
                        ssh pi@$SLAVE1_IP 'sudo /sbin/modprobe -r g_mass_storage && \
                                sync ; \
                                sleep 1 ; \
                                sudo /sbin/modprobe g_mass_storage file=/piusb.bin stall=0 ro=1'

                        else echo -e "Found a new picture, however $EXT is not in our supported extension list, SKIPPING !!!\n"

                fi
        done
done

Now

chmod +x /root/sync_frame.sh

then run the script

bash -x /root/sync_frame.sh

  1. If all works for you then you might want to get the script to start when the master photoframe starts (done it the easy way, would be better to start as a service TODO)

edit the file /etc/rc.local on the line before exit 0 append /root/sync_frame.sh so it looks like

/root/sync_frame.sh
exit 0

  1. Reboot the master frame and after the picture changes on the master frame it should update the slave in couple of seconds.

The sync script is really basic and can be upgraded, however different frames behave differently so I tried to make it a generic as possible with the frames I tested as slaves.

Some frame would keep displaying the picture even if the usb storage is removed which is best, others would display their home screen, other would hang if you dismount/remount too fast. Some frames happily power the RPI Zero while others need the RPI to have its own power supply as they would hang after hours or days.

So the best here is to experiment for yourself and if possible use the same kind of slave frames to keep the tweaking minimal.

That's all from me, Have FUN !