Automation/RaspberryPi

From Medien Wiki

The Raspberry Pi is an inexpensive Linux Computer which you can for example use to play back videos (up to Fill-HD). This page shows you how to set it up:

Making the RapberryPi run a video at startup

Install The Raspbian image (NOOBS is okay for the beginning, but it wastes a bit space on the SDcard for the recovery image which we don't need. Copy the raspbian on the card.

Once that is done, connect to the Internet (Ethernet + DHCP) and bring the OS up to date:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo apt-get install raspberrypi-net-mods

Test video playback: source

omxplayer /opt/vc/src/hello_pi/hello_video/test.h264

add option -r to change display frame rate and resolution to the one that the movie file has:

omxplayer -r /opt/vc/src/hello_pi/hello_video/test.h264

make a file startup_script.sh (shell script) with the following content:

clear
echo "Startup script running"
echo "some useful information here"
sleep 2
omxplayer -r movie.mp4 --loop

you will have to make this executable with

sudo chmod 775 startup_script.sh

and you can test if it works by running it

./startup_script.sh

Make it log in automatically

You don't want a password prompt when the raspberry boots source

Edit the inittab file.

sudo nano /etc/inittab

Disable the getty program. Find this line and comment it our by adding a # at the beginning of the line

#1:2345:respawn:/sbin/getty 115200 tty1

Add login program to inittab. Add the following line just below the commented line

1:2345:respawn:/bin/login -f pi tty1 </dev/tty1 >/dev/tty1 2>&1

This will run the login program with pi user and without any authentication

Save and Exit.

Make it start the script automatically:

sudo nano .bashrc

and right at the end put:

if [ $(tty) == /dev/tty1 ]; then
  ./startup_script.sh
fi

(that last 'if' makes sure the script is not starting in an x session)

Synchronizing multiple RaspberryPi

maybe you want to have the different Pi different host names, so you don't get confused

sudo raspi-config


install pexpect:

sudo apt-get install python-pexpect

install python bindings for DBUS https://github.com/LEW21/pydbus

sudo apt-get install python3-setuptools
sudo wget https://github.com/LEW21/pydbus/archive/master.zip
sudo unzip master.zip
rm master.zip
cd pydbus-master/
sudo chmod 777 setup.py
sudo ./setup.py build
sudo ./setup.py install


sudo apt-get remove omxplayer
sudo rm -rf /usr/bin/omxplayer /usr/bin/omxplayer.bin /usr/lib/omxplayer
sudo wget -O- http://yokto.net/0/omxplayer/omxplayer-3176db4.tar.bz2 | sudo tar -C / -xjvf -
sudo ln -sf /lib/arm-linux-gnueabihf/libpcre.so.3 /lib/arm-linux-gnueabihf/libpcre.so.1
sudo wget -O /usr/bin/omxplayer-sync https://github.com/turingmachine/omxplayer-sync/raw/master/omxplayer-sync
sudo chmod 0755 /usr/bin/omxplayer-sync
sudo wget https://github.com/turingmachine/omxplayer-sync/raw/master/synctest.mp4


Make a local network, connect them with Ethernet cable (+Hub if more then two) and configure static IPs source

sudo nano /etc/network/interfaces

start on master:

omxplayer-sync -mubv synctest.mp4

start on slave:

omxplayer-sync -lubv synctest.mp4

-b flag to make screen background black

(remove v for verbose mode later once everything works)

Notes

other resources

Use multiple RasberryPis to make a video wall (needs one extra server-Pi, plus one Pi per client) Piwall

Backup and copy

let's say /dev/mmcblk0 is your card reader

make a backup of SDCard:

sudo dd if="/dev/mmcblk0" of="Pi.bin"

put backup on card:

sudo dd bs=4M if=Pi.bin of=/dev/mmcblk0

(both these commands take a long time and the terminal seems like frozen, there is no progress feedback)

Power

to switch on just plug in the power. Make sure HDMI is connected first and Beamer/Screen is on prior to plugging in the power, otherwise the screen might not be recognized.

reboot:

sudo reboot -h

shutdown:

sudo shutdown -h now

Timing

Set the time

dpkg-reconfigure tzdata

Note that the Raspberry is searching online for the current time when booting. If there is no Internet the time might not be accurate.

=Shut down at specific time

The shutdown command has a timer built in, so when it is called like this

sudo shutdown -h 15:00

the system will shut down at three in the after noon.

sudo shutdown -h +30

will shut the system down in 30 minutes from now.

You can also set a cron job for shutting down on specific days at specific times.

sudo crontab -e

add this line:

45 18 * * * /sbin/shutdown -h now

to shut down 45mins past 6PM

source