use of raspberry pi chao gao [email protected] february...

18
Use of Raspberry Pi Chao Gao [email protected] February 25, 2016 1. Raspberry Pi setup: 1.1 Connection and start Raspberry Pi If you have a case, start by installing the Raspberry Pi inside the case. Insert a pre-programmed MicroSD card into the MicroSD card slot on the bottom side of the Raspberry Pi Connect a USB keyboard and mouse to the USB ports. Connect a HDMI monitor to the Raspberry Pi using a HDMI cable. Connect the Raspberry Pi to your network using an Ethernet cable. Once all connections have been made, it is now time to connect the MicroUSB power supply to the board. When the power is connected, the Raspberry Pi will start to boot. Booting Up for the First Time: o The following screen should be displayed in Fig. 1: Fig.1 First Time boot Screen o Follow the instructions in order to setup your desired operating system. o If you need detailed and step by step instructions, check out the following YouTube video tutorial: http://www.youtube.com/watch?v=TyFDaMpdh2c o First time Configuration, follow the tutorial:

Upload: danglien

Post on 08-Oct-2018

222 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Use of Raspberry Pi Chao Gao gaoch97@gmail.com February …xinwenfu/IoT/UseRaspberryPi-ChaoGao.pdf · Fig. 2 Raspberry Pi system 1.2 Network setup • Using a Wired Network The quickest

Use of Raspberry Pi Chao Gao

[email protected] February 25, 2016

1. Raspberry Pi setup: 1.1 Connection and start Raspberry Pi

• If you have a case, start by installing the Raspberry Pi inside the case. • Insert a pre-programmed MicroSD card into the MicroSD card slot on the bottom

side of the Raspberry Pi • Connect a USB keyboard and mouse to the USB ports. • Connect a HDMI monitor to the Raspberry Pi using a HDMI cable. • Connect the Raspberry Pi to your network using an Ethernet cable. • Once all connections have been made, it is now time to connect the MicroUSB

power supply to the board. When the power is connected, the Raspberry Pi will start to boot.

• Booting Up for the First Time: o The following screen should be displayed in Fig. 1:

Fig.1 First Time boot Screen

o Follow the instructions in order to setup your desired operating system. o If you need detailed and step by step instructions, check out the following

YouTube video tutorial: http://www.youtube.com/watch?v=TyFDaMpdh2c

o First time Configuration, follow the tutorial:

Page 2: Use of Raspberry Pi Chao Gao gaoch97@gmail.com February …xinwenfu/IoT/UseRaspberryPi-ChaoGao.pdf · Fig. 2 Raspberry Pi system 1.2 Network setup • Using a Wired Network The quickest

https://learn.adafruit.com/adafruits-raspberry-pi-lesson-2-first-time-configuration/overview

• Config Using the Whole SD Card This may seem a bit strange, but by default the Raspberry Pi only uses as much of the SD card as the operating system requires. This means that even though you might have used a large SD card, the operating system won't use it.

To fix this so that all the space on the SD card can be used, use up / down cursor keys to select the 'expand_rootfs' menu option and hit return. Once you do that, there will be some screen flashing as a script is run and then you will see the following confirmation.

• Chaning Timezone

Page 3: Use of Raspberry Pi Chao Gao gaoch97@gmail.com February …xinwenfu/IoT/UseRaspberryPi-ChaoGao.pdf · Fig. 2 Raspberry Pi system 1.2 Network setup • Using a Wired Network The quickest

From the options, first select the Geographic Area, then the Timezone within that area.

• Booting into Desktop

Page 4: Use of Raspberry Pi Chao Gao gaoch97@gmail.com February …xinwenfu/IoT/UseRaspberryPi-ChaoGao.pdf · Fig. 2 Raspberry Pi system 1.2 Network setup • Using a Wired Network The quickest

The final configuration that you definitely want to make, unless you don't like windowing environments is to change the boot behaviour so that it automatically starts the windowing system and logs you in.

Select the sensible option and hit Return.

o You can run the Raspi-Config tool any time you like. To do so, type the

following at a Raspbian command line prompt: sudoraspi-config

The Raspberry Pi system shown below in Fig. 2

Page 5: Use of Raspberry Pi Chao Gao gaoch97@gmail.com February …xinwenfu/IoT/UseRaspberryPi-ChaoGao.pdf · Fig. 2 Raspberry Pi system 1.2 Network setup • Using a Wired Network The quickest

