The Raspberry Pi and how to bring it to life
Lecture 6
Uli Raich
UCC semester 2017/2018
COPYRIGHT © 2024 by the contributing authors
Slide 1 of 33
There are several versions of Raspberry Pis available on the market:
- Raspberry Pi 1 Model B released in 2012
- There is also a simpler and cheaper model A
- Raspberry 2 with more memory
- Raspberry Pi zero a stripped down version for 5 US$
- Raspberry Pi zero W same as zero but with WiFi and Bluetooth for 10 US$
- Raspberry Pi 3 fully equipped model that we will be using
For more information look up the
Wikipedia page
COPYRIGHT © 2024 by the contributing authors
Slide 2 of 33
COPYRIGHT © 2024 by the contributing authors
Slide 3 of 33
Operating systems on the Pi
From the specs we can see that the Raspberry Pi 3 is a full blown computer.
With its
- 64 bit quad core processor
- 1 Gbyte of RAM
- 32 Gbyte of SD card
it by far outperforms the 80 kUS$ mini computer I had used to control
a full particle accelerator and it is also much more powerful
than the computer system that allowed the moon landing!
This allows a great deal of flexibility when it comes to
operating systems to be installed on the machine
COPYRIGHT © 2024 by the contributing authors
Slide 4 of 33
- Raspbian, a Debian variant of Linux tailored to the Raspberry Pi.
- It contains most of the software packages you also find on Ubuntu
The Desktop is however stripped down to make it more
responsive on a processor that cannot cope with the speed of a PC
This is what we are using!
- Ubuntu Mate is a Ubuntu variant for the Pi
- Windows 10 IOT core, a windows variant. I have never tried this but
Windows gurus may give it a try if they cannot live without Windows on the Pi
- Android: There are several Android versions for the Pi floating
around on the WEB. Your success on these may vary
- Kodi is a multimedia server that will allow you to listen to music,
look at photos or watch films. Connect your Pi to a TV set
(through the HDMI connector) and a stereo and off you go!
If this is not enough for your then search the WEB for more.
COPYRIGHT © 2024 by the contributing authors
Slide 5 of 33
The CPU has got an ARM processor core with 4 64 bit CPUs
The operating system and the Linux kernel are still 32 bit versions
(After the course you may try to compile and install
a 64 bit kernel yourself. This is a very good exercise to
understand how the OS is built!)
Around the CPU there are plenty of interfaces
To know the details (the interfaces only!) have a look
at the
data sheet explaining them (205 pages!)
COPYRIGHT © 2024 by the contributing authors
Slide 6 of 33
Here are some of the Raspberry Pi peripherals:
- UART
- SPI
- BSC (serial controller)
- DMA controller
- External mass media controller
- PCM / I2S Audio
- Pulse Width Modulation
- Timer
- USB
- I2C
- GPIO
COPYRIGHT © 2024 by the contributing authors
Slide 7 of 33
Raspberry Pi and the real world
You can easily connect
- General Purpose Input Output signals
- These are 3.3 V single pin signals used e.g. to drive a LED,
a relay or any other device needing a digital signal level
- You can program it input or output
- With pull-ups or pull-downs
- To read switch state
- To drive a 3.3V output level (and light a LED)
COPYRIGHT © 2024 by the contributing authors
Slide 8 of 33
Connection to bread board: The cobbler
COPYRIGHT © 2024 by the contributing authors
Slide 9 of 33
I2C is a serial bus often used in computer systems of for
short distance interfacing. Many devices having a
I2C port
are available and we will program a few:
- ADC
- DAC
- Real time clock
- EEPROM
- BPM180 barometric pressure sensor
- We also have a 2-line LCD display needing some 8 signals
(+ power and gnd). A serial to parallel interface (shift register)
with I2C interface eases the connection to the Raspberry Pi
as only 4 serial signal lines are needed: SDA, SCL, Vcc, Gnd
COPYRIGHT © 2024 by the contributing authors
Slide 10 of 33
There are more interfaces which we will not necessarily use during the course.
Students who think that they do not learn enough during this course
are invited to come forward.
We can easily give you more exercises, e.g to make
- The camera
- The touch screen interface
- The audio system
- Or the video system work
COPYRIGHT © 2024 by the contributing authors
Slide 11 of 33
What you need to bring a RPI to life
This is what you will need to bring a Raspberry Pi to life:
- The Raspberry Pi board
- A case (this increases the chances the Pi will survive for more than a week)
- A 5V, 2.5A power supply with micro USB connector
- A USB keyboard and USB mouse
- A screen with HDMI connection of HDMI to VGA adapter
Once the Raspberry Pi is up and running you can replace the screen,
keyboard and mouse with your laptop or other computer
and access the Pi through a remote desktop.
COPYRIGHT © 2024 by the contributing authors
Slide 12 of 33
Go to the Raspberry Pi
download page and download the
Raspbian image. It comes in 2 versions
- NOOBS which contains the system itself + an installer
- Raspbian proper. This version may be slightly more difficult to install
because it does not have the installer, which you would keep on your
SD card even though after its first use you don’t need it any more
This will get you a zip file, normally downloaded to your
$HOME/Downloads directory.
Since at Internet speeds that we experience at UCC this takes more than
1 hour to download we will distribute the zip file to all the PCs
COPYRIGHT © 2024 by the contributing authors
Slide 13 of 33
How to extract the file system on Ubuntu?
Once downloaded we must first unzip the file:
Create a folder /opt/ucc/micros/raspberry and copy the zip file into it
cd /opt/ucc/micros/raspberry
cp ~/Downloads/2017-09-07-raspbian-stretch.zip .
unzip 2017-09-07-raspbian-stretch.zip which will give you
2017-09-07-raspbian-stretch.img
This is the file system image which will be copied to the SD card
bit by bit using the
dd command
COPYRIGHT © 2024 by the contributing authors
Slide 14 of 33
Structure of the image file
Can we know what is inside this image?
We see that there are 2 disk partitions:
- a FAT32 (Windows type) partition. This is the boot partition
- a Linux (ext4) partition which is the root file system
COPYRIGHT © 2024 by the contributing authors
Slide 15 of 33
Looking inside the partitions
This is something only root (the superuser) can do
We loop mount the file system:
Now we can copy the contents to whatever directory we want
This is the boot partition
Then we can do the same thing for the root partition
COPYRIGHT © 2024 by the contributing authors
Slide 16 of 33
Once we mount the second partition the same way we see that it contains:
something we have seen before on our Ubuntu PC
The boot partition we have seen before is mounted on
/boot in this partition
COPYRIGHT © 2024 by the contributing authors
Slide 17 of 33
How to get the OS onto the Raspberry Pi?
Now we have the OS on the PC where it does not help us much!
We must put it onto a media that can be read by the Rpi.
Traditionally this was the micro SD card
but you can also use certain types of USB memory sticks
(Be careful, not all sticks will work! I use a SanDisk cruzer)
COPYRIGHT © 2024 by the contributing authors
Slide 18 of 33
Copying the OS to the SD card
If your PC has an SD card reader then you put the
micro SD card into a normal SD card holder.
Otherwise there are microSD to USB converters
First check which disks you have on you system:
Then you plug in your microSD adapter or your USB adapter
and do the same thing again
You should see 2 additional partitions, in my case probably
/dev/sdc /dev/sdc1 /dev/sdc2
COPYRIGHT © 2024 by the contributing authors
Slide 19 of 33
Now we are ready to copy the operating system to the SD card (or USB stick)
Where X is the disk letter (in our case “c”)
This may well take several minutes (the image is some 1.6 Gbytes!)
To see the progress:
COPYRIGHT © 2024 by the contributing authors
Slide 20 of 33
COPYRIGHT © 2024 by the contributing authors
Slide 21 of 33
Raspbian has a default user named
- pi
- with password raspberry (which must be changed
immediately for security reasons!)
Create your own user and add him to the sudo group:
adduser uli and follow the instructions on the screen
usermod -a -G sudo uli
Then login with this new login name and
upgrade the system to the latest revision of all programs:
sudo apt update
sudo apt upgrade or
sudo apt dist-upgrade
COPYRIGHT © 2024 by the contributing authors
Slide 22 of 33
Once you have come this far you may want to add
additional software packages, emacs being one of them
You will continue adding packages as you use the system
and you will see what is missing.
COPYRIGHT © 2024 by the contributing authors
Slide 23 of 33
We have seen that the system image takes 1.6 Gbytes our SD card
however provides 32 Gbytes. How to use it to its full capacity?
Start raspi-config (which is a program dedicated to the Raspberry
and does not exists und PC Ubuntu)
Go through all the options of the program and see if they make sense to you.
COPYRIGHT © 2024 by the contributing authors
Slide 24 of 33
Accessing the RPI remotely
Of course we can use the interfaces on the Raspberry Pi
to connect a screen, keyboard and mouse and use it in stand-alone mode
but we can also make use of the PC resources and access it remotely
There are several ways to access the RPI remotely:
- Using the VNC server on the Pi you can access it
with a remote desktop from the PC
- The secure shell (ssh) allows you to get a remote terminal in the Pi
- With scp you can copy files back and forth between the Pi and the PC
- With nfs you can mount part of the Pi file system into the
PC file system tree and access the PI SD card as if it was a local PC disk.
COPYRIGHT © 2024 by the contributing authors
Slide 25 of 33
COPYRIGHT © 2024 by the contributing authors
Slide 26 of 33
When running the remote desktop you are working on the Raspberry Pi
with the screen, keyboard and mouse replaced by the devices on the PC.
You have the same functionality as if the screen was connected
to the Pi’s HDMI port and keyboard and mouse were connected
to the USB ports on the Pi.
COPYRIGHT © 2024 by the contributing authors
Slide 27 of 33
nfs the network file system
With nfs you can mount part of the Pi’s file system tree
onto your PC file system.
This allows you access to the Pi’s files as if you were
using a local disk. You cannot run any Rasberry Pi
programs this way however.
It is interesting if you cross-compile Pi programs on your PC,
which will be immediately visible on the Pi.
COPYRIGHT © 2024 by the contributing authors
Slide 28 of 33
In the case of ssh you have a single terminal window
that is connected to a shell on the Pi.
The command is:
ssh
userOnPi@piIPaddress
Where piIPaddress can be the Pi’s IP address of hostname.
If you specify the -X option you can run X-11 based programs
where the X protocol is run over the ssh connection.
COPYRIGHT © 2024 by the contributing authors
Slide 29 of 33
Here you see a screen dump from the PC with a remote terminal
that started an emacs session on the Pi.
COPYRIGHT © 2024 by the contributing authors
Slide 30 of 33
To copy a file from the PC to the Pi this would be the command:
scp myfile.c
uli@rpi-10:exercises/solutions/exercise_2
This will copy the file “myfile.c” into the sub-directory
exercises/solutions/exercise_2 on my home directory on the Pi.
Of course user uli must exist on raspberry10.
Instead of specifying the machine name: rpi-10
you can also give its IP address.
COPYRIGHT © 2024 by the contributing authors
Slide 31 of 33
Compiling C programs for the Raspberry Pi
Just like Linux on the PC, Linux on the Raspberry Pi uses the GNU C compiler gcc.
The front end:
- Lexical Analyzer
- and the parser for the grammar
are the same.0
However, the code generator is different since now
we compile for the ARM processor and not the
Intel processor used on the PC
COPYRIGHT © 2024 by the contributing authors
Slide 32 of 33
Cross-Compilation for the Pi
As explained in a previous lecture we can also compile
C programs for the Raspberry Pi on the
PC Linux system using a cross-compiler.
The cross compiler we will use is named
arm-linux-gnueabihf-gcc
and it is part of the
tools package for the Pi.
It exists also as an Ubuntu package to be installed with apt.
COPYRIGHT © 2024 by the contributing authors
Slide 33 of 33
--
Uli Raich - 2017-09-13
Comments
This topic: Embedded_Systems
> WebHome >
LectureSlides > Lecture6:BringingTheRaspberryPiToLife
Topic revision: r6 - 2017-10-16 - uli
Copyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback