Difference between revisions of "Raspberry Pi"

From ArchWiki
Jump to: navigation, search
(I2C: there are many other uses than ''sensors'' for i2c devices)
(Archive article. The template has been present for over a year. Please contribute further edits to the ALARM wiki. https://archlinuxarm.org/wiki/Contributing)
Line 1: Line 1:
[[Category:ARM architecture]]
+
#REDIRECT: [[ArchWiki:Archive]]
[[cs:Raspberry Pi]]
 
[[ja:Raspberry Pi]]
 
[[ru:Raspberry Pi]]
 
[[uk:Raspberry Pi]]
 
[[zh-hans:Raspberry Pi]]
 
{{Archive|Merged to [https://archlinuxarm.org/platforms/armv6/raspberry-pi].[https://github.com/archlinuxarm/wiki/pull/4] Redirect to [[:Category:ARM architecture]].}}
 
 
 
From [[Wikipedia:Raspberry_Pi|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 ([[Wikipedia:ARM11|ARM11 architecture]]). The Raspberry Pi 2, released in 2015, is shipped with a BCM2836 SoC (quad-core [[Wikipedia:ARM Cortex-A7|ARM Cortex-A7 architecture]]). In February 2016, the Pi 3 was launched which contains a BCM2837 SoC (quad-core [[Wikipedia:ARM Cortex-A53|ARM Cortex-A53 architecture]]) and built in WiFi and Bluetooth.
 
 
 
== Article preface ==
 
This article is not meant to be an exhaustive setup guide and assumes that the reader has setup an Arch system before.
 
 
 
{{Note|Support for the ARM architecture is provided on http://archlinuxarm.org not through posts to the official Arch Linux Forum.  Any posts related to ARM specific issues will be promptly closed per the [[Code of conduct#Arch Linux distribution support *only*]] policy.}}
 
 
 
== System architecture ==
 
 
 
The Raspberry Pi is an ARM-based device and therefore needs binaries compiled for this architecture. These binaries are provided by the [http://archlinuxarm.org/about 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+, Zero, Zero W
 
* ARMv7 (BCM2836): Raspberry Pi 2 (based on Model B+)
 
* ARMv8 (BCM2837): Raspberry Pi 3
 
 
 
== SD card performance ==
 
 
 
System responsiveness, particularly during operations involving disk I/O such as updating the system, can be adversely affected by poor quality/slow SD media.  This is characterized by [http://archlinuxarm.org/forum/viewtopic.php?f=64&t=9467 frequent, often extended pauses] as pacman writes out files to the file system.  The pauses are not due to saturation of the bus but are likely caused by a slow micro SD card. See the [[Benchmarking#Flash media]] for measuring performance.  The recommended solution is use so-called "Pro" class media classified as UHS-I U3 or better.  As well, performance and system responsiveness can be tweaked by making adjustments to the system configuration. See [[Improving performance]].
 
 
 
=== Enable fsck on boot ===
 
 
 
Follow [[fsck#Boot time checking]]. Remember that kernel parameters are specified in {{ic|/boot/cmdline.txt}}.
 
 
 
== Installing Arch Linux ARM ==
 
 
 
See the [http://archlinuxarm.org/platforms/armv6/raspberry-pi Arch Linux ARM Pi documentation] or [http://archlinuxarm.org/platforms/armv7/broadcom/raspberry-pi-2 Arch Linux ARM RPi2 documentation] or [https://archlinuxarm.org/platforms/armv8/broadcom/raspberry-pi-3 Arch Linux ARM RPi3 documentation].
 
 
 
{{Note|Although the RPi3 can run either ARMv7 (32-bit) or AArch64 (64-bit) architectures, there is currently no support for the vendor-provided libraries, extensions, or related software for AArch64 and some hardware on the board may not work, or may perform poorly.  ARMv7 is recommended at this time.}}
 
 
 
== Network ==
 
 
 
The fresh install comes preconfigured to use the onboard Ethernet NIC in DHCP mode via [[systemd-networkd]]. This should allow access to an official installation through [[Secure Shell]]. The default hostname is '''alarmpi'''. The root user's password is "root" and it is highly recommended to change the password and optionally set up [[SSH keys]].
 
 
 
=== Configure WLAN without ethernet ===
 
 
 
Users needing to establish a wireless internet connection will need to use a wireless daemon such as [[WPA supplicant]]. See also [[Wireless network configuration]].
 
 
 
== Audio ==
 
{{Pkg|alsa-utils}} should supply the needed programs to use onboard sound. Default volume can be adjusted using {{ic|alsamixer}}.
 
 
 
A key change with Linux kernel version 4.4.x for ARM related to ALSA and to the needed sound module: in order to use tools such as {{ic|alsamixer}} with the current kernel, users ''must'' modify {{ic|/boot/config.txt}} to contain the following line:
 
 
 
dtparam=audio=on
 
 
 
{{Tip|Ensure that the sole source "PCM" is not muted (denoted by {{ic|MM}} if muted, press {{ic|M}} to unmute).}}
 
 
 
Select an audio source for output:
 
$ amixer cset numid=3 ''x''
 
 
 
Where {{ic|''x''}} corresponds to:
 
*0 for Auto
 
*1 for Analog out
 
*2 for HDMI
 
 
 
=== Caveats for HDMI audio ===
 
Some applications require a setting in {{ic|/boot/config.txt}} to force audio over HDMI:
 
hdmi_drive=2
 
 
 
=== Caveats for Analogue audio ===
 
Sometimes audio from the 3.5mm analogue output can be terribly distorted. Adding the following to {{ic|/boot/config.txt}} may fix the problem.
 
audio_pwm_mode=2
 
 
 
== Video ==
 
 
 
=== CPU/GPU RAM split ===
 
Memory split between the CPU and GPU of the SoC can be set in {{ic|boot/config.txt}} by adjusting the parameter {{ic|gpu_mem}} which stands for the amount of RAM in MB that is available to the GPU (minimum 16, default 64) and the rest is available to the ARM CPU.
 
 
 
=== HDMI / analog TV-Out ===
 
With the default configuration,  the Raspberry Pi uses HDMI video if a  [[wikipedia:HDMI|HDMI]] monitor is connected.  Otherwise, it uses analog TV-Out (also known as composite output or RCA)
 
 
 
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 {{ic|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
 
 
 
Or simply disable overscan if the TV/monitor has a "fit to screen" option.
 
 
 
disable_overscan=1
 
 
 
Users wishing to use the analog video out should consult [https://raw.github.com/Evilpaul/RPi-config/master/config.txt this] config file which contains options for non-NTSC outputs.
 
 
 
A reboot is needed for new settings to take effect.
 
 
 
=== Caveats for analog TV-Out ===
 
 
 
Since Raspberry Pi 1 Model B+ and Raspberry Pi 2 Model B, the composite video socket was removed, with the replacement of composite signal through the 3.5mm video/audio jack. Some RCA cables do not follow the same standard as Raspberry Pi, in which case connect the red or white audio plug for video.[http://www.raspberrypi-spy.co.uk/2014/07/raspberry-pi-model-b-3-5mm-audiovideo-jack/]
 
 
 
=== X.org driver ===
 
 
 
The X.org driver for Raspberry Pi can be [[installed]] with the ''xf86-video-fbdev'' or ''xf86-video-fbturbo-git'' package.
 
 
 
== Onboard hardware sensors ==
 
=== Temperature ===
 
Temperatures sensors can be queried with utils in the ''raspberrypi-firmware'' package.  The RPi offers a sensor on the BCM2835 SoC (CPU/GPU):
 
 
 
{{hc|$ /opt/vc/bin/vcgencmd measure_temp|2=
 
temp=49.8'C
 
}}
 
 
 
Alternatively, simply read from the file system:
 
{{hc|$ cat /sys/class/thermal/thermal_zone0/temp|2=
 
49768
 
}}
 
 
 
For human readable output:
 
{{hc|$ awk '{printf "%3.1f°C\n", $1/1000}' /sys/class/thermal/thermal_zone0/temp|2=
 
54.1°C
 
}}
 
 
 
=== Voltage ===
 
Four different voltages can be monitored via {{ic|/opt/vc/bin/vcgencmd}} as well:
 
 
 
$ /opt/vc/bin/vcgencmd measure_volts ''<id>''
 
 
 
Where {{ic|''<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
 
 
 
=== Watchdog ===
 
BCM2708 has a hardware watchdog which can be utilized by enabling the {{ic|bcm2708_wdog}} [[kernel module]].
 
 
 
For proper operation, install the ''watchdog'' package, configure it (by uncommenting the "watchdog-device" line in {{ic|/etc/watchdog.conf}}) and [[enable]] {{ic|watchdog.service}}.
 
 
 
This should also apply for Raspberry Pi 2 by using the {{ic|bcm2709_wdog}} module and Raspberry Pi 3 by using the {{ic|bcm2835_wdt}} module.
 
 
 
=== Lightweight monitoring suite ===
 
{{AUR|monitorix}} has specific support for the RPi since v3.2.0 through the {{ic|1=raspberrypi = y}} setting in {{ic|/etc/monitorix/monitorix.conf}}.  Temperature, voltages, and frequencies are logged; screenshots available [http://www.monitorix.org/screenshots.html here].
 
 
 
== Overclocking/underclocking ==
 
 
 
The RPi can be overclocked by editing {{ic|/boot/config.txt}}, for example:
 
 
 
 
'''Raspberry Pi 1: Defaults'''
 
 
 
arm_freq=700
 
core_freq=250
 
sdram_freq=400
 
 
 
 
 
'''Raspberry Pi 1: Overclocked'''
 
 
 
arm_freq=800
 
arm_freq_min=100
 
core_freq=300
 
core_freq_min=75
 
sdram_freq=400
 
over_voltage=0
 
 
 
'''Raspberry Pi 3: Defaults:'''
 
arm_freq=1200
 
core_freq=400
 
sdram_freq=450
 
 
 
'''Raspberry Pi 3: Overclocked'''
 
arm_freq=1350
 
core_freq=500
 
sdram_freq=500 # test required
 
over_voltage=4
 
 
 
 
The optional {{ic|*_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 [http://elinux.org/RPiconfig#Overclocking 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.
 
 
 
{{Tip|The following script will show all frequencies set on the RPi:
 
{{bc|<nowiki>
 
#/bin/bash
 
for src in arm core h264 isp v3d uart pwm emmc pixel vec hdmi dpi ; do
 
    echo -e "$src:\t$(/opt/vc/bin/vcgencmd  measure_clock $src)"
 
done
 
</nowiki>}}
 
}}
 
 
 
== Serial console ==
 
Edit the default {{ic|/boot/cmdline.txt}}, change {{ic|loglevel}} to {{ic|5}} to see boot messages:
 
loglevel=5
 
 
 
{{Note|The RPi3 requires {{ic|1=enable_uart=1}} be added to {{ic|/boot/config.txt}} in order to display boot messages in some kernel versions. In others (such as 4.9.35), this line prevents proper booting, so as of June 2017 it seems that this bug is still not resolved.}}
 
 
 
If the default speed of 115200 does not work properly, try changing it to 38400:
 
console=ttyAMA0,38400 kgdboc=ttyAMA0,38400
 
 
 
[[Start]] and [[enable]] the {{ic|getty@ttyAMA0}} systemd service on the Pi.
 
 
 
Creating the proper service link:
 
# ln -s /usr/lib/systemd/system/serial-getty@.service /etc/systemd/system/getty.target.wants/serial-getty@ttyAMA0.service
 
 
 
From a PC, connect:
 
# screen /dev/ttyUSB0 38400
 
 
 
== Raspberry Pi camera module ==
 
The commands for the camera module are included as part of the ''raspberrypi-firmware'' package - which is installed by default.
 
$ /opt/vc/bin/raspistill
 
$ /opt/vc/bin/raspivid
 
 
 
Append to {{ic|/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 {{ic|/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:
 
{{hc|/etc/modprobe.d/blacklist.conf|blacklist i2c_bcm2708}}
 
 
 
In order to use standard applications (those that look for {{ic|/dev/video0}}) the V4L2 driver must be loaded.  This can be done automatically at boot by creating an autoload file such as the following.
 
{{hc|/etc/modules-load.d/rpi-camera.conf|bcm2835-v4l2}}
 
 
 
The V4L2 driver by default only allows video recording up to 1280x720, else it glues together consecutive still screens resulting in videos of 4 fps or lower. Adding the following options removes this limitation.
 
{{hc|head=/etc/modprobe.d/rpi-camera.conf|output=options bcm2835-v4l2 max_video_width=3240 max_video_height=2464}}
 
 
 
== Hardware random number generator ==
 
Arch Linux ARM for the Raspberry Pi had the {{ic|bcm2708-rng}} module set to load at boot (see [http://archlinuxarm.org/forum/viewtopic.php?f=31&t=4993#p27708 this]); starting with kernel 4.4.7 the {{ic|bcm2835_rng}} module replaces the former on Raspberry Pi 2 and Raspberry Pi 3 units.
 
 
 
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 {{ic|/etc/conf.d/rngd}}:
 
 
 
RNGD_OPTS="-o /dev/random -r /dev/hwrng"
 
 
 
and enabling and [[start]]ing the ''rngd'' service.
 
 
 
If [[haveged]] is running, it should be stopped and disabled, as it might compete with ''rngd'' and is only preferred when there is no hardware random number generator available.
 
 
 
Once completed, this change ensures that data from the hardware random number generator is fed into the kernel's entropy pool at {{ic|/dev/random}}. To check the available entropy, run:
 
 
 
# cat /proc/sys/kernel/random/entropy_avail
 
 
 
The number it reports should be around 3000, whereas before setting up ''rngd'' it would have been closer to 1000.
 
 
 
== I/O pins ==
 
=== GPIO ===
 
To be able to use the GPIO pins from Python, use the [https://pypi.python.org/pypi/RPi.GPIO RPi.GPIO] library. Install the {{AUR|python-raspberry-gpio}} package.
 
 
 
=== SPI ===
 
To enable the {{ic|/dev/spidev*}} devices, uncomment the following line:
 
{{hc|head=/boot/config.txt|output=
 
device_tree_param=spi=on
 
}}
 
 
 
=== I2C ===
 
 
 
Install the ''i2c-tools'' package.
 
 
 
Configure the bootloader to enable the i2c hardware by appending {{ic|/boot/config.txt}}:
 
dtparam=i2c_arm=on
 
 
 
Configure the {{ic|i2c-dev}} and {{ic|i2c-bcm2708}} (if not blacklisted for the camera) modules to be loaded at boot:
 
 
 
{{hc|/etc/modules-load.d/raspberrypi.conf|i2c-dev
 
i2c-bcm2708}}
 
 
 
Reboot the Raspberry Pi and issue the following command to get the hardware address:
 
# i2cdetect -y 0
 
 
 
{{Note|When using the I2C1 port instead of I2C0, one will need to run {{ic|i2cdetect -y 1}} instead and replace {{ic|i2c-0}} with {{ic|i2c-1}} in the following steps.}}
 
 
 
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
 
 
 
Now you can use the device with a program like [[lm_sensors]].
 
 
 
== Compiling on the RPi ==
 
 
 
Compiling can be very slow on a RPi.  [[Distcc]] can greatly improve compilation times if other nodes are on the network.  For users with x86_64 or i686 boxes, [[Distcc#Arch Linux ARM]] describes the proper setup for distcc to use these resources.
 
 
 
 
 
== 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]].
 
 
 
Note that only 64 bit Raspberry Pi models can use {{ic|aarch64}}, the rest need to use {{ic|arm}}.
 
 
 
Install {{AUR|binfmt-support}} and {{AUR|qemu-user-static}} from the [[AUR]].
 
 
 
Enable and start the binfmt-support service:
 
# systemctl enable binfmt-support
 
# systemctl start binfmt-support
 
 
 
{{AUR|qemu-user-static}} is needed to allow the execution of compiled programs from other architectures. This is similar to what is provided by {{Pkg|qemu-arch-extra}}, but the "static" variant is required for chroot. Examples:
 
qemu-arm-static path_to_sdcard/usr/bin/ls
 
qemu-aarch64-static path_to_sdcard/usr/bin/ls
 
 
 
These two lines execute the {{ic|ls}} command compiled for 32-bit ARM and 64-bit ARM respectively. Note that this will not work without chrooting, because it will look for libraries not present in the host system.
 
 
 
{{AUR|qemu-user-static}} allows automatically prefixing the ARM exectuable with {{ic|qemu-arm-static}} or {{ic|qemu-aarch64-static}}.
 
See for example {{ic|/var/lib/binfmts/qemu-arm}} and the {{ic|qemu-user-static}} [https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=qemu-user-static#n38 PKGBUILD].
 
 
 
Make sure that the ARM executable support is active:
 
 
 
# update-binfmts --display qemu-arm
 
# update-binfmts --display qemu-aarch64
 
 
 
If it is not active, enable it using update-binfmts:
 
 
 
# update-binfmts --enable qemu-arm
 
# update-binfmts --enable qemu-aarch64
 
 
 
Mount the SD card to {{ic|mnt/}} (the device name may be different).
 
 
 
# mkdir mnt
 
# mount /dev/mmcblk0p2 mnt
 
 
 
Mount boot partition if needed (again, use the suitable device name):
 
 
 
# mount /dev/mmcblk0p1 mnt/boot
 
 
 
Copy the QEMU executables, which will handle the translation from ARM, to the SD card root:
 
 
 
# cp /usr/bin/qemu-arm-static /usr/bin/qemu-aarch64-static mnt/usr/bin
 
 
 
Finally chroot into the SD card root as described in [[Change root#Using chroot]]:
 
 
 
# chroot mnt/ /bin/bash
 
 
 
Alternatively, you can use {{ic|arch-chroot}} from {{Pkg|arch-install-scripts}}, as it will provide network support:
 
# arch-chroot mnt/ /bin/bash
 
 
 
== See also ==
 
* [https://www.raspberrypi.org Raspberry Pi] - Official website
 
* [http://elinux.org/RPiconfig RPi Config] - Excellent source of info relating to under-the-hood tweaks.
 
* [http://elinux.org/RPI_vcgencmd_usage RPi vcgencmd usage] - Overview of firmware command vcgencmd.
 
* [http://archpi.dabase.com/ Arch Linux ARM on Raspberry PI] - A FAQ style site with hints and tips for running Arch Linux on the RPi
 

Revision as of 23:50, 24 September 2017

Redirect to: