The Raspberry Pi Computer - Seite 1 / 40 Edition 2
←
→
Page content transcription
If your browser does not render page correctly, please read the page content below
http://bitkistl.blogspot.com/ The Raspberry Pi Computer Author: Peter Bauer Edition 2 / Jannuary 2013 Seite 1 / 40 Contact: peba@inode.at Edition 2
Table of contents 1. INTRODUCTION............................................................................................................................3 2. Abbreviations and Terms..................................................................................................................5 3. Hardware Overview Raspberry Pi Typ B.........................................................................................8 3.1 The LED's of the Raspberry Pi..................................................................................................9 3.2 Type B Revisionen.....................................................................................................................9 4. Software Overview Raspberry Pi...................................................................................................10 4.1 Preparing the SD card on a Windows computer......................................................................10 4.2 Preparing the SD card on a Linux computer ...........................................................................12 4.3 Preparing the SD card on a Mac OS X computer ...................................................................13 4.4 Content of the boot Partition....................................................................................................14 4.5 RISC OS on the Raspberry PI..................................................................................................15 5. Startup of the Raspberry Pi.............................................................................................................16 5.1 Configuration via raspi-config script.......................................................................................17 6. The Raspberry Pi in Detail.............................................................................................................19 6.1 Debian or Raspbian as operating system ................................................................................19 6.1.1 Connect to LAN...............................................................................................................20 6.1.2 Audio and Video output on RPI using Debian.................................................................23 6.1.3 Configuration via config.txt.............................................................................................24 6.1.4 The graphical desktop in Debian......................................................................................25 6.2 The GPIO connector ...............................................................................................................26 6.2.1 Control GPIO Pins with Python and Shellscript..............................................................27 6.3 Hardware Extensions...............................................................................................................28 6.3.1 The Piface interface card .................................................................................................28 6.4 Report Linux bugs .................................................................................................................29 6.5 Diagnosis of hard- and software problems in Linux ...............................................................30 6.5.1 Networking with WLAN..................................................................................................32 6.6 Using Raspbmc as operating system ......................................................................................34 6.7 Using Archlinux ARM as operating system ...........................................................................35 6.8 Useful software applications....................................................................................................36 6.8.1 SSH server and SSH client...............................................................................................36 6.8.2 Filesharing with SAMBA ................................................................................................37 6.8.3 Remote Control of the RPI desktop via VNC..................................................................38 6.8.4 Web Server with Lighttpd ...............................................................................................40 7. Resources for the Raspberry Pi on the Internet .............................................................................41 Seite 2 / 40 Contact: peba@inode.at Edition 2
1. INTRODUCTION This book should serve as a hobbyists help for getting started with the Raspberry PI. It was created because there is a wealth of information on the Internet, but unfortunately everything around is very scattered and an orderly book is the best way to describe something and learn something. In this book RPI is used as a shortcut for Raspberry Pi. Currently there are two different Types of the RPI called the Model A and Model B. Model A has one USB connector und no Ethernet connector. Model B has two USB connectors and one Ethernet interface. The software of the RPI is still in development, with Raspbian the developers succeeded to produce a stable Linux distribution with good performance. It's up to the user to explore this Linux distribution and to find the right program for a particular purpose. For pure multimedia playback it is worthwhile taking a look at Raspbmc. Currently the operation of Raspbmc is still a little lame, here is still some potential for improvement. For questions about the RPI I am available by email. http://bitkistl.blogspot.co.at/2013/01/raspberry-pi-e-book.html If you found this book useful you can donate via Paypal to support this E-Book project. https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QNKHGXF3MDV9W Have fun with the Raspberry Pi, Peter Bauer Seite 3 / 40 Contact: peba@inode.at Edition 2
2. Abbreviations and Terms API Application Programming Interface APT Advanced Packaging Tool, a software package management tool for Linux. With APT single programs can be installed or the whole Linux distribution can be updated. ARM Advanced Risc Machines, british Chip Design Developer. The ARM Chips are produced from many companies. armel Name of the current port of Debian for the ARM v6 architecture armhf "hard float" means support for fast floating point calculations via hardware Raspbian Port of the Debian Operating system, this port is optimized for the skills of the RPI CPU. CLI Command Line Interface, Text based interface for the input of commands to the operating system. After booting Linux the shell is waiting for inputs from the user. The CLI or shell has advantages when you need to automate some commands which can be done with so called shell scripts. CPU Central Processing Unit embedded Computer which does its task (e.g. control task) in a device in the System background in contrast to a desktop computer. FAQ Frequently asked questions e.g. http://www.raspbian.org/RaspbianFAQ GPU Graphics processor, Broadcom Videocore IV. Can play videos in high definition and supports acceleration of graphics. Supported Standards are OpenGL ES 2.0, OpenVG 1.1. The GPU must share the available RAM with the CPU. The RAM for the GPU is configurable in the size of 32,64 or 128 MB. IP Internet Protocol IRC Internet Relay Chat, it is possible to chat with the developers and other users by the use of an IRC Client program. OpenGL ES 3D API for embedded systems OpenVG 2D API for Vektor- and Bitmap graphics binary blob Software which is not Open Source, the RPI uses a binary blob to control the Seite 4 / 40 Contact: peba@inode.at Edition 2
GPU. The Raspberry Pi Foundation delivers this binary blob with all linux images. RPI Raspberry Pi Computer, a product of the Raspberry Pi Foundation USB 2.0 Universal Serial Bus - here mouse, keyboard and other devices are connected. If you need more than two connectos or more then 100 mA current an active USB Hub is required. LED Light emitting Diode HDMI High Definition Multimedia Interface (suported Version 1.3a from the RPI) RAM Random Access Memory, the main memory of the RPI is 256 (Model A) or 512 MByte (Model B). SD Card Secure Digital Memory Card The RPI boots from a SD card. If you buy a SD card its good to choose a class 4 or 6 card. These are known to work good with the RPI. SSH Secure Shell is the name of a protocol for the secure transmission of data. You need a SSH Client when you want to use it on your pc. For Windows the program Putty http://www.putty.org/ is recommended. RCA Radio Corporation of America, analogue video connector. Here a cable to a TV with Cinch Plug can be connected. CSI Camera Serial Interface, this year a camera module with 5 Megapixels should be available. It should cost around 25 Euros. DSI Display Serial Interface, not documented for the end user DHCP Dynamic Host Configuration Protocol Is used to get a valid IP Address. GPIO General Purpose Input/Output GUI Graphical User Interface, some Linux programs have no GUI e.g.: omxplayer (Multimedia Player). JTAG Joint Test Action Group Connector for Test and Debugging of the RPI Hardware. This is an interface for the developers. BCM 2835 SoC contains CPU,GPU and FPU of the RPI from Broadcom. The CPU computes with 32 Bit and a clock rate of 700 Mhz. This CPU(ARM1176JZFS) is from the architectural point of view an ARM11 based on the ARM v6 family. Seite 5 / 40 Contact: peba@inode.at Edition 2
overclocking The RPI can be overclocked up to 1Ghz. This can be done with the script raspi-config. polyfuse Is a resetable fuse. Is used in the RPI for limitting the current on the USB connectors (early RPI versions) and for limitting the current from the power supply (1100 mA). If you accidently cause a shortcut on the power supply and you have some luck your RPI will work again after the polyfuse is resetted. SoC System on Chip, means that different functions are integrated on one chip UNIX multiuser operating system, the Open Source variant is called Linux XBMC Open Source Media Player, there are several port for the RPI (Raspbmc, OpenELEC, XBian) X Windows also known as X11 is the window manager of Unix and Linux Seite 6 / 40 Contact: peba@inode.at Edition 2
3. Hardware Overview Raspberry Pi Typ B USB 2.0 Ethernet 2x RPI Typ B: S LED's Audio Output 3,5 mm jack CSI camera connector RCA Video output HDMI output GPIO Input and output BCM 2835 ARM 11 DSI Micro USB 700 MHz Display connector Power supply 5 Volt, 1 Ampere Seite 7 / 40 Contact: peba@inode.at Edition 2
3.1 The LED's of the Raspberry Pi The RPI has 5 LEDs which show the state of the device. OK green Blinks during Boot and during SD card access PWR red PowerOn, ist directly connected to the 3,3V voltage of the RPI FDX green FullDuplex LNK green Blinks, off during Ethernet activity 10M yellow 100 Mbit LED 3.2 Type B Revisionen Model und Revisionen Code(s) comment Model B Revision 1.0 2 Model B Revision 1.0 3 no polyfuses, D14 removed Model B Revision 2.0 4, 5, 6 with 2,5 mm mounting holes Model B Revision 2.0(512MB) 13,14,15 bzw. d,e,f in hexadecimal Request of CPU Version and RPI serial number via terminal: pi@raspberrypi ~ $ cat /proc/cpuinfo Processor : ARMv6-compatible processor rev 7 (v6l) BogoMIPS : 697.95 Features : swp half thumb fastmult vfp edsp java tls CPU implementer : 0x41 CPU architecture: 7 CPU variant : 0x0 CPU part : 0xb76 CPU revision : 7 Hardware : BCM2708 Revision : 0002 Serial : 0000000025cd2f93 Since October 2012 the RPI Model B is deliverd with 512 MB RAM. Seite 8 / 40 Contact: peba@inode.at Edition 2
4. Software Overview Raspberry Pi There are several unix like operating systems for the RPI and there is an operating system called RISC OS that has its origin at the developers of the first ARM chips. The Raspberry Pi Foundation recommends the use of the following Linux Distributions and offers these for Download: • Debian 7 ("Wheezy") /* Soft Float (slow floating point calculations) Oracle JVM requires this • Raspbian ("Wheezy") /* has its origin in Debian 7 - recommended Distribution of the RPI Foundation • Arch Linux ARM • QtonPi Download link for the operating system images for the RPI: http://www.raspberrypi.org/downloads For booting the RPI a SD card is necessary. The RPI Foundation recommends a SD card with 4 GB. For flashing the image to the SD card there are programs for the PC running Winodws, Mac OS X or Linux. 4.1 Preparing the SD card on a Windows computer You need a SD Cardreader/writer, the Win32DiskImager and the operating system image. 1. Download the operating system image 2. Unzip the file *.zip to *.img 3. Insert the SD Card in your SD Cardreader and remember the drive letter. 4. Download Win32DiskImager , the download links are on the right side. 5. Unzip the Win32DiskImager and start it. 6. Select the file *.img 7. Select the drive letter in the device box (Attention: When you select the wrong drive letter your harddisc can be damaged) 8. Click write und wait for the completion 9. Quit the Win32DiskImager und take out the SD card from your Cardreader. 10. Insert the SD Card in your RPI and connect the power supply. The RPI should boot now. Seite 9 / 40 Contact: peba@inode.at Edition 2
Alternative methode if your RPI does not boot: 1. Download the operating system image 2. Unzip the file *.zip to *.img 3. Insert the SD Card in your SD Cardreader and remember the drive letter. 4. Download the program http://shounen.ru/soft/flashnul/ and unzip it. 5. Start button > All Programs > Accessories > Command Prompt (start with right mouse click as Admin) 6. C:/flashnul/flashnul.exe -p Available physical drives: 0 size = 250059350016 (232 Gb) 1 size = 1990197248 (1898 Mb) --> SD Card values Available logical disks: C:\ D:\ F:\ G:\ H:\ Press ENTER to exit. 7. C:/flashnul/flashnul.exe 1 -L C://*.img (The number 1 is the number of your SD Card and was printed by the previous command on the left side) If you get the error message "access denied" try it again with the assigned drive letter. C:/flashnul/flashnul.exe H: -L C://*.img Seite 10 / 40 Contact: peba@inode.at Edition 2
4.2 Preparing the SD card on a Linux computer 1. Download the operating system image 2. Unzip the file *.zip to *.img 3. Check with the command df -h which discs are mounted 4. Insert the SD Card in your SD Cardreader 5. Check again with df -h which disc are mounted The newly added disc is your SD Card 6. enter as root user: unmount /dev/sdd1 /* Could have a different name The unmount is necessary for the following command 7. enter as root user: dd bs=1M if=~//*.img of=/dev/sdd After the "if" (short for input file) the filename and path for the image files must be entered The dd command has no process indicator and can take a while 8. enter command: sync To ensure that all data are written to the SD Card and you can safely remove the SD Card from the SD Cardreader 9. Insert the SD Card in your RPI and connect the power supply. The RPI should boot now. Seite 11 / 40 Contact: peba@inode.at Edition 2
4.3 Preparing the SD card on a Mac OS X computer 1. Download the operating system image 2. Unzip the file *.zip to *.img 3. Start df -h vom Terminal 4. Insert the SD card in your SD cardreader 5. Check with df -h which discs are mountet The newly added discs is your SD card Remember the discs name e.g. /dev/disk3s1 6. Unmount this disc commad: diskutil unmount /dev/disk3s1 7. Determine the disc name for the raw device: /dev/disk3s1 --> /dev/rdisk3 (disk --> rdisk, s1 is leaved off) 8. command: sudo dd bs=1m if=~/Downloads//*.img of=/dev/rdisk3 After the "if" (short for input file) the filename and path for the image files must be entered 9. enter command: diskutil eject /dev/rdisk3 10. Insert the SD Card in your RPI and connect the power supply. The RPI should boot now. Seite 12 / 40 Contact: peba@inode.at Edition 2
4.4 Content of the boot Partition The boot partition of the SD card is formatted as FAT32 (data are readable form Windows PC) It contains the following files: • bootcode.bin 2nd stage bootloader, starts with switched off SDRAM • loader.bin 3rd stage bootloader, starts with activated SDRAM • start.elf GPU firmware image, provided by the Raspberry Pi Foundation • kernel.img default Linux operating system kernel • kernel_cutdown.img cutdown Kernel • kernel_emergency.img Kernel version for emergency (kernel.img does not work) • cmdline.txt Parameter for the Kernel Optional files: • config.txt a configuration file which is read by the GPU on boot You can change the Video Mode, the System clock and voltages • vlls folder optional GPU programs (e.g. codecs) Seite 13 / 40 Contact: peba@inode.at Edition 2
4.5 RISC OS on the Raspberry PI Since October 2012 RISC OS is released for the RPI. RISC OS was originally developed for the Acorn Archimedes and the Risc PC. This operating system was running on the first types of the ARM processor from ARM2 up to the StrongArm. The advantages of RISC OS can be explained quickly: • uses low resources, most of the RISC OS programs do not require a fast processor, do not use many memory and do not require a large harddsisc • RISC OS boots in just about 10 seconds in a graphical desktop • for operation a three key mouse is required, the keys have the function select, menu and adjust • the configuration of the operating system is done completely via the desktop GUI • RISC OS is a single user, multi tasking operating system. It uses cooperative multitasking. This means that a single program gives control to the next program when it has finished its task. Release Note und Download: https://www.riscosopen.org/news/articles/2012/10/26/risc-os-pi-released-risc-os-for-the-raspberry-pi http://downloads.raspberrypi.org/images/riscos/ The Installation of the operating system to the SD card is done like in chapter 4.1 bis 4.3. RISC OS includes some useful applications: • the slim Webbrowser Netsurf (Youtube does not work) • Draw, Paint and Edit for drawing and editing • SwiftJPEG, ChangeFSI for viewing and conversion of pictures • Omniclient to access fileshares (Samba or CIFS) • a paket manager and App Store (in Development) named Store. With the paket manager and the App Store many additional programs can be installed, many of them are free of cost RISC OS is not good in: • playing videos ist slow, the GPU is not used Seite 14 / 40 Contact: peba@inode.at Edition 2
5. Startup of the Raspberry Pi You will need the following things to startup the Raspberry Pi for the first time: • USB keyboard und USB mouse. The current is limited to 100 mA per USB connector • Prepared SD card with the operating system (see chapter 4) • A TV with HDMI or Composite connector or monitor with HDMI connector (perhaps an adapter from HDMI to DVI if your monitor has such a connector) VGA is not supported by the RPI ! • A power supply with micro USB plug. The power supply should supply at least 700 mA at 5 Volt. Der RPI has a fuse rated with 1100 mA on the PCB. • One ethernet lan cabel (optional) A good overview with pictures can be found here: http://www.raspberrypi-spy.co.uk/2012/03/raspberry-pi-cables-connectors/ Insert the prepared SD card into your RPI, plug in all required cables. It is a good idea to plug in the power supply lastly. Your RPI boots and you should be able to watch the boot process in your monitor. If your RPI is connected with a lan cable to your network it will try to obtain an IP address via DHCP. Now you can login with username and password. For Debian Linux or Raspbian the username is "pi" and the password is "raspberry" With the command: startx you can now start the desktop GUI The valid passwords for your SD card image can be found at the Raspberry Downloads http://www.raspberrypi.org/downloads With the command sudo you can get Superuser (root user) rights Seite 15 / 40 Contact: peba@inode.at Edition 2
5.1 Configuration via raspi-config script Debian 7 and Raspbian: command: sudo raspi-config • info - Informaion about this tool Displays a short text about the raspi-config program. • expand_rootfs - Expand root partition to fill SD card The images for the RPI fit nicely on a 4 GB SD card. If you use a larger SD card you need to enlarge your system partition or you make an additional partition. This is necessary when you want to use the additional free space. This menu option does all the work. After invoking this option a reboot is required to activate the resizing of the partition, this may take some time. • overscan - Change overscan This allows us to switch on or off the oversacan. When overscan is enabled the RPI generates a black border around the visible screen. This may be useful for some TV sets. For newer TV sets and TFT monitors overscan can be set to disabled. Changes will become effective after reboot. • configure_keyboard - Set keyboard layout Here the keyboard layout can be choosen. You can choose the keyboard layout from a list. If you can't find your keyboard just choose a generic 105-key one. You also need to select your language version. • change_pass - Change password for 'pi' user The user 'pi' is per default present on the RPI system. The user is there to do every days work. With this option you can change the password for this user. • change_locale - Set locale This option sets the character set and language of the system. When set to your language the programs will display texts in your language if available. • change_timezone - Set timezone Here you can choose your timezone. • memory_split - Change memory split The 256 or 512 MB main memory of your RPI are shared between the CPU and GPU. Currently you can select one of four memory splits. These reserve 32\64\128\256 MB for the GPU, the rest for the ARM11 CPU. When you don't use expensive graphics the 32 MB memory split will work. For a media center or 3D graphics the 128 MB memory split will fit better. Changes will become effective after reboot. The default value is 64 MB. Seite 16 / 40 Contact: peba@inode.at Edition 2
• overclock - configure overclocking The RPI can be overclocked dynamically in several steps. Dynamically meens that the RPI is overclocked on demand. The software also takes care of the temperature of the CPU, the temperature is limited to 85 degrees celsius. If you find that your RPI does not run stable with the the overclock you are using, just try a lower one. There exists widgets for the LXDE Desktop which display the clock frequency and the temperature. When your RPI has a problem with overclockking during boot, you can switch off overclocking by pressing the shift key. Afterwards a reconfiguration of overcocking can be done. • ssh - Enable or disable ssh server By using SSH you can access a text based console (shell) over the network. You can use for example the putty program to access your RPI from a remote PC. The connection is encrypted per default. To allow this access the SSH server program on the RPI must run. • boot_behaviour - Start desktop on boot? Here you can choose to automatically start the desktop during boot. If you don't choose to start the desktop you can start it later by invoking the startx command from the shell. • update - Try to upgrade raspi-config If your RPI is connected to your home network the raspi-config script itself can be updated to the newest version which may offer enhanced or new functionality. Seite 17 / 40 Contact: peba@inode.at Edition 2
6. The Raspberry Pi in Detail 6.1 Debian or Raspbian as operating system Debian Linux for ARM contains about 35.000 software packages If your RPI is connected to the Internet you can check this with the following command. apt-cache pkgnames /* all available packages are listed If you want to know the currently installed packages: command: dpkg -l /* alle installed packages are listed If you would like to install software XXX. Here you need root user rights. command: sudo -i /* now you have root rights command: apt-cache search /* search for packages apt-get install /* install software packages apt-get remove /* remove software packages apt-get purge /* remove software package and its configuraton files With apt-get update the database of software packages can be updated. This is necessary before you apt-get upgrade the whole Linux Distribution. If you want to know which files are installed for a particular software package: dpkg -L /* list files for a package Details about Debian and the ARM Port can be found here: http://www.debian.org/ports/arm/index.de.html sudo apt-get install synaptic /* install paket management tool with GUI /* LXDE -> Administration -> Synaptic Seite 18 / 40 Contact: peba@inode.at Edition 2
6.1.1 Connect to LAN hostname -I /*What IP Addresse has my RPI ? ifconfig /*What state have my network interfaces pi@raspberrypi:~$ ifconfig eth0 Link encap:Ethernet Hardware Adresse b8:27:eb:2b:c3:50 inet Adresse:192.168.1.25 Bcast:192.168.255.255 Maske:255.255.0.0 inet6-Adresse: fe80::ba27:ebff:fe2b:c350/64 Gültigkeitsbereich:Verbindung UP BROADCAST RUNNING MULTICAST MTU:1500 Metrik:1 RX packets:2182737 errors:0 dropped:0 overruns:0 frame:0 TX packets:563997 errors:0 dropped:0 overruns:0 carrier:0 Kollisionen:0 Sendewarteschlangenlänge:1000 RX bytes:3195864956 (2.9 GiB) TX bytes:57555644 (54.8 MiB) lo Link encap:Lokale Schleife inet Adresse:127.0.0.1 Maske:255.0.0.0 inet6-Adresse: ::1/128 Gültigkeitsbereich:Maschine UP LOOPBACK RUNNING MTU:16436 Metrik:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 Kollisionen:0 Sendewarteschlangenlänge:0 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) In the section eth0 see inet address for the IP address and the subnet mask. The lo (loopback Interface) serves the local communication. The IP configuration for the LAN can be found in the following two files: /etc/network/interfaces /* interface configuration /etc/resolv.conf /* DNS server entries /etc/network/interfaces when using DHCP: # The loopback network interface auto lo iface lo inet loopback # The primary network interface auto eth0 iface eth0 inet dhcp /* DHCP vorhanden /etc/resolv.conf: nameserver /* In most cases IP-Address of the router /etc/network/interfaces when using a fixed IP-Configuration: # The loopback network interface auto lo iface lo inet loopback # The primary network interface auto eth0 iface eth0 inet static /* IP address Seite 19 / 40 Contact: peba@inode.at Edition 2
address /* IP address of the RPI netmask /* In home network mostly 255.255.255.0 gateway /* IP address of the router After changing the network configuration a restart of the network services is necessary sudo /etc/init.d/networking restart If the network interface is not working try the following: sudo ifdown eth0 /* deactivate interface and sudo ifup eth0 /* activate interface With the Ping command you can test if packets are transmitted and answered ping -c1 www.google.at /* test if network endpoint answes PING www.google.at (173.194.35.183) 56(84) bytes of data. 64 bytes from muc03s02-in-f23.1e100.net (173.194.35.183): icmp_req=1 ttl=52 time=34.2 ms --- www.google.at ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 34.293/34.293/34.293/0.000 ms Seite 20 / 40 Contact: peba@inode.at Edition 2
With the program lsof (list open files) you can list the running Internet services and the application running behind. If lsof is not yet installed on your RPI you can install it with sudo apt-get install lsof. pi@raspberrypi ~ $ sudo lsof -i COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME ntpd 1369 ntp 16u IPv4 3473 0t0 UDP *:ntp ntpd 1369 ntp 17u IPv4 3477 0t0 UDP localhost:ntp ntpd 1369 ntp 19u IPv4 4118 0t0 UDP raspberrypi:ntp dhclient 1593 root 9u IPv4 3932 0t0 UDP *:bootpc dhclient 1593 root 20u IPv4 3917 0t0 UDP *:32549 sshd 1635 root 3u IPv4 4111 0t0 TCP *:ssh (LISTEN) Of particular interest are the "listening sockets", those are the TCP / IP ports where Applications provides service. In our example it is only the application sshd (secure shell daemon). The protocol ssh provides login option on the Internet to a shell. Seite 21 / 40 Contact: peba@inode.at Edition 2
6.1.2 Audio and Video output on RPI using Debian The RPI supports the sound through the ALSA sound system. Sound output can either be via the 3.5 mm stereo jack or via HDMI. The default is auto which outputs via HDMI if possible. play test sample: sudo aplay /usr/share/sounds/alsa/Front_Center.wav configure audio output: sudo amixer cset numid=3 n is 0=auto, 1=jack connector, 2=hdmi. The omxplayer ist pre installed and can play audio and video files. Since August 2012 omxplayer and the XBMC variants plays MPEG-2 und VC-1 coded videos. The required codecs can be bought from the Raspberry PI Foundation for a small amount. http://www.raspberrypi.com/ /*Raspberry Pi Store pi@raspberrypi ~ $ omxplayer .mp3 file : *.mp3 reult 0 format mp3 audio streams 1 video streams 0 chapters 0 subtitles 0 Audio codec mp3 channels 2 samplerate 44100 bitspersample 16 Subtitle count : 0 state off : index 0 Supported hardware accelerated video formats: MPEG-2,MPEG-4,VC-1 and H264 With apt-get install mplayer you can install an additional media player. Mplayer is not hardware accelerated but videos (MPEG 2) with low res (e.g. 640x480) are ok. On my RPI I need to use the following options: mplayer -ao sdl Seite 22 / 40 Contact: peba@inode.at Edition 2
6.1.3 Configuration via config.txt sudo nano /boot/config.txt /* change configuration sudo reboot /* Restart the RPI When changing the configurtion a reboot is required. # uncomment if you get no picture on HDMI for a default "safe" mode #hdmi_safe=1 # uncomment this if your display has a black border of unused pixels visible # and your display can output without overscan disable_overscan=1 # 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=16 #overscan_top=16 #overscan_bottom=16 # uncomment to force a console size. By default it will be display's size minus # overscan. (sehr nützlich wenn Ihnen die Bildschirmdarstellung zu klein ist) framebuffer_width=1280 framebuffer_height=720 # uncomment if hdmi display is not detected and composite is being output #hdmi_force_hotplug=1 # uncomment to force a specific HDMI mode (this will force VGA) #hdmi_group=1 #hdmi_mode=1 # uncomment to force a HDMI mode rather than DVI. This can make audio work in # DMT (computer monitor) modes #hdmi_drive=2 # uncomment to increase signal to HDMI, if you have interference, blanking, or # no display #config_hdmi_boost=4 # uncomment for composite PAL #sdtv_mode=2 #uncomment to overclock the arm. 700 MHz is the default. #arm_freq=800 #for more options see http://elinux.org/RPi_config.txt Seite 23 / 40 Contact: peba@inode.at Edition 2
6.1.4 The graphical desktop in Debian With raspi-config (see 5.1) it is possible to configure if the RPI shall boot with the GUI or just with a CLI. By using the command startx the manual start of the GUI is possible. The default desktop respectively the GUI of the RPI consists of the LXDE Window manager. LXDE means "Lightweight X11 Desktop Environment" and is a slim windowing system. Debian offers generally a variety of desktop environments, which can always be installed with the package manager (see 6.1). Recommended for the RPI are slim desktop environments. Some examples would be: • XFCE Installation: sudo apt-get install xfce4 Start: startxfce4 • MATE Desktop (Gnome 2 Desktop) Installation see : http://www.raspbian.org/RaspbianMate Seite 24 / 40 Contact: peba@inode.at Edition 2
6.2 The GPIO connector The RPI has a 26 pin connector with freely programmable I/O Pins. The connector has two rows with 13 pins. PIN 1 is clearly marked on the PCB. The numbering works with even numbers on the top row and odd numbers on the bottom row. PIN 1 carries 3V3 with a maximum current of 50 mA. PIN 2 carries 5V which are directly connected to the power supply. Each I/O Pin can source a maximum of 16 mA Attention: Most I/O Pins are connected direct to the Broadcom chip, a short circuit can damage your RPI. http://www.element14.com/community/docs/DOC-43484/l/raspberry-pi-gpio-expansion--low-level- peripherals ... Details about the GPIO connector at Element14 Assignment of the Pins (REV 1 and REV 2 Boards are different): Pins marked DNC (do not connect) should not be used. Here are 8 I/O Pins, and the I2C,SPI and UART Pins. The control of the pins can be done easily with the programming language Python. This requires the installation of a library. http://www.raspberrypi-spy.co.uk/2012/05/install-rpi-gpio-python-library/ Seite 25 / 40 Contact: peba@inode.at Edition 2
6.2.1 Control GPIO Pins with Python and Shellscript Python script: import RPi.GPIO as GPIO # configure GPIO Pins - one input and one output GPIO.setup(11, GPIO.IN) GPIO.setup(12, GPIO.OUT) # read input from pin 11 input_value = GPIO.input(11) # output to Pin 12 GPIO.output(12, True) The Numbering of the Pins 11 and 12 in this example refers to the physical Pins GPIO 17 and GPIO 18 see picture. Shell script: #!/bin/sh # GPIO numbers should be from this list # 0, 1, 4, 7, 8, 9, 10, 11, 14, 15, 17, 18, 21, 22, 23, 24, 25 # Note that the GPIO numbers that you program here refer to the pins # of the BCM2835 and *not* the numbers on the pin header. # So, if you want to activate GPIO7 on the header you should be # using GPIO4 in this script. Likewise if you want to activate GPIO0 # on the header you should be using GPIO17 here. # set up GPIO 4 and set to output echo "4" > /sys/class/gpio/export echo "out" > /sys/class/gpio/gpio4/direction # set up GPIO 7 and set to input echo "7" > /sys/class/gpio/export echo "in" > /sys/class/gpio/gpio7/direction # write output echo "1" > /sys/class/gpio/gpio4/value # read from input cat /sys/class/gpio/gpio7/value # clean up echo "4" > /sys/class/gpio/unexport echo "7" > /sys/class/gpio/unexport Seite 26 / 40 Contact: peba@inode.at Edition 2
6.3 Hardware Extensions 6.3.1 The Piface interface card The Piface Interface card is an I/O Extension which offers 8 Inputs and 8 Outputs. You can buy the card from the sales partners of Farnell/Element14. The card has two relais for switching currents up to 5 Ampere and a maximum Voltage of 20 Volt. According to the printing on the relais the switching of 220 V AC should be possible - at your own risk. The 8 inputs can take Voltages from 0-5 Volt. Four of these Inputs are wired to Switches. The 8 outputs are driven by a ULN2803 transistor array. Each output can switch currents up to 500 mA and a maximum voltage of 50 Volt. A getting started guide is available at Element14: http://www.element14.com/community/docs/DOC-52896/l/piface-get-started-guide-feb-2013 You can find a schematic drawing here: http://piface.openlx.org.uk/kernel-driver-delays-and-new-interface-board Raspbian can be used for operating the Piface card. For controlling the interface the SPI (Serial Peripheral Interface Bus) drivers are required. These must be activated. You find details in the above referenced getting started guide. Datasheets of the two IC's on the board: ULN2803A: http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/DAT ASHEET/CD00000179.pdf SPI I/O Chip MCP23S17SP: http://ww1.microchip.com/downloads/en/DeviceDoc/21952b.pdf Seite 27 / 40 Contact: peba@inode.at Edition 2
6.4 Report Linux bugs If you use the RPI and install a lot of hardware and software packages, you can easily discover an error. Depending on the Linux distribution, there are several ways to report the error. Before writing a bug report it is good to investigate whether this error may have been reported by of another user. Important: Only known errors can be corrected, so do not be shy when writing error messages. Debian: Error Database: http://www.debian.org/Bugs/ Program for writing Error report: reportbug Raspbian: Error Database: https://bugs.launchpad.net/raspbian Report an Error: Raspberry Pi Forum in section Raspbian and on IRC Archlinux: Error Database: https://bugs.archlinux.org/ Report an Error: register with the error database and login It is possible to request features in the form of an error message. It is also useful to report errors in the documentation (e.g. man pages are sometimes incomplete). Seite 28 / 40 Contact: peba@inode.at Edition 2
6.5 Diagnosis of hard- and software problems in Linux This chapter uses the CLI (Command Line Interface) of Linux, also known as shell as the basis for the examples given. You can follow the examples in a terminal (LXTerminal). The following example uses the text editor nano to be explored as a faulty program. The following examples are assuming that the program to be examined is compiled to something executable and is not interpreted (perl, python, ruby, ...) program. The diagnosis of interpreted programs is easy to accomplish with the tools of the language. When you start a Linux program, first the search path is scanned for the name of the program entered. With the tool "which" you can display the exact place where a program is located. For example which nano displays "/usr/bin/nano" - now you found the place where the program is stored on the storage media. With the commad man nano and info nano you can read the documentation of the program and possibly find hints for solving problems. Most linux programs offer a wealth of optional parameters which can be used to adapt the program to your needs. By using the commd strace you can track the system calls of a program and pursue startup issues and the further execution of the program. Strace with the -p option can attach to a running process when you specify the PID (process ID). With pidof you can get the process ID of a running program. To follow this example, you must start multiple terminal windows with one window running the program under investigation. The -o option causes the strace outputs to be saved in a file instead of being displayed on the screen. This is useful if the program under test itself writes to the screen. With lsof -p you can see which files are used by a program. If a program hangs (stops responding to keystrokes) it can be stopped with kill -9 . This works under the condition that the user of the kill command has proper permissions, otherwise you get the error message that the operation is not allowed. The command ps -efw displays a list of all running processes on your system. If a USB device does not work, you can list all existing USB devices with lsusb. With the command dmesg, you can take a look at the kernel ring buffer. Here the diagnostic output of the Linux system since startup is displayed. pi@raspberrypi ~ $ lsusb Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp. Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. Bus 001 Device 004: ID 046d:c52e Logitech, Inc. Based on the USB device ID a search at Google will find out pretty quickly whether the unit operates principally under Linux or with a specific Linux kernel version, or if there are problems. You can always query your kernel version with the command uname-a. pi@raspberrypi ~ $ uname -a Linux raspberrypi 3.1.9-cutdown+ #167 PREEMPT Sat Jul 14 18:50:21 BST 2012 armv6l GNU/Linux Seite 29 / 40 Contact: peba@inode.at Edition 2
Here is the dmesg output when plugging in and subsequently plug out a USB RF dongle for the keyboard and mouse: pi@raspberrypi ~ $ dmesg [ 3060.829351] usb 1-1.2: USB disconnect, device number 4 /*abstecken [ 3073.101504] usb 1-1.2: new full speed USB device number 5 using dwc_otg /*anstecken [ 3073.204611] usb 1-1.2: New USB device found, idVendor=046d, idProduct=c52e [ 3073.204637] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=0 [ 3073.204653] usb 1-1.2: Product: USB Receiver [ 3073.204671] usb 1-1.2: Manufacturer: Logitech [ 3073.217444] input: Logitech USB Receiver as /devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1- 1.2:1.0/input/input2 [ 3073.217886] generic-usb 0003:046D:C52E.0003: input: USB HID v1.11 Keyboard [Logitech USB Receiver] on usb-bcm2708_usb-1.2/input0 [ 3073.241557] input: Logitech USB Receiver as /devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1- 1.2:1.1/input/input3 [ 3073.242602] generic-usb 0003:046D:C52E.0004: input,hiddev0: USB HID v1.11 Mouse [Logitech USB Receiver] on usb-bcm2708_usb-1.2/input1 By invoking sudo dmesg --clear the kernel ring buffer can be cleared. Seite 30 / 40 Contact: peba@inode.at Edition 2
6.5.1 Networking with WLAN For network connection via WLAN it must be noted that not all wireless sticks (USB WIFI adapter) are compatible with Linux and the RPI. A list of working WIFI sticks can be found at the website: http://elinux.org/RPi_VerifiedPeripherals#USB_WiFi_Adapters Some WLAN sticks have a high power consumption and can not function right on the RPI but only through a USB hub with its own power supply. To operate a WLAN stick a specific firmware respectively a software driver is needed. With your Linux distribution, it may well be that this software driver is not yet installed, and therefore must be installed manually. You will need access to the Internet for downloading this. This situation is not entirely hopeless - these software drivers can be downloaded with another computer. To find the appropriate driver for your wireless stick you have to plug it in to your RPI and examine the outputs in the kernel ring bufffer. command: dmesg /* invoke from a terminal dmesg | grep usb /* output filter by occurence of usb /* in most cases the manufacturer is visible By using apt-cache, you can search the software packages from Debian or Raspbian for drivers and firmware and install these with apt-get install. pi@raspberrypi:~$ apt-cache search firmware | grep -i wireless linux-wlan-ng - utilities for wireless prism2 cards atmel-firmware - Firmware for Atmel at76c50x wireless networking chips. firmware-atheros - Binary firmware for Atheros wireless cards firmware-brcm80211 - Binary firmware for Broadcom 802.11 wireless cards firmware-ipw2x00 - Binary firmware for Intel Pro Wireless 2100, 2200 and 2915 firmware-iwlwifi - Binary firmware for Intel Wireless 3945, 4965 and 5000-series cards firmware-libertas - Binary firmware for Marvell Libertas 8xxx wireless cards firmware-ralink - Binary firmware for Ralink wireless cards firmware-realtek - Binary firmware for Realtek wired and wireless network adapters libertas-firmware - Firmware for Marvell's libertas wireless chip series (dummy package) zd1211-firmware - Firmware images for the zd1211rw wireless driver Seite 31 / 40 Contact: peba@inode.at Edition 2
In the case that you have to download the drivers or firmware with another computer: With the help of a Google search request, it is possible to assign a suitable driver manufacturers and the software packages to find as a *. Deb file. By the use of the command sudo dpkg-i *. The appropriate package will be installed on your RPI. If the right software packages can not be found on the Internet it is recommended to ask other users or developers, for example via email or IRC. By the use of: sudo iwlist scan You can list all existing WLAN networks. By the use of: sudo iwconfig You can display or set the WLAN configuration. A detailed description can be found here: http://elinux.org/RPi_Peripherals#Wireless:_TP-Link_TL- WN722N_USB_wireless_adapter_.28Debian_6.29 Seite 32 / 40 Contact: peba@inode.at Edition 2
6.6 Using Raspbmc as operating system Go to the website http://www.raspbmc.com/download/ and follow the instructions for your operating system. After creating the flash card, insert the card into your RPI, which must be connected to the Internet to complete the installation. After booting, the RPI contacts the Raspbmc update location and loads the root file system (OS) from there. This process may take, depending on the speed of the internet connection about 20 minutes. After completion of the download the root file system will be installed. The Raspbmc installation software invites you to take a coffee. Thereafter the current version of the XBMC program is downloaded and installed. This XBMC Media Center will automatically start and the various sources for playing music and videos can be configured via the graphical user interface. If you have purchased licenses for video codecs, it is now time to make them known to the RPI. For this purpose, you can login with username "pi" and password "raspberry" by using Secure Shell. At first login via ssh the language - and international settings are configured. Now you can add your licence key to the file /boot/config.txt. sudo nano /boot/config.txt Example for a key entry: decode_MPG2=0x12345678 Seite 33 / 40 Contact: peba@inode.at Edition 2
6.7 Using Archlinux ARM as operating system Archlinux is a slightly larger puzzle than Debian. In its basic configuration it comes without a graphical interface and there is no dialogue for various settings. The installation on the flash card is as described in sections 4.1 - 4.3. The advantage of Archlinux lies in the availability of newer versions of programs. Archlinux is suitable for experienced Linux users. Guides for Archlinux: http://elinux.org/ArchLinux_Install_Guide The first step should be to update the distribution, for this there must be a working internet connection. # pacman-key --init /* generate pacman key # pacman -Syu /* update ditribution Create a standard user account: # useradd # pacman -sS searchstring /* list available program packages # pacman -S program-name /* Install programs of your choice Seite 34 / 40 Contact: peba@inode.at Edition 2
6.8 Useful software applications 6.8.1 SSH server and SSH client Secure Shell is a protocol for secure data transmission. Using SSH, it is possible to administer your RPI from far away. There is a login shell and a secure file transfer using SCP (secure copy). Using X11 forwarding also graphical applications are displayed on the client, if there exists an X server. SSH server is pre installed in Raspbian and Debian, Ubuntu and other Linux distributions have an SSH client pre installed. The SSH server on the RPI can be activated or deactivated by means of the script raspi- config. If you want to access your RPI using SSH from the Internet, you need to enable port forwarding on your modem or router to the IP address of your RPI and the TCP port 22 (SSH). For Windows the following tools are recommended: • Putty - SSH client, Putty is available for Linux too • WinSCP - SCP client with GUI • XMing - X Server for Windows Putty SSH Client The login on the SSH server is done with username and password. By the use of sudo it is possible to invoke commands with root rights remotely. In principle a direct login as root user would be possible. Please take care to choose a secure password. Seite 35 / 40 Contact: peba@inode.at Edition 2
6.8.2 Filesharing with SAMBA SAMBA provides a Windows compatible file and printer sharing system. Therefore, it is quite convenient to use when you want to access volumes of the RPI over the network. Install software packages on Debian or Raspbian: sudo apt-get install samba samba-common configure SAMBA: sudo nano /etc/samba/smb.conf It is very helpful to make a copy of smb.conf, since small typos in this file may lead to strange errors. As an example here is a section of a smb.conf file for a public fileshare named "myshare". The folder /share must be present in the RPI root folder with appropriate access rights. drwxrwxr-x 2 nobody nogroup 4096 Sep 27 19:11 share In the default configuration the SAMBA server works with the privileges of the user nobody, that is, for reasons of safety. When files are copied to the SAMBA share, they get the file permissions for the user nobody. In section [global] of smb.conf: security = share At the end of smb.conf: #example public share [myshare] comment = Samba server's folder writeable = yes path = /share guest ok = yes After changes in the configuration the SAMBA server needs to be restarted. sudo /etc/init.d/samba restart A more in depth guide can be found here: http://elinux.org/R-Pi_NAS Here it is described how different SAMBA users can be created. This can be used to authenticate the user by username and password. With the command smbstatus the SAMBA connection state can be displayed. Seite 36 / 40 Contact: peba@inode.at Edition 2
6.8.3 Remote Control of the RPI desktop via VNC Using VNC (Virtual Network Computing), the desktop of the RPI can displayed and operated on a remote screen. This requires a VNC server program to be installed and started on the RPI. For the transmission of the data the RFB (remote framebuffer) protocol is used. Attention: The transfer of the data and also the login sequence is not encrypted. Installation of VNC server on the RPI: sudo apt-get install tightvncserver Start of the VNC server on the RPI: vncserver :1 -geometry 1280x768 -depth 24 pi@raspberrypi ~ $ vncserver :1 -geometry 1280x768 -depth 24 New 'X' desktop is raspberrypi:1 Starting applications specified in /home/pi/.vnc/xstartup Log file is /home/pi/.vnc/raspberrypi:1.log The VNC server usually listens on Port 5901 for incoming connections. With the lsof command this can be checked. pi@raspberrypi ~ $ lsof -i COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME Xtightvnc 15897 pi 0u IPv4 33624 0t0 TCP *:x11-1 (LISTEN) Xtightvnc 15897 pi 3u IPv4 33626 0t0 TCP *:5901 (LISTEN) To quit the VNC server: vncserver -kill :1 For the PC several VNC clients also called viewers exist: • for Linux the VNC client vinagre is recommended • for Windows there is Tightvnc and RealVNC • for Mac OS X there is also RealVNC An in depth guide can be found here: http://elinux.org/RPi_VNC_Server Seite 37 / 40 Contact: peba@inode.at Edition 2
6.8.4 File server with ftpd An FTP file server provides a way to access files on the RPI over the Internet. There is a FTP client on almost any computer. A web browser can also be used as a FTP client. To use the web browser to access a FTP server you simply use "ftp:// " as the URL. Installation: sudo apt-get install ftpd The FTP server listens on TCP port 21 for incoming connections. The login can be done with any valid user account on the RPI. So for example user: pi, and the password. A good password should be at least 6 characters and contain lower and uppercase characters as well special characters. Drawback of the FTP protocol: It is not encrypted. Even the login is transmitted in clear text. By the use of SSH (see 6.7.1) a secure login and encrypted data transmission is possible. Configuration of the ftpd: /etc/ftpusers This file contains the users which are not allowed to use FTP. # /etc/ftpusers: list of users disallowed ftp access. See ftpusers(5). root ftp anonymous /etc/ftpwelcome This file may contain a welcome message. Further information can be found in the man pages. man ftpd Seite 38 / 40 Contact: peba@inode.at Edition 2
6.8.4 Web Server with Lighttpd A sleek and powerful WEB server is available with the package lighttpd under Raspbian and Debian Linux. A complete description of this WEB server would fill an entire book. Lighttpd Web site: http://www.lighttpd.net/ Installation: sudo apt-get install lighttpd After installation, the web server is started automatically and is accessible on port 80 and a sample website. The default setting for the document-root directory (this is the place where your html pages should be) is the location /var/www/. stop the server: sudo /etc/init.d/lighttpd stop start or restart the server: sudo /etc/init.d/lighttpd start oder restart Configuration: the configuration files are located in the folder /etc/lighttpd The Lighttpd server is modular, which means for different features, different modules are loaded. Some modules of the server loads automatically at startup however. An example is the module mod_dirlisting. This module allows the viewing and browsing of a directory using a web browser. In order to enable your dir listing only one additional entry in the file lighttpd.conf is necessary. The dir listing function works if there is no index. *.html file available. Rename he sample page of your Web server to index.bak. dir-listing.activate = "enabled" /* configuration entry After Restarting the Web server the Web page looks like this: Seite 39 / 40 Contact: peba@inode.at Edition 2
7. Resources for the Raspberry Pi on the Internet http://www.raspberrypi.org/ The Homepage of the Raspberry Pi Foundation http://elinux.org/R-Pi_Hub RPI Wiki in several languages http://elinux.org/RPi_VerifiedPeripherals working Hardware http://www.element14.com/community/groups/raspberry-pi Datasheets and more http://www.raspbian.org/ Linux variant optimized for the RPI http://www.raspbmc.com Linux variant for multimedia http://rastrack.ryanteck.org.uk/ The RPI Tracker, where is already an RPI ? http://www.themagpi.com/ monthly Magazin IRC channels: Chat with the developers #raspberrypi, #raspbian Seite 40 / 40 Contact: peba@inode.at Edition 2
You can also read