create new tag
view all tags

The Raspberry Pi


The Raspberry Pi is a small computer powerful enough to run a full blown operating system like Linux. The 3rd version of this machine features

  • a quad core 1.2 GHz Broadcom BCM2837 64 bit ARM CPU

  • 1 Gbytes of RAM

  • Ethernet and wireless networks

  • 4 USB 2 ports

  • full size HDMI

  • a camera port

  • micro SD connector

  • a 40 pin extended GPIO connector with GPIO input output pins, SPI and I2C bus interface

This is how it looks like:

The Raspberry Pi 3 board

Raspberry Pi documentation

The Raspberry Pi has a huge user community making sure that documentation is always up to date. Raspbian, an ARM Debian version of Linux is the standard OS which is regularly upgraded.

Normally the OS is installed on a micro SD card and boot from there. Version 3 of the board however also allows to boot from a USB stick, which has easier access.

Bringing up Raspbian

The operating system can be downloaded here which gives you a zip file. Once uncompressed (use the unzip command to do this and be patient because it can take several minutes to unpack) you get an image file (2017-07-05-raspbian-jessie.img at the time of writing) which you can copy to the micro SD card or a memory stick using dd. To enable USB or network boot mode you must prepare the machine however as described here .

Once you have prepared the card, downloaded and unpacked the OS you can copy it to the SD card or USB stick. Make sure to find out which device corresponds to your SD card (/dev/mmcblk0p1 ?) or you USB stick (/dev/sdX where X is your device letter).

Make damned sure you know the device letter without doubt because otherwise you may overwrite your hard disk and your PC will not boot any more!)

One way to find out the device letter is this: Before inserting the SD card into yout PC SD card slot, type ls /dev/sd*, which will give you the names of all hard disk partitions installed on your system. Then insert the SD card into the reader and redo the same command. The disk you have added is the one you want to use.

When you put the SD card into the SD card reader, the system will automatically mount it because at the factory a vfat file system was put onto it. Before we can copy the Raspberry Pi image we must first unmount this partition:

umount /dev/sdX1

Copy the OS image to the SD card or USB stick with:

sudo dd bs=4M if=2017-07-05-raspbian-jessie.img of=/dev/sdX status=progress conv=fsync

This may take a while. Eject the SD card (right click on its icon in the task bar and select eject, then re-insert it and make sure you can see 2 partitions. The first one is named "boot" and you may want to rename the second one to "root" with the command:

sudo tune2fs -L root /dev/sdX2 (replace the X with your disk letter again).

Once done, eject the SD card again and install the device in your Raspberry Pi and boot.

You can also unpack the Raspbian file system by loop mounting it onto your Linux system.

Before doing this, create 2 directories: /media/loop1 and /media/loop2.

Since there are 2 partitions in the image in addition to the boot loader, you must specify the offset of each file system (boot and root) when mounting them. You can find out these offsets with fdisk -l imageName.img.

Multiplying the start sector offset by 512 (size of a sector) gives you the offset needed for the mount command. In case of the boot partition this is 8192*512 = 4194304. The W95 FAT32 file system is the boot partition and the Linux file system is the root partition.


You can then copy the contents of /media/loop into a directory you call boot and do the same thing for the root file system

For copying you must first cd to /media/loop1, then I use:

tar cvpf - * | (cd /opt/ucc/micros/raspberry/raspbian-stretch-2017-09-07/b(r)oot; tar xvf -) This rather complex looking tar command does the actual copy, keeping the file permissions and ownership intact. In fact it created a tar archive file which is again un-tared in the destination directory /opt/ucc/micros/raspberry/raspbian-stretch-2017-09-07/boot in case of the boot file system.

(use either boot or root).

Setting up the system

Once Raspbian is up and running you will have a user pi with password raspberry to log in. This user has the UID 1000 and GID 1000. Unfortunately on my PC Ubuntu system these are the UID and GID of user uli, my main user name. This causes trouble when we want to easily log in through ssh or copy files with scp. I therefore modified the UID and GID for user pi to be 1001 to free 1000 for user uli.

I created a new user uli, added him to the sudoers list (usermod -a -G sudo uli) such that I can easily become super user. Then I modified the UID and GID of pi and uli as described here. Make sure that the user and group ownership of the home directories are also correct (chmod -R uli:uli /home/uli).

Once all this is correctly set up you will have to run raspi-config as super user and enable

  • ssh

  • vnc

  • gpio, spi, i2c

Go through all the options in raspi-config, make sure you understand what they mean and set them up to your liking. One important thing to do is setting up the correct keyboard layout. This must be done in the localization options in raspi-config. If you do it in Preferences->Mouse and Keyboard Settings, then it will only be active when logged in but not on the logging screen. This may cause you problems when trying to log in because your password will not be recognized due to the wrong keyboard layout.

After that we will have to sync the apt packages to the repository which we do with sudo apt update and upgrade all packages to the latest version: sudo apt upgrade.

Now you may install additional packages like emacs or other commands you may be missing using apt install package name.

When running emacs I get this nasty warning:


You can get rid of it by defining the environment variable NO_AT_BRIDGE: export NO_AT_BRIDGE=1 which I do in the system-wide bash initialization script /etc/bash.bashrc. All subsequent bash shells will have this environment variable set up and the problem will be gone.

We had some difficulties to access the Pis on the network because the IP addresses kept changing. Finally we opted for fixed IP adresses which can be configured in /etc/dhcpcd.conf as shown below:


The hardware access libraries wiringPi and pigpio we will install from source code using git (see below).

Installing wiringPi

First I create a new group named ucc and a new user uccstaff which I make a member of this new group:

addgroup ucc

adduser uccstaff

usermod -a -G ucc uccstaff

Then reboot the machine to activate these changes.

Create the directory /opt/ucc/src belonging to uccstaff and group ucc. This is where the source files of wiringPi and pigpio will be stored. Then we download the wiringPi source code into this directory with git clone git://git.drogon.net/wiringPi. I modified the Makefile in gpio to install everything in /usr instead of /usr/local (comment PREFIX? with a "#" in front of it.

After that compile you may want to compile also the examples. do make really-all in the examples sub-directory of wiringPi.

The remote desktop

When you enable VNC in raspi-config the tightvncserver will be installed and run on your system. I use the Remmina Remote Desktop Client which seems to be the standard remote desktop client on PC Ubuntu. However, when running it on the Raspberry Pi server I get an authorization failure which I can get rid of by modifying the authorization method on tightvcnserver from Unix authorization to VNC authorization. You define a password, which you also used on the client (PC) side.

When running VNC without a physical screen attached to the Raspberry Pi you may experience that the desktop window on the PC become very small. This can be fixed by edition the /boot/config.txt on Raspbian. You must set the bramebuffer width and height as shown below.


-- Uli Raich - 2017-08-14


Topic attachments
I Attachment History Action Size Date Who Comment
PNGpng dhcpcdConf.png r1 manage 17.6 K 2017-10-14 - 13:16 UnknownUser  
PNGpng piEmacsError.png r1 manage 11.7 K 2017-09-27 - 14:12 UnknownUser  
PNGpng raspberryFileSystem.png r1 manage 117.8 K 2017-09-25 - 12:01 UnknownUser  
PNGpng screenConfig.png r1 manage 10.9 K 2017-10-14 - 13:16 UnknownUser  
Edit | Attach | Watch | Print version | History: r9 < r8 < r7 < r6 < r5 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r9 - 2017-10-14 - uli
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2022 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback