There is a lot of interest in the amazing Raspberry Pi 3 computer here at Cranfield University. Once you have the basics for the Raspberry Pi in place, there are a few tips and tricks you can follow to make the Pi work better for you, explained below. The assumption here is that you already have the Pi connected up to a monitor, and have a keyboard and mouse plugged in and are running Jessie Raspian (if not, see our earlier Pi tutorials). the topics covered here are:
Setting a system password | Getting WiFi running | Accessing the Pi from another computer | Moving files to and from the Pi from another computer – scp | Installing and updating software on the Pi | Setting aliases | Learning Python
Setting a system password
The default account on the Pi is in fact username ‘pi’, and there is no password for the account by default. It is good practice to set a password, particularly once you activate WiFi for the Pi. To do this, Select Menu > Preferences > Raspberry Pi Configuration > System. Select the password option and enter in a secure password.
While you are at this dialogue box, you can explore the other options there – for example, under ‘Localisation’ you can set the Pi’s timezone appropriately.
Getting WiFi running
WiFi on the Pi is very straight forward if you have a home router running WPA security. At the graphical interface, in the op right corner of the screen is the WiFi icon. Right mouse click the WiFi icon and select the first ‘WiFi Networks Settings’ option. In the Network Settings dialogue, in the ‘configure’ drop-down, select ‘SSID’ and search for your router, select it and press OK. If there is a WiFi password required, select the WiFi icon again, locate the connection you just made in the list and double click – a dialogue appears for you to enter in the password. Once done, hopefully the connection is made and you will be online.
To get the Pi to connect wirelessly to the campus WiFi network ‘EduRoam’ is rather more tricky – see https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=86253
Using the Jessie graphical user interface of the Pi, you should be able to follow the same procedure to get the Pi online with Eduroam. If you intend to do this however, you must ensure that users all have passwords set, and that the hostname is something other than ‘pi’!
Accessing the Pi from another computer
To start with you have to connect a monitor and keyboard/mouse up to the pi to connect to it. However, ultimately you may want to have it running on its own, and so then be able to connect to it from a different computer – on the command line, or graphically.
Assuming the Pi is using WiFi and is online, find out what its IP address is. To do this, you can either consult the WiFi router’s web console to look for its connected clients, or you can type:
In a home WiFi situation, the IP address will likely be something like ‘192.168.1.nn’ (e.g. 192.168.1.11).
From your other computer (e.g. a PC or Mac), you can now run an ‘
ssh‘ (secure shell) client. To do this, on the PC you might use the excellent freeware tool ‘putty’; on a Mac you can fire up the terminal and at the prompt enter ‘
ssh ‘. Make the connection by incorporating the pi user name (which by default is ‘pi’) into the IP address, thus in a mac terminal window for the user name ‘pi’, you would type:
Sometimes accessing via the command line is just not enough, and you may want to run an app with a graphical interface from another computer. If you use the secure shell (
ssh) to log in to the Pi, you may be able to carry the ‘X-windows’ session over to the computer using the ‘
-X’ parameter, thus:
ssh –X email@example.com
On a Mac running Sierra, you may have to run with a ‘
-Y’ instead, (assuming you have Quartz installed):
ssh –Y firstname.lastname@example.org
On Windows computers, you can install and use Xming for the X-windows, and then use putty as noted above for ssh sessions. Putty has a dialogue tick box option to carry X11 over to the local session.
To test this works, install the standard set of X11 apps, then run say xclock, thus:
sudo apt-get install x11-apps
All the above can be a bit fiddly – and a much easier method is to use a VNC (Virtual Network Computing) server. In former times to do this you would install a software package called ‘tightvncserver’ – and there are lots of instructions out on the web to do this – and you can still do this if you wish. However, as from Sept 2016, the Raspberry Pi 3 now includes a VNC server by default, from RealVNC – (see https://www.realvnc.com/docs/raspberry-pi.html). Although installed it is not activated by default. To activate it, select Menu > Preferences > Raspberry Pi Configuration > Interfaces. Ensure the VNC tick box is Enabled and then reboot the Pi. From now on, VNC Server will start automatically whenever your Pi is powered on.
Now, on the computer you want to connect to the Pi, you will also need to install the RealVNC viewer. Visit ‘https://www.realvnc.com/download/viewer/‘, download and install the appropriate viewer. Note you will need to know and enter the IP address of the Pi, as well as your account and password.
Moving files to and from the Pi from another computer – scp
Very often you will want to copy files to and from the Pi – here’s how:
If you have the ssh tools running as above, you can just as easily use the ‘secure copy’ command ‘scp’ to move files to and from the Pi from your controlling computer, as described at https://www.raspberrypi.org/documentation/remote-access/ssh/scp.md.
Copying a file from your computer TO the Pi
scp myfile.txt email@example.com:
or to copy the file to a specific folder:
scp myfile.txt firstname.lastname@example.org:myfolder/
this copies the file to the /home/pi/myfolder/ directory on your Raspberry Pi
Copying a file from your Pi TO the computer
scp email@example.com:myfile.txt .
Installing and updating software on the Pi
You will need to keep the software installed up to date on the Pi. Being open source, it seems that there are constantly updates that need installing – so this is a procedure that should be run through on a regular basis. The tool needed to do this is called ‘apt’.
Open a terminal and enter (‘
apt-get’ is all one word, with no spaces)
sudo apt-get update
This may take a few moments – don’t interrupt until it is finished.
This command line tool is very powerful and can be used to install software as well as keep it updated. For example, to install the package ‘curl’, you type:
sudo apt-get install curl
ps. by the way, curl is a useful command-line tool to transfer data from or to a server, using one of the supported protocols (DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET and TFTP).
If you prefer a software package manager tool with a graphical interface, you can try ‘
Using the Pi, you quickly realise that the command line, using the ‘terminal’, offers you powerful and efficient command tools for configuring and running the computer. Did you know you can set up shortcuts to help make the use of these commands even more efficient. An example we shall use here is to set an alias of ‘
ll’ to run the full command ‘
ls –al’ – a little shortcut that speeds up making full file listings on the screen – so that then, every time you type ‘
ll’ the command ‘
ls –al’ gets run.
Each time you start a terminal session, a configuration file in your home folder named ‘.bashrc’ is read – and shortcuts can be placed into this file. If you have a look in this file (it is a plain text file) you can actually see that there is a line in it making a call to incorporate any aliases defined in a companion file called ‘.bashrc_aliases’. Note this latter file doesn’t exist by default, so enter the following:
This starts up the text editor ‘nano’ (any text editor would do the job as well!) and creates the file – now enter a new line in it:
alias ll=’ls =al’
Save the file out and exit (in nano this is Ctrl+O, Ctrl+X)
Now close the terminal window (type ‘exit’). Next time you run terminal session, type ‘ll’ to see the file listing – try and see.
Be sure to visit https://www.raspberrypi.org/ to learn more about these amazing machines.
The Pi offers a fantastic means to learn programming – using languages such as Python. There are so many Python tutorials out there that we don’t write our own here. However, here are a few guidelines to get you up and running on the excellent quick Python tutorial from Magnus Lie Hetland. This is a good starting point for anyone who has done a spot of coding before as it is short, sweet and to the point!
The tutorial is online here
Firstly you need a decent editor (did you know there were so many!). Sadly, our favourite editor PyCharm is not yet posted to the Pi.
At the command line you can use ‘nano’:
Better still use a graphical editor – assuming it is installed, use say ‘Leafpad’
(the ‘&’ symbol means run editor as a background process):
leafpad myfile.py &
Best of all, use the Idle3 editor on the Pi:
idle3 myfile.py &
Secondly, run the code with the python command as below, (or in Idle – just press ‘F5’ to run the source code).
Then you can follow Magnus’ examples through! For example, copy and run this code:
# Exercise 2
# Part 1:
print ("Part 1\nThis program continually reads in numbers\nand adds them together until the sum reaches 100:")
total = 0
goes = 0
while total < 100:
# Get the user's choice:
number = int(input("enter a number > "))
total += number
goes += 1
print ("The sum is now", total, "and it took you", goes, "turns.")
# Part 2:
print ("\nPart 2\nThis program receives a number of values\nand prints the sum")
total = 0
number = int(input("enter the number of values to enter > "))
for counter in range(0, number):
# Get the user's choice:
number = int(input("enter a number > "))
total += number
print ("The total was", total)