Fig. 2 Raspberry Pi system

1.2 Network setup

• Using a Wired Network The quickest way to get your Raspberry Pi connected is to use an Ethernet patch cable and just plug it into the back of your home network router. As soon as you plug your Pi in, you should see the network LEDs start to flicker.

• USB WiFi Adapter Follow the tutorial: https://learn.adafruit.com/adafruits-raspberry-pi-lesson-3-network-setup/setting-up-wifi-with-occidentalis Then plug the WiFi adapter in and reboot your Raspberry Pi again. You should find that the Raspberry Pi connects using the WiFi adapter as it boots up. (It is not applied for Umass Lowll school WiFi “eduroam”.)

Page 6: Use of Raspberry Pi Chao Gao gaoch97@gmail.com February …xinwenfu/IoT/UseRaspberryPi-ChaoGao.pdf · Fig. 2 Raspberry Pi system 1.2 Network setup • Using a Wired Network The quickest

1.3 GPIO setup The GPIO pins can be used as both digital outputs and digital inputs. As digital outputs, you can write programs that turn a particular pin HIGH or LOW. Setting it HIGH sets it to 3.3V setting it LOW sets it to 0V. If you use a pin as a digital input, then you can connect switches and simple sensors to a pin and then be able to check whether it is open or closed (that is, activated or not) To program the GPIO ports in Python, we need to install a very useful Python 2 library called Rpi.GPIO. This module gives us a simple to use Python library that will let us control the GPIO pins. To install RPi.GPIO, you first need to install the Python Development toolkit that RPi.GPIO requires. To do this enter the following command into Raspberry Pi Terminal:

sudoapt-getupdate

sudoapt-getinstallpython-dev

sudoapt-getinstallpython-rpi.gpio (You will probably be prompted to confirm by entering 'Y'.)

1.4 I2C setup

I2C is a very commonly used standard designed to allow one chip to talk to another. So, since the Raspberry Pi can talk I2C we can connect it to a variety of I2C capable chips and modules. The I2C bus allows multiple devices to be connected to your Raspberry Pi, each with a unique address, that can often be set by changing jumper settings on the module. It is very useful to be able to see which devices are connected to your Pi as a way of making sure everything is working. To do this, it is worth running the following commands in the Terminal to install the i2c-tools utility.

sudoapt-getupdate

sudoapt-getinstallpython-smbus

sudoapt-getinstalli2c-tools

Then follow the tutorial to install Kernel Support (with Raspi-Config): https://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/configuring-i2c

In Terminal, run sudoraspi-configand follow the prompts to install i2c support for the ARM core and linux kernel:

Page 7: Use of Raspberry Pi Chao Gao gaoch97@gmail.com February …xinwenfu/IoT/UseRaspberryPi-ChaoGao.pdf · Fig. 2 Raspberry Pi system 1.2 Network setup • Using a Wired Network The quickest

Then reboot! Then test I2C devices use: sudoi2cdetect-y1

Page 8: Use of Raspberry Pi Chao Gao gaoch97@gmail.com February …xinwenfu/IoT/UseRaspberryPi-ChaoGao.pdf · Fig. 2 Raspberry Pi system 1.2 Network setup • Using a Wired Network The quickest

2. Raspberry Pi with thermal sensor D6T-44L-06 and Pi-Pan servo 2.1 Overview

In this project, we use OMRON's D6T-44L-06 thermal sensors to detect human presence. In order to increase the detection region, we mount the thermal sensor on the Pi-Pan servo. We use GPIO connector on Raspberry Pi to control the Pi-Pan servo and read the thermal sensor’s signals through I2C connector on Raspberry Pi.

2.2 Parts To build the project described in this topic, you will need the following parts. a. OMRON D6T-44L-06 thermal sensors with Cable Harness

Fig.3 D6T-44L-06 thermal sensors Fig.4 Cable Harness D6T-HARNESS-02

• TheOMROND6T-44L-06datasheet: https://www.omron.com/ecb/products/pdf/en-d6t.pdf

• TheOMROND6T-44L-06userguide:https://www.omron.com/ecb/products/sensor/special/mems/pdf/AN-D6T-01EN_r2.pdf

b. Pi-Pan servo

Fig.5 Pi-Pan servo

• Assembly instructions for Pi-Pan Kit: http://www.mindsensors.com/content/27-assembly-instructions-for-pi-pan-kit

