Setting up the Raspberry (Jessie)

July 2016 update – Following extensive feedback from other clubs building boards, I have come to the conclusion that the old instructions put together when I first set up my board 3 years ago no longer work properly, because of changes in the operating system.

Thanks to James at Potton Down CC and Pete at Lintz CC for their ongoing patients while we worked on debugging various problems.  These instructions have been fully tested using Raspbian Jessie – May 2016 edition.  If you still need the old instructions, they are available from here.

Overview

These are very brief instructions on how to set up the Raspberry PI, including:

  • Install Apache and PHP to host the web user interface
  • Install web pages and script to enable the interface between the raspberry and the arduino
  • Set up passwords for some of the admin functions
  • Setting a static IP address
  • Configure BIND, to provide DNS services (optional).

Completing basic setup of the Raspberry

Before you start, you need to install Raspbian Jessie (May 2016 version) on to a memory card.  There are instructions on how to do this on the Raspberry Pi website here.

As an absolute minimum, you will need to connect the Raspberry to a network router via a cable, and give it access to the Internet.  Once you have got the raspberry on the network, you should lookup the IP address by opening a terminal and running the following command

sudo ifconfig

jessie1

Make a note of the IP address, we will need this for later.

Now we need to run the raspberry pi setup script in order to disable serial, enable SSH, and change the host name.  To do this, from the same terminal screen type:

sudo raspi-config

jessie2

Choose Advanced options and

Disable serial console
Enable SSH
Update the hostname (I called mine scoreboard)

Now reboot the pi by typing

sudo reboot

Install Apache and PHP

In order to install the pre-requisite software type the following commands in to a terminal, and press ‘y’ when asked any questions. Your Raspberry Pi must be connected to the Internet for this stage to work correctly.

sudo apt-get update
sudo apt-get install apache2 php5 libapache2-mod-php5

Once the pre-requisite software has been installed, you need to make a small configuration change to Apache.  To do this edit the /etc/apache2/apache2.conf file, by typing the following command:

sudo nano /etc/apache2/apache2.conf

Find the section relating to <Directory /var/www/>, which is towards the bottom of the file.  Change the AllowOverride None entry to read AllowOverride All

jessie3

Save the file by pressing CTRL + O, and then exit with CTRL + X.

Now setup Apache to start on boot, and restart the service so that it picks up the new setting by typing the following in to a terminal:

sudo systemctl enable apache2
sudo service apache2 restart

jessie4

Now we need to configure permissions to allow apache to send commands to the Arduino.  To do this type the following command in to a terminal:

sudo usermod -a -G dialout www-data

jessie5

Setting up the scoreboard user interface

Download the software2016R2.zip on to your laptop computer, and then using WinSCP to copy it on to your Raspberry and put it in the /home/pi directory.  You will need to use the IP address you looked up earlier to connect to the Raspberry.

jessie6

jessie7

Now that the software2016R2.zip file has been copied on to the Raspberry, you need to unzip the files with the following commands:

 cd /home/pi
 unzip software2016R2.zip

Now copy the files in to the correct location and set the file permissions with the following commands:

cd /home/pi/software/software/web/var/www/
sudo cp -r * /var/www/html
sudo rm /var/www/html/index.html
sudo chown -R www-data: /var/www/html/

The /var/www/html directory listing should look something like this

jessie8

Now we need to set the passwords for the reboot and shutdown pages with the following commands:

cd /var/www/html/reboot
sudo htpasswd .reboot.password reboot
cd /var/www/html/shutdown
sudo htpasswd .shutdown.password shutdown

jessie9

Setting up the scoreboard scripts

Now that the UI is installed you need to setup the scripts to make the Raspberry work with the Arduino correctly.

Type the following in to a terminal:

