By default, Raspbian provides username: pi and password: raspberry.. In this chapter, we learn how to connect Raspberry Pi 3 to a network through built-inEthernet and WiFi... Raspberry P
Trang 44.3 Connecting to a Network
4.3.1 Connecting a Network via Ethernet 4.3.2 Connecting a Network via WiFi 4.4 Auto Connect to WiFi
Trang 56.4.1 Setting up 6.4.2 Pairing 6.4.3 Transferring File 6.5 Building your own iBeacon
Trang 7
This book was written to help anyone who wants to get started in Raspberry Pi 3 Itdescribes all the basic elements of the Raspberry Pi 3 with step-by-step approach
Agus Kurniawan
Berlin, March 2016
Trang 81 Introduction to Raspberry Pi 3
Trang 9The Raspberry Pi is a low cost, credit-card sized computer that plugs into a computermonitor or TV, and uses a standard keyboard and mouse
(source: https://www.raspberrypi.org/help/what-is-a-raspberry-pi/)
Built on the latest Broadcom 2837 ARMv8 64bit processor the new generation Raspberry
Pi 3 Model B is faster and more powerful than its predecessors It has improved powermanagement to support more powerful external USB devices and further to customerfeedback based development the new Raspberry Pi 3 now comes with built-in wireless andBluetooth connectivity
The following is technical specification of Raspberry Pi 3 device:
Broadcom BCM2837 64bit ARMv8 Quad Core Processor powered Single BoardComputer running at 1.2GHz
You can see Raspberry Pi 3 model B device on the Figure below
Trang 11After bought Raspberry Pi 3 from The Pi Hut (http://thepihut.com), I get the board asfollows
Trang 12This chapter explains how to work with Operating System for Raspberry Pi 3
Trang 13Raspberry Pi provides some Operating Systems you can use and run on the top ofRaspberry Pi 3 You can download these OS files on
http://www.raspberrypi.org/downloads
In this book, I use Raspbian “Jessie” OS
Trang 14Raspbian is an Operating system based on Debian Linux for the Raspberry Pi hardware Irecommend you to download OS image file on http://www.raspberrypi.org/downloads For illustration, I use Raspbian Jessie OS
jessie.img file
After extracted this file, you will obtain *.img file, for instance, 2016-02-26-raspbian-2.2.1 Setup MicroSD Card
If we are working with Raspberry Pi 3 board, we need MicroSD card to extract this OSimage file I use MicroSD Card 16 GB
Trang 15Wait it until done
Trang 17Download Win32DiskImager on https://sourceforge.net/projects/win32diskimager/ Run Win32DiskImager and navigate Raspberry Pi image file
Trang 18Now your Raspberry Pi 3 is ready to be deployed OS.
Trang 19In this chapter we start to run and configure Raspberry Pi 3
Trang 20Now you are ready to boot your Raspberry Pi Connect Monitor via HDMI, a keyboard viaUSB and power into Raspberry Pi
Turn on the power for your Raspberry Pi Raspbian OS will boot for the first time
If success, you will get the first screen of Raspberry Pi Jessie desktop as below
Trang 21On desktop mode, if you want to work with Terminal, you can click black monitor icon,shown in Figure below.
Trang 22After running Jessie OS, you can configure it by expanding Filesystem via raspi-config tooptimize your micro SD storage Type this command on Terminal
sudo raspi-config
Then, you get the following form
Select 1 Expand Filesystem After that, you are be required to restart Raspbian
Trang 24Select your Geographic area
Trang 25After that, Raspbian will configure your Timezone
Trang 28Select I3 Change Keyboard Layout Choose your keyboard type and model.
Trang 30It’s better to shutdown your Raspberry Pi If you don’t use it Please don’t turn off thepower directly
Write this script to shutdown and turn off your Raspberry Pi
$ sudo shutdown -h -P now
Trang 31By default, Raspbian provides username: pi and password: raspberry If you want tochange password, you can do it by calling passwd
$ passwd
Then type the current password and new password
Trang 33This chapter explains how to work with networking in Raspberry Pi 3
Trang 34In this chapter, we learn how to connect Raspberry Pi 3 to a network through built-inEthernet and WiFi
Let’s start
Trang 35Raspberry Pi 3 has built-in Ethernet and WiFi so we can connect to a network directly Wedon’t need additional network module
Trang 364.3.1 Connecting a Network via Ethernet
Connect Ethernet USB to Raspberry Pi and a network
Turn on Raspberry Pi 3 You can see the monitor and access it via Keyboard You alsoaccess it via SSH, read section 4.7
Select your SSID
Trang 37If succeed, WiFi icon will show on the right toolbar
Trang 38Then, you should get Network dialog
Trang 41Save all settings Now try to reboot Raspbian.
Trang 42By default, Raspberry Pi configures IP address in DHCP mode If you want to change tostatic IP Address, you edit interfaces file
Trang 43If your Raspberry Pi already connected to Internet, you can browse the Internet Raspberry
Pi provides Epiphany as browser Click its icon, shown in Figure below.
Furthermore, a browser is opened Navigate to a specific URL If success, it show thetarget URL A sample output of browser can be seen in Figure below
Trang 45By default, Raspbian Jessie has installed and enabled SSH service so we can use itdirectly
For testing, I used PuTTY, http://www.putty.org, application in Windows platform toremote Raspberry Pi via SSH
Fill IP Address of Raspberry Pi
You can get IP address your Raspberry Pi 3 board by checking it on your router Forinstance, my router detected my board MAC
Trang 46Pi hostname By default, the Pi hostname is raspberrypi.
Then, click Open button If connected, you will get a security alert.
Trang 48If you want to update your package repository, you can execute by writing this script
$ sudo apt-get update
Note: It needs the Internet connection
Trang 51If you success, you will get xrdp dialog Fill Raspberry Pi account
If done, you will get Raspbian desktop
Trang 52Fill IP address for your Raspberry Pi 3
Trang 53If succeed, you should see Jessie desktop
Trang 55This chapter explains how to work with development environment on Raspberry Pi 3
Trang 56In this section, we learn several programming on Jessie OS on Raspberry Pi 3
Trang 57Raspberry Pi Jessie provides Python for development by default so you can executePython code inside Raspberry Pi console
$ python
After that, you run Python command
Trang 58Raspberry Pi also provides GCC inside package distribution You can check your currentGCC version by typing this command
Trang 61If you are node.js lovers, Raspbian Jessie has installed for you.Try to check the node.js version
Trang 62Now you can execute mynode.js file using node.js
$ node mynode.js
Trang 64Scratch is a free desktop and online multimedia authoring tool that can be used by
students, scholars, teachers, and parents to easily create games and provide a steppingstone to the more advanced world of computer programming or even be used for a range
of educational and entertainment constructivist purposes from math and science projects,including simulations and visualizations of experiments, recording lectures with animatedpresentations, to social sciences animated stories, and interactive art and music
Trang 65Further information about Scratch, you can read and learn it on https://scratch.mit.edu/
Trang 66Now you can get Wolfram Mathematica for Raspberry Pi for free license You can findWolfram Mathematica on desktop
You can read how to use Wolfram Mathematica on this
site, http://www.wolfram.com/raspberry-pi/
I also wrote a book, Getting Started with Wolfram Language and Mathematica for
Trang 67Raspberry Pi You can reach it on http://blog.aguskurniawan.net/post/pimath.aspx
Trang 68Java also has installed on Raspbian Jessie You can verify it typing this command onTerminal
$ java -version
You should see Java version which installed on Raspberry Pi 3
Raspbian Jessie has BlueJ for Java IDE too
Trang 69public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World");
}
}
Trang 70$ javac HelloWorld.java
$ java HelloWorld
Program output:
Trang 72This chapter explains how to work with built-in Bluetooth on Raspberry Pi 3.
Trang 73In this chapter, we learn how to use built-in Bluetooth on Raspberry Pi 3 board Let’s start
Trang 76Now my Macbook detected Raspberry Pi Bluetooth.
Trang 78In this section, we want to pair my Macbook Bluetooth to Raspberry Pi Bluetooth
Firstly, I scan my Macbook Bluetooth using hcitool to retrieve MAC address of Macbook Bluetooth
Trang 79In this section, we learn to manage Raspberry Pi 3 Bluetooth using GUI, Bluetooth Manager
Let’s start
6.4.1 Setting up
Firstly, you run Raspbian Jessie in desktop mode You should see Bluetooth Manager on Preferences menu, shown in Figure below
If you don’t see it, Raspbian Jessie may not install blueman You can install it using this command on Raspberry Pi Terminal
Trang 81For example, Bluetooth Manager detected my Macbook Bluetooth
Trang 82Select Adaptors Next, you can select Always visible
6.4.2 Pairing
In this section, we learn how to pair Raspberry Pi Bluetooth to other Bluetooth device How to pair?
Open Bluetooth Manager Search and find Bluetooth device which you want to pair After found, select menu Device -> Pair
Trang 83You can select Random Passkey or Custom Passkey
On target Bluetooth machine, it should get notification for pairing
Trang 84Click Close if done
Trang 85On target Bluetooth, for instance, my Mackbook shown paired with Raspberry Pi Bluetooth
Trang 86After paired with other Bluetooth device, we can transfer a file In this scenario, I use Macbook I should configure my Bluetooth can receive a file
Trang 87On System Preferences, select Sharing.
Trang 88Now we send a file from Raspberry Pi Select Bluetooth icon, select Send Files to Device
Trang 89Choose a file
Trang 90On target machine, Macbook, I got a confirmation, shown in Figure below
Click Accept so you will get a file
Trang 91The last section, we try to build iBeacon using hcitool Firstly, we configure Bluetooth for iBeacon mode Type these commands
Trang 92$ sudo hcitool -i hci0 cmd 0x08 0x0008 1E 02 01 1A 1A FF 4C 00 02 15 63 6F 3F 8F 64 91 4B EE 95 F7 D8 CC 64 A8 63 B5 00 00 00 00 C8
It will generate iBeacon data
Trang 93On Beacon Scan application, it shows iBeacon data.
Trang 94This chapter explains how to deploy LAMP stack on Raspberry Pi 3 board.
Trang 96Firstly, we install Apache Server
$ sudo apt-get install apache2
Trang 97The second step is to install MySQL Execute this command
$ sudo apt-get install mysql-server
In the middle of installing process, you will be asked to fill root password for MySQL
Trang 98$ mysql version
Trang 101You need MySQL driver for PHP to access MySQL database Execute this command to install PHP-MySQL driver
$ sudo apt-get install php5 php5-mysql
Trang 104<p>List of database:</p>
<?php
$link = mysql_connect ('localhost', 'pi', 'raspberry');
$res = mysql_query ("SHOW DATABASES");
while ($row = mysql_fetch_assoc ($res)) {
Trang 105You test it now Open your browser and navigate to URL where hellodb.php file is
located
Trang 106This chapter explains how to work with GPIO on Raspberry Pi 3
Trang 107General-purpose input/output (GPIO) is a generic pin on an integrated circuit whosebehavior, including whether it is an input or output pin, can be controlled by the user atrun time GPIO pins have no special purpose defined, and go unused by default
To understand GPIO on Raspberry Pi 3 board, you can see it in Figure below
(source: model-b-gpio-40-pin-block-pinout )
https://www.element14.com/community/docs/DOC-73950/l/raspberry-pi-3-See the pin 1 and pin 2 on physical board on the following Figure
Trang 109In this section, we will focus on Raspberry Pi GPIO programming using Python Python and RPi.GPIO library, http://pypi.python.org/pypi/RPi.GPIO , have installed for you soyou can use them directly to access Raspberry Pi GPIO
Now you read all GPIO configuration using gpio command Type this command on Terminal
$ gpio readall
You can see pin mapping for Raspberry Pi 3 GPIO
You also can install RPi.GPIO library manually How to install?
For illustration, we will install RPi.GPIO 0.6.2 Firstly, we need Python developmentlibrary Type the following command
$ sudo apt-get install python-dev
Make sure your Raspberry Pi already connected to Internet network
Now you can download RPi.GPIO and install it For instance, I install RPi.GPIO 0.6.2
Trang 111In this section, we learn how to write data using GPIO on Raspberry Pi We can use oneLED to illustrate our case
The LED is connected to GPIO pin 11 (GPIO17) LED ground pin is connected to GPIOGND
The following is my wiring
Now we create Python application to write data on GPIO We can use GPIO.output() towrite data, GPIO.HIGH and GPIO.LOW
Trang 113The LED also is blinking.
Trang 114You can learn Raspberry Pi GPIO by trying more practices I have written a book,Raspberry Pi I/O Programming Using Python This book helps you to get started
Raspberry Pi I/O programming This book uses Raspberry Pi 1 but it’s compatible withRaspberry Pi 2 Further information about this book, you can visit to my blog,
http://blog.aguskurniawan.net/post/Raspberry-Pi-IO-Programming-using-Python.aspx
Trang 115This chapter explains how to access Raspberry Pi 3 via Serial Port.
Trang 116To debug Raspberry Pi using GPIO serial through computer, we need USB TTL device There are a lot of USB TTL device, for instance, USB to TTL Serial Cable - Debug /
Console Cable for Raspberry Pi from Adafruit, http://www.adafruit.com/products/954
Another device, you can buy USB to TTL on Cooking-Hacks,
http://www.cooking-hacks.com/index.php/usb-to-ttl-converter-cp210.html
In this section, I used a Foca V2.1 FT232RL Tiny Breakout USB to Serial UART Interface from iteadstudio I bought it on
Trang 117
http://www.exp-tech.de/Shields/Foca-V2-1-FT232RL-Tiny-Breakout-USB-to-Serial-UART-Interface.html
Trang 118By default, Raspbian disables serial debugging so we need to enable this feature On Terminal type the following command
$ sudo raspi-config
You will get a dialog Select 8 Advanced Options menu.
Then, select A8 Serial menu.
Trang 119feature
If success, you will get a success confirmation
Trang 120Now you can reboot your Raspbian by typing the command on Terminal
$ sudo reboot
Trang 121How to implement?
It’s easy You can just connect Tx from USB TTL to Raspberry Pi UART0_TXD and USB TTL RX to Raspberry Pi UART0_RXD Some USB TTL must change them It means USB TTL TX should be connected to Raspberry Pi UART0_RXD and USB TTL RX to Raspberry Pi UART0_TXD (Optional) You can connect GND from USB TTL to GND of Raspberry Pi board
Here is a sample of connected hardware
Now your USB cable of USB TTL device is be connected to your computer You can use any serial application to execute
In this book, I used PuTTY,
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html, and run it on my Windows OS
Run PuTTY and choose Serial for connection type Fill Serial line name, for instance, my Windows detected it on COM6 as below
Trang 122Set 115200 for speed serial.
Trang 123Click Serial on side menu and choose None for Parity and Flow control.
Trang 124http://freeware.the-meiers.org
Trang 125To use it, you can open Options menu and select Port and Baudrate on 115200.
Trang 126On Terminal tab, you don’t configure anything.
Trang 127Click OK button to save the configuration.
Trang 128If you’re ready, you can click Open button on PuTTY You may press Enter on keyboard
when you see blank screen
If success, you will get the authentication form
Trang 129Here is a sample of serial debugging output
Trang 130Type username and password
Trang 131You also can execute common commands such as ls.
Trang 133
If you have question related to this book, please contact me at aguskur@hotmail.com Myblog: http://blog.aguskurniawan.net