• Mounting Pi-Pan Assembly on Target: http://www.mindsensors.com/content/28-mounting-pi-pan-assembly-on-target

• Pi-PanSoftwareinstallationandTest: http://www.mindsensors.com/content/33-pi-pan-readme

Page 9: Use of Raspberry Pi Chao Gao gaoch97@gmail.com February …xinwenfu/IoT/UseRaspberryPi-ChaoGao.pdf · Fig. 2 Raspberry Pi system 1.2 Network setup • Using a Wired Network The quickest

c. Logic Level Converter board

Fig.6 Logic Level Converter

• Logic level converter datasheet: http://cdn.sparkfun.com/datasheets/BreakoutBoards/BSS138.pdf

• Hookup Guide: https://learn.sparkfun.com/tutorials/bi-directional-logic-level-converter-hookup-guide

d. Two pull-up resistors (10 KΩ)

Fig.7 Pull-up resistors 10 KΩ

Pull-up Resistor:http://www.seattlerobotics.org/encoder/mar97/basics.html The key function for a pull-up is to prevent input lines from floating. The key function for the resistor itself is to prevent too much current from flowing through the pull-up circuit.

The R1 resistors function is to limit the amount of current that can flow through the circuit. When switch S1 is open (off), if nothing is connected to pin 1, the value of the input is considered to be floating. This is a very weak condition, and any electrical noise could cause the input to go low. However, if pin 1 is tied to Vcc through the resistor. Since pin1 is a high impedance input, a voltage meter or logic probe placed on pin 1 will show Vcc (+5v) if connected to pin 1. When switch S1 is closed (on), pin 1 has a direct connection to GND, which takes it to the low state. The pin1 side of R1 also has a direct connection to ground. Current will flow from Vcc, through R1, and to ground. It isn't considered a short, however, because R1 will limit the amount of current that can flow to a very small amount. In fact, you can compute this using Ohms law.

I = V / R => I = 5v / 10,000ohms => I = .0005A (.5mA)

Page 10: Use of Raspberry Pi Chao Gao gaoch97@gmail.com February …xinwenfu/IoT/UseRaspberryPi-ChaoGao.pdf · Fig. 2 Raspberry Pi system 1.2 Network setup • Using a Wired Network The quickest

e. Raspberry Pi 2

Fig.8 Raspberry Pi 2

f. Breadboard and Jumper wire pack

Fig.9 Breadboard and Jumper wire pack

2.3 Hardware Connection All devices are connected in this way shown in Fig.10 and Fig.11:

Fig.10 Connection

Page 11: Use of Raspberry Pi Chao Gao gaoch97@gmail.com February …xinwenfu/IoT/UseRaspberryPi-ChaoGao.pdf · Fig. 2 Raspberry Pi system 1.2 Network setup • Using a Wired Network The quickest

Fig.11 Connection

2.4 Software

• Install pigpio library first: http://abyz.co.uk/rpi/pigpio/ Follow the tutorial to install the pigpio library on your Raspberry Pi http://abyz.co.uk/rpi/pigpio/download.html

• Start the pigpio daemon sudopigpiod

• Run the demo program: http://www.cs.uml.edu/~cgao/Pi/pi.py

pythonpi.py2.5 Test

• Please see the demo on YouTube: https://youtu.be/SscHY2hkUrg

Page 12: Use of Raspberry Pi Chao Gao gaoch97@gmail.com February …xinwenfu/IoT/UseRaspberryPi-ChaoGao.pdf · Fig. 2 Raspberry Pi system 1.2 Network setup • Using a Wired Network The quickest

3. Raspberry Pi with Motion detector 3.1 Overview

In this project, we use the GPIO connector on Raspberry Pi to read digital inputs signals from a PIR motion detector. We will concentrate on sensing movement and activation of the LED. Raspberry Pi will show a “Movement Detection” on Screen and light up the LED when movement is detected.

3.2 Parts To build the project described in this topic, you will need the following parts. a. PIR Sensor

Fig.12 PIR Motion Sensor

• PIR Motion Sensor Datasheet: https://learn.adafruit.com/downloads/pdf/pir-passive-infrared-proximity-motion-sensor.pdf

b. A LED and a 10 KΩ resistor. This LED can be lighted up when movement is detected. The 10 KΩ resistors can be used for protecting the LED.

Fig.13 LED and 10 KΩ resistor

