2. RASPBERRY PI TECHNICAL DOCUMENTATION
INDEX
1. Raspberry Pi Specifications 1
2. Raspberry Pi OS Installation 7
2.1.SD Formatter 7
2.2.Win32DiskImager 8
2.3.Advanced IP Scanner 9
2.4.PuTTY 10
2.5.Remote Desktop Connection 10
3. How to Setup A Raspberry Pi Without A Monitor or Keyboard 11
4. Establish An SSH Connection To Your Raspberry Pi 16
5. How To Access The Raspberry Pi GUI With A Remote Desktop Connection 19
6. Raspberry Pi Configuration 22
7. Raspberry Pi Package Installation 23
7.1.wiringPi Package 23
7.2.Python Installation 24
7.3.Geany IDE Installation 24
7.4.QT IDE Installation 26
8. Raspberry Pi Technical Commands 34
8.1.Auto Login 34
8.2.Auto Start Program in Desktop 34
8.3.Auto Start Program on Boot 34
3. 8.4.Access Terminal on Boot 35
8.5.Wi-Fi Setup 36
8.6.Raspberry Pi Configuration 37
8.7.Remote Access (ssh) 37
8.8.Show IP Address 38
8.9.Static IP Address 38
8.10. Restart and Shutdown 38
8.11. Clean Screen 39
8.12. Terminate Program 39
8.13. Force Quit 39
8.14. Update & Upgrade Software 40
8.15. Raspberry Pi Camera 40
8.16. USB Camera 42
9. Raspberry Pi Example Programs 42
4. 4
1. Raspberry pi 2 Model B Specifications:
The Raspberry Pi is a credit-card sized computer that plugs into your TV and a
keyboard. It is a capable little computer which can be used in electronics projects, and
for many of the things that your desktop PC does, like spreadsheets, word-processing,
browsing the internet and games. It also plays high-definition video. We want to see it
being used by kids all over the world to learn programming.
The Raspberry Pi 2 Model B features Broadcom BCM2836 ARMv7 Quad Core
Processor running at 900MHz. The board now features 1GB RAM which makes it now
runs more powerful applications. The board is capable of streaming High definition
video output at 1080p resolution.
5. 5
Features:
Broadcom BCM2836 900MHz Quad Core ARM Cortex-A7 CPU
1GB RAM
4 USB ports
40 GPIO pins
Full HDMI port
Ethernet port
Combined 3.5mm audio jack and composite video
Camera interface (CSI)
Display interface (DSI)
Micro SD card slot
Video Core IV 3D graphics core
Kit Contents:
Raspberry Pi Board
Clear Acrylic case
SanDisk 8 GB SD Card Class 10 with NOOBS preinstalled
5 Volt 2 Ampere Power Supply
CAT 5E Network Patch LAN cable
HDMI Cable
Quick Start Guide
A brief description of the components on the Pi.
1) Processor / SoC (System on Chip)
The Raspberry Pi has a Broadcom BCM2835 System on Chip module. It has an
ARM1176JZF-S processor.
The Broadcom SoC used in the Raspberry Pi is equivalent to a chip used in an old
Smartphone (Android or iPhone). While operating at 700 MHz by default, the Raspberry
Pi provides a real world performance roughly equivalent to the 0.041 GFLOPS. On the
6. 6
CPU level the performance is similar to a 300 MHz Pentium II of 1997-1999, but the
GPU, however, provides 1 Gpixel/s, 1.5 Gtexel/s or 24 GFLOPS of general purpose
compute and the graphics capabilities of the Raspberry Pi are roughly equivalent to the
level of performance of the Xbox of 2001. The Raspberry Pi chip operating at 700 MHz
by default, will not become hot enough to need a heat sink or special cooling.
2) Power source
The Pi is a device which consumes 700mA or 3W or power. It is powered by a Micro
USB charger or the GPIO header. Any good Smartphone charger will do the work of
powering the Pi.
3) SD Card
The Raspberry Pi does not have any onboard storage available. The operating system is
loaded on a SD card which is inserted on the SD card slot on the Raspberry Pi. The
operating system can be loaded on the card using a card reader on any computer.
4) GPIO
GPIO – General Purpose Input Output
General-purpose input/output (GPIO) is a generic pin on an integrated circuit whose
behaviour, including whether it is an input or output pin, can be controlled by the user at
run time.
GPIO pins have no special purpose defined, and go unused by default. The idea is that
sometimes the system designer building a full system that uses the chip might find it
useful to have a handful of additional digital control lines, and having these available
from the chip can save the hassle of having to arrange additional circuitry to provide
them.
GPIO capabilities may include:
GPIO pins can be configured to be input or output
GPIO pins can be enabled/disabled
7. 7
Input values are readable (typically high=1, low=0)
Output values are writable/readable
Input values can often be used as IRQs (typically for wakeup events)
The production Raspberry Pi board has a 40-pin 2.54 mm (100 mil) expansion
header, marked as P1, arranged in a 2x13 strip. They provide 8 GPIO pins plus access to
I²C, SPI, UART), as well as +3.3 V, +5 V and GND supply lines. Pin one is the pin in the
first column and on the bottom row.
8. 8
Figure 6: GPIO connector on RPi
5) DSI Connector
The Display Serial Interface (DSI) is a specification by the Mobile Industry Processor
Interface (MIPI) Alliance aimed at reducing the cost of display controllers in a mobile
device. It is commonly targeted at LCD and similar display technologies. It defines a
9. 9
serial bus and a communication protocol between the host (source of the image data) and
the device (destination of the image data).
A DSI compatible LCD screen can be connected through the DSI connector, although it
may require additional drivers to drive the display.
6) RCA Video
RCA Video outputs (PAL and NTSC) are available on all models of Raspberry Pi. Any
television or screen with a RCA jack can be connected with the RPi.
Figure 7: RCA Video Connector
7) Audio Jack
A standard 3.5 mm TRS connector is available on the RPi for stereo audio output. Any
headphone or 3.5mm audio cable can be connected directly. Although this jack cannot be
used for taking audio input, USB mics or USB sound cards can be used.
8) Status LEDs
There are 5 status LEDs on the RPi that show the status of various activities as follows:
“OK” - SDCard Access (via GPIO16) - labelled as "OK" on Model B Rev1.0 boards and
"ACT" on Model B Rev2.0 and Model A boards
“POWER” - 3.3 V Power - labelled as "PWR" on all boards
“FDX” - Full Duplex (LAN) (Model B) - labelled as "FDX" on all boards
“LNK” - Link/Activity (LAN) (Model B) - labelled as "LNK" on all boards
“10M/100” - 10/100Mbit (LAN) (Model B) - labelled (incorrectly) as "10M" on Model B
Rev1.0 boards and "100" on Model B Rev2.0 and Model A boards
10. 10
Figure 8: Status LEDs
9) USB 2.0 Port
USB 2.0 ports are the means to connect accessories such as mouse or keyboard to the
Raspberry Pi. There is 1 port on Model A, 2 on Model B and 4 on Model B+. The
number of ports can be increased by using an external powered USB hub which is
available as a standard Pi accessory.
10) Ethernet
Ethernet port is available on Model B and B+. It can be connected to a network or
internet using a standard LAN cable on the Ethernet port. The Ethernet ports are
controlled by Microchip LAN9512 LAN controller chip.
11) CSI connector
CSI – Camera Serial Interface is a serial interface designed by MIPI (Mobile Industry
Processor Interface) alliance aimed at interfacing digital cameras with a mobile
processor.
The RPi foundation provides a camera specially made for the Pi which can be connected
with the Pi using the CSI connector.
12) . JTAG headers
JTAG is an acronym for „Joint Test Action Group', an organisation that started back in
the mid 1980's to address test point access issues on PCB with surface mount devices.
The organisation devised a method of access to device pins via a serial port that became
11. 11
known as the TAP (Test Access Port). In 1990 the method became a recognised
international standard (IEEE Std 1149.1). Many thousands of devices now include this
standardised port as a feature to allow test and design engineers to access pins.
13) HDMI
HDMI – High Definition Multimedia Interface. HDMI 1.3 a type a port is provided
on the RPi to connect with HDMI screens.
2. Raspberry Pi OS Installation
1) SD Formatter
This software formats all SD memory cards, SDHC memory cards and SDXC
memory cards. SD Formatter provides quick and easy access to the full capabilities of
your SD, SDHC and SDXC memory cards.
The SD Formatter was created specifically for memory cards using the
SD/SDHC/SDXC standards. It is strongly recommended to use the SD Formatter instead
of formatting utilities provided with operating systems that format various types of
storage media. Using generic formatting utilities may result in less than optimal
performance for your memory cards.
The SD/SDHC/SDXC memory cards have a "Protected Area" on the card for the SD
standard's security function. The SD Formatter does not format the "Protected Area".
Please use appropriate application software or SD-compatible device that provides SD
security function to format the "Protected Area" in the memory card.
12. 12
2) Win32Disk Imager
Win32 Disk Imager is a simple open source application that writes CD or DVD
image files to a USB or SD card, creating a virtual disk drive.
Just unzip the program (no installation required), select the image you want to create
from your hard drive and finally the device where you want it written to, and that's it, in a
few seconds your pen drive or your memory card will become a virtual CD.
13. 13
3) Advanced IP Scanner
Reliable and free network scanner to analyses LAN. The program shows all
network devices, gives you access to shared folders and FTP servers, provides remote
control of computers (via RDP and Radmin), and can even remotely switch computers
off. It is easy to use and runs as a portable edition. It should be the first choice for every
network admin.
Advanced IP Scanner is a free, fast and powerful network scanner with a user-
friendly interface. In a matter of seconds, Advanced IP Scanner can locate all the
computers on your wired or wireless local network and conduct a scan of their ports. The
program provides easy access to various network resources, such as HTTP, HTTPS, FTP
and shared folders. It also enables you to detect all the IP addresses on your Wi-Fi
network.
14. 14
4) Putty
PuTTY is an SSH and telnet client, developed originally by Simon Tatham for the
Windows platform. PuTTY is open source software that is available with source code and
is developed and supported by a group of volunteers.
15. 15
5) Remote Desktop Connection
With Remote Desktop Connection, you can connect to a computer running
Windows from another computer running Windows that's connected to the same network
or to the Internet. For example, you can use all of your work computer's programs, files,
and network resources from your home computer, and it's just like you're sitting in front
of your computer at work.
To connect to a remote computer, that computer must be turned on, it must have a
network connection, Remote Desktop must be enabled, you must have network access to
the remote computer (this could be through the Internet), and you must have permission
to connect. For permission to connect, you must be on the list of users. Before you start a
connection, it's a good idea to look up the name of the computer you're connecting to and
to make sure Remote Desktop connections are allowed through its firewall.
16. 16
3. How to Setup a Raspberry Pi without a Monitor or Keyboard:
The Raspberry Pi is lots of fun to experiment with and will teach you a lot about
computers. I think anyone interested in learning about computers or the internet should
have one. The only obstacle with the Raspberry Pi is that it doesn‟t come with a monitor
or keyboard. You can connect an external monitor to it, but many people choose to run it
“headless”. Headless means we can operate it without the keyboard and monitor us are
17. 17
used to having on most computers. This is all very easy to do, even if you have never
booted your Raspberry Pi. You don‟t need a monitor and keyboard to use your Raspberry
Pi. All you need is another computer with internet access and an SD card reader, an
Ethernet cable, and access to your router to plug in the Ethernet cable.
I will explain how to set up your Raspberry Pi for the first time without a monitor
and keyboard. We will use a remote SSH connection to access the command prompt of
the Pi to do the initial set up and install the packages for a desktop interface (GUI). After
we we boot up the Pi for the first time, we will be able to configure it to run from the
command prompt or the desktop via a remote desktop application.
Gather all the Pieces
The first step is to download Raspbian, the operating system which I will be using in this
tutorial.
Just download the ZIP file, and Extract it to a new folder on your Mac or PC. You will
now have a single .img image file containing the Raspbian operating system:
18. 18
Next, we will need a program that can write the Raspbian operating system image file
onto an SD or microSD card. Win32DiskImager will do this, so download and install it to
your Mac or PC.
Now, we will need a way to access the command prompt of our Raspberry Pi over our
home internet connection. We can do this with a remote SSH client called PuTTY. SSH
(Secure Shell) is a network protocol for secure data communication, remote command-
line login, remote command execution, and other secure network services between two
networked computers. PuTTY establishes an SSH connection from our home computer to
our Raspberry Pi. PuTTY will display the command prompt of the Raspberry Pi on the
computer in which it is installed. All we need to do is to give it the local IP address of the
Raspberry Pi. Download and install PuTTY to your PC. If you are using a Mac, you can
just use Terminal, click here for good tutorial on SSH via Terminal.
19. 19
We will also need a way to find the local IP address of your Raspberry Pi once it is
connected to the router via the ethernet cable. There are many ways to do this, but one
very simple way is to use Advanced IP Scanner. With this program, you can scan your
home network (i.e. your home WiFi) and find out the local IP addresses of all devices
connected to your home network.
Another way is to log into your router‟s configuration page to list all the connected
devices, but this method is not always possible if you don‟t have access to the router‟s
username and password. To do this, look for the product number on the back of the
router, and search online for the user manual for it. There will be instructions on how to
access the router‟s configuration page and how to view the connected devices.
Write the Raspbian Operating System to the SD/micro SD Card
Now we are ready to write the Raspbian OS to our SD/micro SD card. Open
Win32DiskImager, and select the Raspbian image file that was extracted earlier by
clicking on the little file icon to the right of the large text field:
20. 20
Next, select the drive letter that the SD/micro SD card is inserted into from the drop-
down list below “Device.”
Now, click “Write” on the bottom of the window. The write process will take from 1 to
15 minutes depending on your computer and the size of your SD/microSD card:
Wait for the process to complete, then eject the SD/micro SD card from your computer
and insert it into the Raspberry Pi.
21. 21
Now you are ready to power up the Raspberry Pi. Plug the power cord into the Raspberry
Pi, and connect the Pi to your router via the Ethernet cable.
4. Establish an SSH Connection to your Raspberry Pi
In order to access the Raspberry Pi via remote SSH, we need to know the local IP address
your router has given to it. If you are able to access this information from your router‟s
configuration menu, go ahead and do it. If not, use Advanced IP Scanner to scan your
home network and generate a list of all connected devices and their local IP addresses.
Just click “Scan” in the upper left hand area of the window, and a list of all connected
devices will be generated with their associated local IP addresses:
Write down the IP address for the device that says Raspberry Pi Foundation in the
“Manufacturer” column. In my case it is 10.0.0.105. We will need the local IP address to
establish an SSH connection from our home computer to the Raspberry Pi.
Now we can set up our SSH connection to the Raspberry Pi with our SSH client, PuTTY.
Open up PuTTY, and enter the local IP address of the Raspberry Pi into the “Host Name
(or IP address)” field. Don‟t worry about the port for now, keep it as is:
22. 22
After you have entered the local IP address of your Raspberry Pi, click “Open” to initiate
the connection. On the first connection attempt, an error message will appear, but press
yes anyway since you are connecting to your own Raspberry Pi so the security risk is
minimal here:
If the SSH connection is successful you will now be greeted with the login prompt of
your Raspberry Pi:
23. 23
If this is your first login, and you have not changed the username or password, type
type pi here, then press Enter. Next, enter raspberry as the password. You are now logged
in to your Raspberry Pi‟s command prompt via an SSH connection:
At this point, it‟s a good idea to configure your Raspberry Pi by entering sudo raspi-
config to enter the configuration settings menu:
This is where you can change all of the default settings for Raspbian, and do other useful
tasks like expand the file system and over clock the processor. I explain all of the
24. 24
different configuration settings in a separate post, but for now, let‟s continue setting up
your Raspberry Pi so that you can operate it heedlessly via a remote desktop application
5. How to Access the Raspberry Pi GUI with a Remote Desktop
Connection:
Sometimes it‟s not practical to have a monitor and keyboard attached to your Raspberry
PI. This is a quick guide to setting up your PI to allow windows to use Remote Desktop
to connect to your PI. This guide is the result of the Blooming labs Raspberry Pi and
Adafruit Build Nights.
Step 1: What is needed?
A Raspberry Pi (any version should work)
Ethernet cable or WIFI adapter to connect to your network
Keyboard, Video Monitor, and Mouse to setup the software
A computer running Windows used to connect to your Raspberry Pi
25. 25
Step 2: Installing XRDP server
Open LXTerminal.
enter "sudo apt-get update" to get the most current list of packages
enter "sudo apt-get install xrdp" to install the server
enter "sudo reboot" to restart your system
XRDP will now automatically run whenever your Raspberry Pi is running.
26. 26
Step 3: Find your IP
Open LXterminal on your Raspberry Pi
Type "ifconfig"
The green line shows where to find your IP address. Write this down and save it for later.
(The red line is to hide the MAC address on the Pi I was using for the demo)
Step 4: Connect to your Raspberry Pi
In Windows, open the Remote Desktop Client.
You will find it under:
Start Menu -> All Programs -> Accessories -> Remote Desktop Connection.
27. 27
Enter the IP address from the previous step.
Step 5: Login to your Raspberry Pi
Enter your username and password as you normally would.
After a brief loading window, you will have your Raspberry Pi desktop just as if you
were in front of it with a monitor and keyboard.
6. Raspberry Pi Configuration
1) First find out Raspberry Pi IP address using advanced IP scanner
2) Second open PuTTY Configuration
i. Host Name/IP : Raspberry Pi IP address (Ex. 192.168.1.4)
ii. Port No : 22
3) Automatically open Raspberry Pi Terminal
i. Login : pi
ii. Password : raspberry
4) Next install XPDP connection for Remote Desktop connection, enter bellow
command.
sudo apt-get install xrdp
28. 28
5) Open Remote Desktop Connection, enter Raspberry Pi IP address
6) Next step, ones again enter login and password
7) Now enter below command for Raspberry Pi OS desktop
startx
8) Now open LX Terminal for Raspberry Pi Configuration, enter bellow command
sudo raspi-config
9) Next update & upgrade Raspberry Pi OS, enter bellow command
sudo apt-get update & sudo apt-get upgrade
7. Raspberry pi package installation
1) WiringPi Package
sudo apt-get install git-core
sudo apt-get update
sudo apt-get upgrade
git clone git://git.drogon.net/wiringPi
cd wiringPi/
ls
git pull origin
../build
Example Program:
ls
mkdir mycode
cd examples/
29. 29
cp blink.c ../mycode/
cd ..
cd mycode/
ls
nano blink.c
Save the file, Ctrl + O
Close the editor, Ctrl + X, Y, Enter
gcc blink.c -o blink -l wiringPi
sudo ./blink
2) Python Installation
sudo apt-get install idle
sudo apt-get install python-pip
sudo apt-get install python-rpi.gpio OR sudo apt-get install python-gpio
sudo apt-get install python-serial
3) Geany IDE Installation (Compiler)
sudo apt-get update
sudo apt-get install geany
…with C and WiringPi
Let‟s recreate our WiringPi Example with Geany. Open the “blinker.c” created earlier
within the confines of Geany. You should immediately be presented with some very
pleasant color-coding.
30. 30
Before trying to compile the code, though, you‟ll need to tweak some of the build
options. Go up to Build and Set Build Commands. Inside the “Compile” and “Build”
text blocks, tack this on to the end of the default command:-l wiringPi. That will load the
wiringPi library.
31. 31
While you‟re here, add “sudo” to the beginning of your execute command. Make
sure your build commands look like the window above and click “OK”.
Once you‟ve adjusted that setting, you should be ready to go. Click
the Build menu, then click Build (or click the red cinder-block-looking icon up top).
Upon building, the IDE will switch focus to the bottom “Compiler” tab, and relay the
results of your compilation. If the build was successful, go ahead and run with it.
To run your built file, click Build > Execute (or click the gear icon up top).
Executing will bring up a new terminal window, and start your program running. You can
stop the program by pressing CTRL+C in the terminal window.
…with Python
You can also use Geany with Python. To test it out, go ahead an open up the
“blinker.py” file we created earlier. As with the C file, you‟ll be greeted with some
pleasnt context highlighting.
No building required with Python! Once you‟re script is written, simply click the
“Execute” gear up top. Again, running will produce a separate terminal to pop up. To
exit, simply press CTRL+C.
32. 32
4) QT IDE Installation(Compiler and GUI Creation)
sudo apt-get update
sudo apt-get install qtcreator
I like to share how I setup Qt-creator, which is C/C++ Qt library IDE. It turned out that
this was much faster than Eclipse. I like to try it out a few days more for fun.
Once you installed the package, you can launch it with a command: qtcreator
You will see nice welcome page like screenshot above; you may need to setup PuTTY
with X11-forwarding if you are connected from MS-Windows.
If you came this far, it was a big one step but the default setup wouldn't let you create Qt
application as you expect. You need to change the setup. You will need to:
uninstall one of plug-ins, "Remote Linux",
set the path of gcc and gdb and
33. 33
set the path of qmake-qt4 for Desktop; not for Embedded Linux.
You can uninstall a plugin, "Remote Linux" from "About Plugins...", which is
under "Help" on the menu; this menu organization feels like Eclipse. Lol
You will find "Remote Linux" and you need to uncheck it and restart QtCreator.
You need to setup the path of gcc and gdb from "Options..." under "Tools" on menu.
34. 34
Go to "Build & Run" and click "Tool Chains" tab. Click "Add" and add "GCC". Fill up
the form: "Compiler path" and "Debugger".
The actual path of gcc and gdb may little differ but you can figure it out by a command
"whereis".
35. 35
Lastly you need to set the path of qmake-qt4. You can do it from the other tab,
"QtVersions". You will be able to find qmake_qt4 from the path, "/usr/bin/qmake-qt4"; I
believe it is installed while qtcreator is installed.
Make sure that you see "Desktop" on the bottom after you set the path of "qmake-qt4". If
it says "Embedded Linux", your plugin, "Remote Linux", hasn't been uninstalled yet.
All of setup process is done and let's create our first project.
Go to "File" on the menu and select "New File or Project".
36. 36
We are going to create the first "Qt Gui Application". It will ask the name of project and
where it should be stored. Fill them up and hit "Next" button.
You should be seeing "Desktop" on "Targets" step. If it shows only "Embedded Linux",
probably your plugin, "Remote Linux", is not removed yet. If it says, "No valid QT
version found.", your "QtVersion" setting went wrong.
37. 37
You may see "Desktop" and "Embedded Linux" both on the "Targets" step if you
uninstalled the plugin, "Remote Linux", and re-installed it, which is fine. But uncheck
"Embeded Linux" for now. You can click "Next" buttons on "Details" and "Summary"
steps.
You will see the first project default setup like screenshot above.
38. 38
You can execute the default program by clicking the green arrow button on bottom left. It
will show a progress bar that indicates compile progress.
39. 39
You will be able to see an empty window created by Qt library as the final result.
As I mentioned earlier, Qt Creator runs pretty fast on Raspberry Pi. I haven't tried
Debugging feature yet but it seems promising. It is not cross-compile and it makes whole
thing so much simpler compare to the other try of mine. Qt-Creator seems to be a
practically usable IDE on Raspberry Pi.
8. Raspberry Pi Technical Commands
1) Auto Login
$ sudo nano /etc/inittab
In that file, comment out this line by typing this symbol „#‟ before it:
1:2345:respawn:/sbin/getty 115200 tty1
Like so:
#1:2345:respawn:/sbin/getty 115200 tty1
And place this line under it:
1:2345:respawn:/bin/login -f pi tty1 </dev/tty1 >/dev/tty1 2>&1
Replacing “pi” with the user you want auto-logged in on power-up. Reboot the Pi, and
watch it auto-login.
2) Auto Start Program in Desktop
sudo nano /etc/rc.local
Scroll to the bottom and add the following above exit 0:
Su –l pi –c startx
(Where pi is the username you want to run X as)
40. 40
3) Auto Start Program on Boot
There are several ways to start a program on boot. The best way depends on what your
program does.
Rc.local
Rc.local is a script that will run at the end of each multiuser runlevel.
$ sudo nano /etc/rc.local
Type in the file path your program at the end of the file before „exit 0‟:
/home/pi/myProgram.bin
Run Script file on Startup
Change the rights to a file so that it can run as a program.
$ sudo chmod +x filename
Cron
Cron is a program that let‟s you run programs at set times. E.g. at boot. To open the
Cron setup file:
$ sudo crontab -e
At the bottom of the file type:
@reboot /home/pi/myProgram &
To run several commands type „&&‟ between them:
@reboot sleep 60 && /home/pi/myProgram &
„Sleep 60‟ waits for 60 seconds before the program runs.
41. 41
Bash
This method starts your program when you enter the bash console. Also when
connecting wit ssh. Put your command at the bottom of „/home/pi/.bashrc‟. Can be
aborted with „ctrl-c‟ when program is running!:
$ sudo nano /home/pi/.bashrc
4) Access Terminal on Boot
If a program is started automatically with e.g. „/etc/rc.local‟, and you can‟t use „ctrl-c‟
to exit the running program, and you can‟t access the pi throughssh, samba, ftp or in
another way access the „/etc/rc.local‟ file, here is a little trick to solve the problem:
Take the sd card into another computer and edit the „cmdline.txt‟ file. At the end of the
line insert:
init=/bin/sh
Save the file, put it back into the pi and start it. After a shorter boot than normal, you
can access the command line. Edit the „/etc/rc.local‟:
$ sudo nano /etc/rc.local
When finished turn off the pi and put the sd card back into the other computer and
edit the „cmdline.txt‟ file again and remove „init=/bin/sh‟.
5) Wi-Fi Setup
& sudo nano /etc/network/interfaces
You will see something like this:
auto lo
iface lo inet looopback
iface eth0 inet dhcp
This is the setup of the Ethernet connection. Add this to enable wi-fi:
42. 42
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
Press “ctrl-x” to quit, choose “Y” to save. Now edit the wpa config:
& sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
It probably looks like this:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
Add this:
network={
ssid="YOURSSID"
psk="YOURPASSWORD"
# Protocol type can be: RSN (for WP2) and WPA (for WPA1)
proto=WPA
# Key management type can be: WPA-PSK or WPA-EAP (Pre-Shared or Enterprise)
key_mgmt=WPA-PSK
# Pairwise can be CCMP or TKIP (for WPA2 or WPA1)
airwise=TKIP
#Authorization option should be OPEN for both WPA1/WPA2 (in less commonly
used are SHARED and LEAP)
auth_alg=OPEN
}
Then “ctrl-x” to quit and “Y” to save. And do a reboot:
& sudo reboot
6) Raspberry Pi Configuration
Opens the default config screen for Raspberry Pi.
43. 43
& sudo raspi-config
Raspberry pi Config File
Edit the default Raspberry Pi config manually.
& sudo nano /boot/config.txt
7) Remote Access (ssh)
Enable SSH server in raspi-config under advanced options. Replace the ip address with
the pi‟s ip address. It is a -l (L) not -1 (one).
Login from terminal on OS X:
& ssh -l pi 192.168.1.1
8) Show IP Address
View the Raspberry Pi‟s ip address, multicast address and more.
& ifconfig
Shows only the ip address:
$ hostname –I
9) Static IP Address
How to set up static ip address.
& sudo nano /etc/network/interfaces
Replace
iface eth0 inet dhcp
with
iface eth0 inet static
address 192.168.100.1
44. 44
netmask 255.255.255.0
network 192.168.100.0
broadcast 192.168.100.255
gateway 192.168.100.254
Use your preferred addresses above.
10)Restart and Shutdown
Restart:
$ sudo reboot
Or (restart):
$ sudo shutdown -r now
11)Clear Screen
Type in terminal:
$ clear
12)Terminate Program
Ctrl-c
To termnitate a running program you are using, type „ctrl-c‟.
13)Force Quit
To force quit (kill) an application type:
$ sudo killall applicationName.bin
Or with PID number:
$ sudo kill -9 XXXXX
XXXXX is the PID for the process you want to kill. Can be found using the „top‟
command
45. 45
14)Update & Upgrade Software
Clean update cache
First clean your update cache list:
$ sudo apt-get clean
Update
To make sure you have the latest software, use apt-get update to make your source list of
software up to date:
$ sudo apt-get update
Upgrade
Then use apt-get upgrade to upgrade the software itself.
$ sudo apt-get upgrade
Firmware update
Type:
$ sudo rpi-update
15)Raspberry Pi Camera
First enable raspberry pi camera
sudo raspi-config
Next, install camera
sudo apt-get install raspistill
46. 46
Next, take image
raspistill -o image.jpg
Next, take video
sudo apt-get install raspivid
sudo apt-get update
sudo apt-get install python-picamera
Example Program 1:
import picamera
camera = picamera.PiCamera()
camera.capture('image.jpg')
Example Program 2:
import picamera
from time import sleep
camera = picamera.PiCamera()
camera.capture('image1.jpg')
sleep(5)
camera.capture('image2.jpg')
Example Program 3:
import time
import picamera
with picamera.PiCamera() as camera:
camera.start_preview()
time.sleep(0)
camera.capture('/home/pi/Desktop/image.jpg')
47. 47
camera.stop_preview()
16)USB Camera
Check if a USB Webcam is Compatible with Raspberry Pi
lsusb
Next, install web cam
sudo apt-get update
sudo apt-get install fswebcam
Next, take image
fswebcam image.jpg
SPECIFY RESOLUTION
fswebcam -r 1280x720 image2.jpg
SPECIFY NO BANNER
fswebcam -r 1280x720 --no-banner image3.jpg
9. Raspberry Pi Example Programs
WiringPi Programs
1) LED
#include<wiringPi.h>
int main (void)
{
wiringPiSetup () ;
48. 48
pinMode (0, OUTPUT) ;
while(1)
{
digitalWrite (0, HIGH) ;
delay (500) ;
digitalWrite (0, LOW) ;
delay (500) ;
}
return 0 ;
}
2) Switch
#include <wiringPi.h>
#include <stdio.h>
int main (void)
{
int pin_LED = 7; // GPIO7 / header pin 7
int pin_switch = 8; // SDA0 / header pin 3
int del = 250;
printf ("Raspberry Pi wiringPi button LED testn") ;
if (wiringPiSetup() == -1)
exit (1);
pinMode(pin_LED, OUTPUT);
pinMode(pin_switch, INPUT);
while(1)
{
if (digitalRead (8) == 0) // button pressed
{
del = 100;
49. 49
}
else
{
del = 250;
}
digitalWrite(pin_LED, 1);
delay(del);
digitalWrite(pin_LED, 0);
delay(del);
}
return 0 ;
}
3) LCD
#include <wiringPi.h> //WiringPi headers
#include <lcd.h> //LCD headers from WiringPi
#include <stdio.h> //Needed for the printf function below
//Pin numbers below are the WiringPi pin numbers
#define LCD_RS 3 //Register select pin
#define LCD_E 0 //Enable Pin
#define LCD_D4 6 //Data pin 4
#define LCD_D5 1 //Data pin 5
#define LCD_D6 5 //Data pin 6
#define LCD_D7 4 //Data pin 7
int main()
{
int lcd; //Handle for LCD
wiringPiSetup(); //Initialise WiringPi
50. 50
//Initialise LCD(int rows, int cols, int bits, int rs, int enable, int d0, int d1, int d2, int
d3, int d4, int d5, int d6, int d7)
if (lcd = lcdInit (2, 16,4, LCD_RS, LCD_E ,LCD_D4 , LCD_D5, LCD_D6, LCD_D7, 0,0,0,0))
{
printf ("lcdInit failed! n");
return -1 ;
}
lcdPosition(lcd,0,0); //Position first line in the first column
lcdPuts(lcd, "Character LCD"); //Print the text on the LCD at the current
cursor postion
getchar(); //Wait for key press
lcdClear(lcd); //Clear the display
}
4) DC Motor
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <wiringPi.h>
int EnableDisable=24; // WiringPi 24, physical 35, GPIO 19
int DirectionBit0=27; // WiringPi 27, physical 36, GPIO 16
int DirectionBit1=25; // WiringPi 25, physical 37, GPIO 26
int main (int argc, char *argv[])
{
wiringPiSetup();
// Set up pins to all OUTPUT
pinMode(EnableDisable,OUTPUT);
pinMode(DirectionBit0,OUTPUT);
pinMode(DirectionBit1,OUTPUT);
while(1)
{
// Forward
digitalWrite(EnableDisable,LOW);
52. 52
while True:
inputValue = GPIO.input(18)
if (inputValue == False):
print("Button press ")
time.sleep(0.3)
3) LCD
#!/usr/bin/python
import time #for timing delays
import RPi.GPIO as GPIO
#OUTPUTS: map GPIO to LCD lines
LCD_RS = 7 #GPIO7 = Pi pin 26
LCD_E = 8 #GPIO8 = Pi pin 24
LCD_D4 = 17 #GPIO17 = Pi pin 11
LCD_D5 = 18 #GPIO18 = Pi pin 12
LCD_D6 = 27 #GPIO21 = Pi pin 13
LCD_D7 = 22 #GPIO22 = Pi pin 15
OUTPUTS = [LCD_RS, LCD_E, LCD_D4, LCD_D5, LCD_D6, LCD_D7]
#HD44780 Controller Commands
CLEARDISPLAY = 0x01
SETCURSOR = 0x80
#Line Addresses. (Pick one. Comment out whichever doesn't apply)
#LINE = [0x00, 0x40, 0x14, 0x54] #for 20x4 display
LINE = [0x00,0x40] #for 16x2 display
# Low-level routines for configuring the LCD module.
# These routines contain GPIO read/write calls.
53. 53
def InitIO():
#Sets GPIO pins to input & output, as required by LCD board
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
for lcdLine in OUTPUTS:
GPIO.setup(lcdLine, GPIO.OUT)
for switch in INPUTS:
GPIO.setup(switch, GPIO.IN, pull_up_down=GPIO.PUD_UP)
def PulseEnableLine():
#Pulse the LCD Enable line; used for clocking in data
mSec = 0.0005 #use half-millisecond delay
time.sleep(mSec) #give time for inputs to settle
GPIO.output(LCD_E, GPIO.HIGH) #pulse E high
time.sleep(mSec)
GPIO.output(LCD_E, GPIO.LOW) #return E low
time.sleep(mSec) #wait before doing else
def SendNibble(data):
#sends upper 4 bits of data byte to LCD data pins D4-D7
GPIO.output(LCD_D4, bool(data & 0x10))
GPIO.output(LCD_D5, bool(data & 0x20))
GPIO.output(LCD_D6, bool(data & 0x40))
GPIO.output(LCD_D7, bool(data & 0x80))
def SendByte(data,charMode=False):
#send one byte to LCD controller
GPIO.output(LCD_RS,charMode) #set mode: command vs. char
SendNibble(data) #send upper bits first
PulseEnableLine() #pulse the enable line
data = (data & 0x0F)<< 4 #shift 4 bits to left
54. 54
SendNibble(data) #send lower bits now
PulseEnableLine() #pulse the enable line
def InitLCD():
#initialize the LCD controller & clear display
SendByte(0x33) #initialize
SendByte(0x32) #set to 4-bit mode
SendByte(0x28) #2 line, 5x7 matrix
SendByte(0x0C) #turn cursor off (0x0E to enable)
SendByte(0x06) #shift cursor right
SendByte(CLEARDISPLAY) #remove any stray characters on display
# Higher-level routines for displaying data on the LCD.
def SendChar(ch):
SendByte(ord(ch),True)
def ShowMessage(string):
#Send string of characters to display at current cursor position for character in
string:
SendChar(character)
def GotoLine(row):
#Moves cursor to the given row
#Expects row values 0-1 for 16x2 display; 0-3 for 20x4 display
addr = LINE[row]
SendByte(SETCURSOR+addr)
# Main Program
print "Pi LCD2 program starting. Ctrl-C to stop."
InitIO()
InitLCD()
55. 55
while (True):
GotoLine(1)
ShowMessage('Ganesh Reddy')
GotoLine(2)
ShowMessage(‘9951407307’)
time.sleep(0.2)
4) DC Motor
import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BOARD)
Motor1A = 16
Motor1B = 18
Motor1E = 22
GPIO.setup(Motor1A,GPIO.OUT)
GPIO.setup(Motor1B,GPIO.OUT)
GPIO.setup(Motor1E,GPIO.OUT)
print "Turning motor on"
GPIO.output(Motor1A,GPIO.HIGH)
GPIO.output(Motor1B,GPIO.LOW)
GPIO.output(Motor1E,GPIO.HIGH)
sleep(2)
print "Stopping motor"
GPIO.output(Motor1E,GPIO.LOW)
GPIO.cleanup()
5) Serial
56. 56
import serial
ser = serial.Serial ("/dev/ttyAMA0") #Open named port
ser.baudrate = 9600 #Set baud rate to 9600
data = ser.read(10) #Read ten characters from serial port to
data
ser.write(data) #Send back the received data
ser.close()