sudo mkdir /usr/local/bin/scoreboard
sudo cp -r /home/pi/software/software/web/usr/local/bin/scoreboard/* /usr/local/bin/scoreboard/
sudo chown -R root: /usr/local/bin/scoreboard/
sudo chmod 755 /usr/local/bin/scoreboard/*.sh

Now we need to edit crontab to make these scripts start at boot (or run regularly) . To do this type the following command in to a terminal (and choose nano if asked which editor to use)

sudo crontab -u root -e

Added the following lines to the end of the file, before saving and closing (CTRL + O and CTRL + X).

 * * * * * /usr/local/bin/scoreboard/checkReboot.sh
 * * * * * /usr/local/bin/scoreboard/checkShutdown.sh
 @reboot /usr/local/bin/scoreboard/loadSerialSettings.sh
 @reboot /usr/local/bin/scoreboard/cleanup.sh

jessie10

Finally reboot the raspberry, as we have completed the setup!   Make sure that the Arduino is plugged in to the Raspberry via the USB port before rebooting.

Some basic testing

Once the Raspberry has rebooted, we can test the software is working correctly.  First, open a terminal and run (this will sit in an endless loop):

sudo /usr/local/bin/scoreboard/readFromSerial.sh

Leave that terminal open, and now open a second terminal and run:

sudo tail -f /var/log/scoreboard.log

Now using a browser, open the scoreboard web interface from your laptop.  I recommend using Chrome for this.   Type in the name of the IP address of the Raspberry in to the address bar and the interface should load.  Change the score.

jessie11

In the second terminal you opened you should see something like:

jessie12

If this is displayed, and the interface has loaded correctly then congratulations!  You have set up the Raspberry correctly!

Optional – Setting a static IP address

When you plug the Raspberry in to the wireless router in the scoreboard, it is likely that you will need to set a static IP address.  To do this edit the /etc/dhcpcd.conf file and add the following lines.  Make sure you set an appropriate IP address for your router:

 #added by Ian N
 interface eth0
 static ip_address=192.168.1.50/24
 static routers=192.168.1.1
 static domain_name_servers=192.168.1.1

jessie13

Save the file and exit (CTRL + O and CTRL +X if using nano).  Reboot the PI, and the new IP address will be applied and the Raspberry is ready to plug in to the wireless router used by the scoreboard (but will no longer have internet access)

Optional – Setting up the Bradford upon Avon interface

Chris at Bradford upon Avon CC completely re-wrote the web interface, and I am sure you will agree he has done a great job and made it much easier to use.  However, before you install the interface please make sure that you have setup and tested the standard Westbury on Severn interface fully  (with a set of LEDs), before you attempt an upgrade.  This makes troubleshooting so much easier.

5

You can see details of the Bradford upon Avon build here, and see an online demo of the interface here.

To install the interface, we should start by making a backup copy of the original Westbury on Severn interface and then deleting it from the apache directory.  To do this open a terminal on the raspberry and run the following commands (with significant care!)

sudo cp -r /var/www/html /var/www/html.old
sudo rm -rf /var/www/html/*

Now download the scoreboard-web-interfacev4.zip updated UI, and upload it to the /home/pi/bradford directory on the Raspberry using WinSCP (you will have to create the Bradford directory using WinSCP).

jessie6

jessie14

Now open a terminal on the Raspberry, and unzip the files with the following command

cd /home/pi/bradford
unzip scoreboard-web-interfacev4.zip

Now copy the interface in to the apache directory and set the correct permissions with the following commands:

cd /home/pi/bradford/
sudo cp -r * /var/www/html/
sudo chown -R www-data: /var/www/html/
sudo chmod 666 /var/www/html/save.txt

jessie15

Now edit the admin password that is required to shutdown or reboot the board by editing the /var/www/html/veriifyadmin.php file.  Update the if($_GET[‘pass’]==”admin”) line to change the password from admin to something secret.

Now we can test the software is working correctly.  First, open a terminal and run (this will sit in an endless loop):

sudo /usr/local/bin/scoreboard/readFromSerial.sh

Leave that terminal open, and now open a second terminal and run:

sudo tail -f /var/log/scoreboard.log

Now using a browser, open the scoreboard web interface from your laptop.  I recommend using Chrome for this.   Type in the name of the IP address of the Raspberry in to the address bar and the interface should load.  Change the score.

jessie16

In the second terminal you opened you should see something like:

jessie12

If this is displayed, and the interface has loaded correctly. And the task is complete!