Raspberry Pi
From Wikipedia:
- "The Raspberry Pi is a series of credit card-sized single-board computers developed in the UK by the Raspberry Pi Foundation with the intention of promoting the teaching of basic computer science in schools."
The original models, released in 2012, are based on the Broadcom SoC BCM2835 (ARM11 architecture). The Raspberry Pi 2, released in 2015, is shipped with a BCM2836 SoC (quad-core ARM Cortex-A7 architecture).
Contents
- 1 Article Preface
- 2 System Architecture
- 3 Installing Arch Linux ARM
- 4 Network
- 5 Audio
- 6 Video
- 7 Onboard hardware sensors
- 8 Overclocking/underclocking
- 9 Tips for maximizing SD card performance
- 10 Serial console
- 11 Raspberry Pi camera module
- 12 Hardware random number generator
- 13 GPIO
- 14 I2C
- 15 QEMU chroot
- 16 See also
Article Preface
This article is not meant to be an exhaustive setup guide and assumes that the reader has setup an Arch system before. Arch newbies are encouraged to read the Beginners' guide if unsure how to perform standard tasks such as creating users, managing the system, etc.
System Architecture
The Raspberry Pi is an ARM-based device and therefore needs binaries compiled for this architecture. These binaries are provided by the Arch Linux ARM project which ports Arch Linux to ARM-based devices. They also have a separate community and forum on their website, while original forum does not support ARM specific issues. With the introduction of the Raspberry Pi 2 the packages needed now depend on which architecture the devices has:
- ARMv6 (BCM2835): Raspberry Pi Model A, A+, B, B+
- ARMv7 (BCM2836): Raspberry Pi 2 (based on Model B+)
Installing Arch Linux ARM
See the Arch Linux ARM Pi documentation or Arch Linux ARM Pi2 documentation.
Network
The fresh install comes preconfigured to use the onboard NIC in dhcp mode via systemd-networkd; as long as a cable is connected, almost every router will assign an IP automatically.
To access an initially prepared SD card installation through Secure Shell, the most convenient method is to connect the Raspberry Pi via Ethernet cable and find its assigned IP address through your router configuration. Then direct access via ssh as the root user (password: root) will grant one access. It is highly recommended to change the password and optionally set up SSH keys in the first place.
Configure WLAN without Ethernet
Users needing to establish a wireless internet connection, must download some additional packages and save them to the SD card. WPA supplicant is a recommended wireless daemon.
Consult the wireless section of the Beginner's Guide for additional instruction.
Audio
Install the alsa-utils, alsa-firmware, alsa-lib and alsa-plugins packages.
Optionally adjust the default volume using alsamixer
and ensure that the sole source "PCM" is not muted (denoted by MM
if muted, press M
to unmute).
Select an audio source for output:
$ amixer cset numid=3 x
Where x
corresponds to:
- 0 for Auto
- 1 for Analog out
- 3 for HDMI
Caveats for HDMI audio
Some applications require a setting in /boot/config.txt
to force audio over HDMI:
hdmi_drive=2
Video
HDMI / analog TV-Out
To turn the HDMI or analog TV-Out on or off, have a look at
/opt/vc/bin/tvservice
Use the -s parameter to check the status; the -o parameter to turn the display off and -p parameter to power on HDMI with preferred settings.
Adjustments are likely required to correct proper overscan/underscan and are easily achieved in boot/config.txt
in which many tweaks are set. To fix, simply uncomment the corresponding lines and setup per the commented instructions:
# uncomment the following to adjust overscan. Use positive numbers if console # goes off screen, and negative if there is too much border #overscan_left=16 overscan_right=8 overscan_top=-16 overscan_bottom=-16
Users wishing to use the analog video out should consult this config file which contains options for non-NTSC outputs.
A reboot is needed for new settings to take effect.
X.org driver
The X.org driver for Raspberry Pi can be installed with the xf86-video-fbdev package.
Onboard hardware sensors
Temperature
Temperatures sensors can be queried with utils in the raspberrypi-firmware-tools package. The RPi offers a sensor on the BCM2835 SoC (CPU/GPU):
$ /opt/vc/bin/vcgencmd measure_temp
temp=49.8'C
Alternatively, simply read from the file system:
$ cat /sys/class/thermal/thermal_zone0/temp
49768
For human readable output:
$ awk '{printf "%3.1f°C\n", $1/1000}' /sys/class/thermal/thermal_zone0/temp
54.1°C
Voltage
Four different voltages can be monitored via /opt/vc/bin/vcgencmd
as well:
$ /opt/vc/bin/vcgencmd measure_volts <id>
Where <id>
is:
- core for core voltage
- sdram_c for sdram Core voltage
- sdram_i for sdram I/O voltage
- sdram_p for sdram PHY voltage
Lightweight Monitoring Suite
monitorixAUR has specific support for the RPi since v3.2.0. Screenshots available here.
Overclocking/underclocking
The RPi can be overclocked by editing /boot/config.txt
, for example:
arm_freq=800 arm_freq_min=100 core_freq=300 core_freq_min=75 sdram_freq=400 over_voltage=0
The optional *_min
lines define the minimum frequency to be used for the given component. When the system is not under load, the frequencies will drop down to the minimum value. Consult the Overclocking article on elinux for additional options and examples.
A reboot is needed for new settings to take effect.
The overclocked setting for CPU clock applies only when the governor throttles up the CPU, i.e. under load. To query the current frequency of the CPU:
$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
See CPU frequency scaling for details on scaling governors.
Tips for maximizing SD card performance
See Maximizing performance for the general performance improvements.
Enable fsck on boot
Follow fsck#Boot time checking. Remember that kernel parameters are specified in /boot/cmdline.txt
.
Serial console
Edit the default /boot/cmdline.txt
, change loglevel
to 5
to see boot messages:
loglevel=5
Change speed from 115200 to 38400:
console=ttyAMA0,38400 kgdboc=ttyAMA0,38400
Start getty service
# systemctl start getty@ttyAMA0
Enable on boot
# systemctl enable getty@ttyAMA0.service
Creating the proper service link:
# ln -s /usr/lib/systemd/system/serial-getty@.service /etc/systemd/system/getty.target.wants/serial-getty@ttyAMA0.service
Then connect :)
# screen /dev/ttyUSB0 38400
Raspberry Pi camera module
The commands for the camera module are included as part of the raspberrypi-firmware-tools package - which is installed by default.
$ /opt/vc/bin/raspistill $ /opt/vc/bin/raspivid
Append to /boot/config.txt
:
gpu_mem=128 start_file=start_x.elf fixup_file=fixup_x.dat
Optionally
disable_camera_led=1
The following is a common error:
mmal: mmal_vc_component_enable: failed to enable component: ENOSPC mmal: camera component couldn't be enabled mmal: main: Failed to create camera component mmal: Failed to run camera app. Please check for firmware updates
which can be corrected by setting these values in /boot/config.txt
:
cma_lwm= cma_hwm= cma_offline_start=
Another common error:
mmal: mmal_vc_component_create: failed to create component 'vc.ril.camera' (1:ENOMEM) mmal: mmal_component_create_core: could not create component 'vc.ril.camera' (1) mmal: Failed to create camera component mmal: main: Failed to create camera component mmal: Only 64M of gpu_mem is configured. Try running "sudo raspi-config" and ensure that "memory_split" has a value of 128 or greater
can be corrected by adding the following line into the /etc/modprobe.d/blacklist.conf
:
blacklist i2c_bcm2708
In order to use standard applications (those that look for /dev/video0
) the V4L2 driver must be loaded. This can be done automatically at boot by creating an autoload file such as the following.
/etc/modules-load.d/rpi-camera.conf
bcm2835-v4l2
Hardware random number generator
Arch Linux ARM for the Raspberry Pi has the bcm2708-rng
module set to load at boot (see this), but install the rng-tools and tell the Hardware RNG Entropy Gatherer Daemon (rngd) where to find the hardware random number generator.
This can be done by editing /etc/conf.d/rngd
:
RNGD_OPTS="-o /dev/random -r /dev/hwrng"
and restarting the rngd daemon.
Once completed, this change ensures that data from the hardware random number generator is fed into the kernel's entropy pool at /dev/random
.
GPIO
SPI
To enable the /dev/spidev*
devices, uncomment the following line:
/boot/config.txt
device_tree_param=spi=on
Python
To be able to use the GPIO pins from Python, use the RPi.GPIO library. Install either python-raspberry-gpioAUR or python2-raspberry-gpioAUR from the AUR.
I2C
Install i2c-tools and lm_sensors packages.
Configure the bootloader to enable the i2c hardware by appending /boot/config.txt
:
dtparam=i2c_arm=on
Configure the i2c-dev
module to be loaded at boot:
/etc/modules-load.d/raspberrypi.conf
i2c-dev
Reboot the Raspberry Pi and issue the following command to get the hardware address:
i2cdetect -y 0
Now we need to tell Linux to instantiate the device. Change the hardware address to the address found in the previous step with '0x' as prefix (e.g. 0x48) and choose a device name:
echo <devicename> <hardware address> >/sys/class/i2c-adapter/i2c-0/new_device
Check the dmesg command for a new entry:
i2c-0: new_device: Instantiated device ds1621 at 0x48
Finally, read the sensor output:
sensors
QEMU chroot
Sometimes it is easier to work directly on a disk image instead of the real Raspberry Pi. This can be achieved by mounting an SD card containing the RPi root partition and chrooting into it. From the chroot it should be possible to run pacman and install more packages, compile large libraries etc. Since the executables are for the ARM architecture, the translation to x86 needs to be performed by QEMU.
Install binfmt-supportAUR and qemu-user-staticAUR from the AUR.
Make sure that the ARM to x86 translation is active:
# update-binfmts --importdir /var/lib/binfmts/ --import # update-binfmts --display qemu-arm
If ARM to x86 translation is not active, enable it using update-binfmts:
# update-binfmts --enable qemu-arm
Mount the SD card to mnt/
(the device name may be different).
# mkdir mnt # mount /dev/mmcblk0p2 mnt
Copy the QEMU executable, which will handle the translation from ARM, to the SD card root:
# cp /usr/bin/qemu-arm-static mnt/usr/bin
Finally chroot into the SD card root as described in Change root#Using chroot.
See also
- RPi Config - Excellent source of info relating to under-the-hood tweaks.
- RPi vcgencmd usage - Overview of firmware command vcgencmd.
- Arch Linux ARM on Raspberry PI - A FAQ style site with hints and tips for running Arch Linux on the RPi
- [1] - A really opionionated guide how to setup a RPi with Arch Linux