Page 13: Use of Raspberry Pi Chao Gao gaoch97@gmail.com February …xinwenfu/IoT/UseRaspberryPi-ChaoGao.pdf · Fig. 2 Raspberry Pi system 1.2 Network setup • Using a Wired Network The quickest

c. Raspberry Pi Used for reading the value through GPIO pins.

Fig.14 Raspberry Pi 2

d. Breadboard and Jumper wire pack

Fig.15 Breadboard and Jumper wire pack

3.3 Hardware Connection

Fig.16 Connection

Page 14: Use of Raspberry Pi Chao Gao gaoch97@gmail.com February …xinwenfu/IoT/UseRaspberryPi-ChaoGao.pdf · Fig. 2 Raspberry Pi system 1.2 Network setup • Using a Wired Network The quickest

Fig.17 Connection

3.4 Software

• Run the demo program: http://www.cs.uml.edu/~cgao/Pi/Mov.py

pythonMov.py

3.5 Test

• Please see the demo on YouTube: https://youtu.be/kgeYOVPYKas

Page 15: Use of Raspberry Pi Chao Gao gaoch97@gmail.com February …xinwenfu/IoT/UseRaspberryPi-ChaoGao.pdf · Fig. 2 Raspberry Pi system 1.2 Network setup • Using a Wired Network The quickest

4. Raspberry Pi with photo resistor 4.1 Overview

Raspberry Pi cannot read analog input signals, thus need to use an Analog-to-Digital Converter chip with a Pi to read analog input signals. However, there's a way to read many sensors without an ADC! By measuring the sensor as a resistor that is used to 'fill up' a capacitor, we can count how long it takes. It's not nearly as precise as an ADC and its a little flakey (since it depends on the Pi timing itself which can vary based on how 'busy' the computer is) The way we do this is by taking advantage of a basic electronic property of resistors and capacitors. It turns out that if you take a capacitor that is initially storing no voltage, and then connect it to power (like 3.3V) through a resistor, it will charge up to the power voltage slowly. The bigger the resistor, the slower it is. This technique only works with sensors that act like resistors. However, there are quite a few fun sensors that act this way: photocells, thermistors (temperature sensors), flex sensors, force-sensitive resistors, and many more. It cannot be used with sensors that have a pure analog output like IR distance sensors or analog accelerometers. In this project, we use Raspberry Pi to read the photocell resistance. In the dark, a photo resistor can have a resistance as high as several megohms (MΩ), while in the light, a photo resistor can have a resistance as low as a few hundred ohms. Thus, when the lightness is less than a threshold value, the LED will be lighted up.

4.2 Parts To build the project described in this topic, you will need the following parts. a. A basic photocell. This is a resistor that changes resistance based on how bright the light is.

Fig.18 Photocell resistor

b. A capacitor The capacitor just needs to be rated for 5V or greater.

Fig.19 Capacitor

Page 16: Use of Raspberry Pi Chao Gao gaoch97@gmail.com February …xinwenfu/IoT/UseRaspberryPi-ChaoGao.pdf · Fig. 2 Raspberry Pi system 1.2 Network setup • Using a Wired Network The quickest

c. Raspberry Pi Used for reading the value through GPIO pins.

Fig.20 Raspberry Pi 2

d. A LED and a 10 KΩ resistor. This LED can be light up when lightness is less than a threshold value. The 10 KΩ resistor can be used for protecting the LED.

Fig.21 Raspberry Pi 2

e. Breadboard and Jumper wire pack

Fig.22 Breadboard and Jumper wire pack

Page 17: Use of Raspberry Pi Chao Gao gaoch97@gmail.com February …xinwenfu/IoT/UseRaspberryPi-ChaoGao.pdf · Fig. 2 Raspberry Pi system 1.2 Network setup • Using a Wired Network The quickest

4.3 Hardware Connection

Fig.23 Connection

Fig.24 Connection

Page 18: Use of Raspberry Pi Chao Gao gaoch97@gmail.com February …xinwenfu/IoT/UseRaspberryPi-ChaoGao.pdf · Fig. 2 Raspberry Pi system 1.2 Network setup • Using a Wired Network The quickest

4.4 Software

• Run the demo program: http://www.cs.uml.edu/~cgao/Pi/photo.py

pythonphoto.py

4.5 Test

• Please see the demo on YouTube: https://youtu.be/Xwcc2uJq8e8