navigate site menu

Start learning with our library of video tutorials taught by experts. Get started

Up and Running with Raspberry Pi

Up and Running with Raspberry Pi

with Mark Niemann-Ross

 


The Raspberry Pi is a small, cheap, single-board computer that opens a new door to computer exploration. Simple to use and program, it can be embedded in innovative projects and has been used to build Internet-connected dog treat dispensers, low-res plotters, cell phone–operated coffeemakers, and a solar-powered computer.

This course shows how to obtain, configure, and do simple tasks with a Raspberry Pi. Mark Niemann-Ross shows you how to play sounds, boot up a GUI, program simple tasks, install software, and begin to explore hardware control with GPIO (General Purpose Input/Output).
Topics include:
  • Buying a Raspberry Pi
  • Connecting hardware
  • Installing the Raspbian OS
  • Working with frequently used Linux commands
  • Setting up VNC to control the Raspberry Pi remotely
  • Playing a sound
  • Building a simple webcam website
  • Controlling a device with GPIO in Python

show more

author
Mark Niemann-Ross
subject
Developer, Programming Languages
software
Python , Linux , Raspberry Pi 2
level
Intermediate
duration
55m 22s
released
Jul 22, 2013

Share this course

Ready to join? get started


Keep up with news, tips, and latest courses.

submit Course details submit clicked more info

Please wait...

Search the closed captioning text for this course by entering the keyword you’d like to search, or browse the closed captioning text by selecting the chapter name below and choosing the video title you’d like to review.



Introduction
Welcome
00:00 (MUSIC). Hi, I'm Mark Niemann-Ross, and welcome to
00:06 up and running with Raspberry Pi. The Raspberry Pi is a credit card-sized
00:11 microcomputer designed by the Raspberry Pi Foundation for experimentation and education.
00:17 In this course, we'll explore how the Raspberry Pi microcomputer works and get a
00:23 taste of what it can do. I'll start with an explanation of how to
00:26 buy Raspberry Pi and some necessary accessories, then show you how to
00:32 configure and boot it up with a Linux operating system.
00:36 I'll show you how to talk to the Raspberry Pi from your computer, and then explore
00:40 how to use it with peripherals. When you're finished with this course,
00:44 you'll have a great platform to learn more about embedded computers, and a working
00:48 introduction into the world of do it yourself computing.
00:51 So, let's get up and running with Raspberry Pi.
00:54
Collapse this transcript
What you should know
00:00 The Raspberry Pi is nothing but a small computer.
00:04 Small power needs, small physical size, small memory.
00:08 Everything about it is small, but it's still just a computer.
00:12 And it runs Linux, so you'll be more comfortable if you know some basic commands.
00:17 I'll discuss those commands later, but the more you know about Linux the better off
00:21 you'll be. I'm also assuming you have a working
00:24 ethernet connection with a wired, not a wireless connection.
00:28 You can use wireless adapters, but to get started, it's easier with a wired connection.
00:34 You'll also need a USB mouse, keyboard and powered speakers.
00:38 During this course, we'll build a simple webcam.
00:40 And for that you'll need an inexpensive USB camera.
00:44 Towards the end of this course, we'll be discussing the general purpose input
00:48 output pins. Also known as GPIO.
00:52 We're only going to have time to skim the surface.
00:54 GPIO requires a knowledge of electronics, as well as some skill with a soldering iron.
00:59
Collapse this transcript
Using the exercise files
00:00 In some chapters we'll be entering code and downloading files.
00:04 If you're not familiar with Linux shell programming you may find some of the
00:08 syntax odd and prone to typographic errors.
00:11 Fear not, all of these scripts are included in the exercise files and can be
00:15 transferred to the raspberry pie for cutting and pasting into the Raspberry Pie Editor.
00:20 Download the exercise files from this course at lynda.com, and unpack the zip file.
00:25 I've already got the folder here on my Desktop.
00:28 You'll need to copy that fold over to a flash drive, for use later in the course.
00:32 I've included the source files for the Python programs.
00:36 I'll discuss what these programs do and how to create them, but they are here if
00:40 you need to refer to them during the session.
00:42
Collapse this transcript
Related websites and documentation
00:00 The internet contains a wealth of information about Raspberry Pi.
00:04 As you work on more advanced topics you'll find it helpful to know where to find answers.
00:08 Raspberrypi.org is the official website for the Raspberry Pi Foundation.
00:13 It lists sources to purchase the Raspberry Pi micro computer.
00:17 It has a variety of tutorials and helpful forums.
00:19 Elinux.org is a clearing house of information about the version of Linux
00:24 running on Raspberry Pi. There is information about the general
00:28 purpose and put-out put-pins. Raspbian Wheezy, the version of Linux
00:32 design for the Raspberry Pi. And sample projects.
00:35 You'll also find information about other embedded systems, such as the Minnow board
00:40 and Beagle board. Neil Black has created a stellar beginners
00:44 guide to the Raspberry Pie, and deserves a round of applause.
00:48 If you ever find yourself confused during the set up process, check here for another perspective.
00:54 Finally, adafruit sells the Raspberry Pi as well as power supplies, motor control
00:59 boards, and experimentation kits. If you can't buy parts locally, this group
01:04 is an excellent place to purchase accessories and other useful components.
01:08
Collapse this transcript
1. Obtaining a Raspberry Pi and Accessories
Buying a Raspberry Pi
00:00 The Raspberry Pi is made by the Raspberry Pi Foundation in the United Kingdom.
00:04 And unfortunately, it has a history of being back ordered.
00:08 Fortunately, there are several vendors you can buy from.
00:11 Some of them listed on the main page of rasberrypi.org.
00:15 You can also buy it from Amazon.com, although you'll pay a bit more.
00:19 Prices vary from what you'll see here. Finally, check out adafruit.
00:25 They are reasonably priced and also carry some useful accessories that we'll talk
00:29 about in a minute. As of the date of this recording, there
00:33 are two models of the Raspberry Pi, A and B.
00:36 The model A is cheaper, but only has one USB port and no Ethernet connection.
00:43 This may not be a problem. If you connect a powered USB hub to the
00:47 Model A, and then employ a USB to WI-FI adapter, you have all the networking
00:52 capabilities of Model B. One main difference between the two models
00:56 is the amount of RAM. Model A has 256 MB of on board RAM.
01:02 The Model B, has 512 MB. This is not up-gradable on either model.
01:10 All Raspberry Pi microcomputers come with a slot for an SD memory card, an audio
01:16 out-jack, video ports for RCA, and HDMI. And a row of pins for general purpose
01:24 input and output. There are two additional connectors for
01:28 display, and a camera, but both require highly specialized hardware.
01:33 Given a small price difference, typically $10 to $25, I recommend getting the Model
01:38 B to start with. If you are purchasing more than one for,
01:42 say, a classroom, the Model A may be sufficient.
01:46
Collapse this transcript
Selecting a monitor
00:00 You'll need some way to see what the Raspberry Pi is doing, and for that you'll
00:04 need a monitor. Surprisingly, there is no VGA port, only
00:09 RCA and HDMI. You wont be able to use a standard
00:13 computer monitor, as they usually only support VGA.
00:16 Using the RCA video port is the cheapest way to go.
00:20 You'll need a TV with an RCA jack. This is often used to plug in a video
00:26 recorder or a game console. It's quite possible that you can pick up a
00:29 small, used TV from friends or a thrift store.
00:33 While you're looking for a TV also look for an RCA connector.
00:37 You'll often find them listed in the stereo department as speaker cables.
00:42 This cable will go between your Raspberry Pi and the video input on the television.
00:46 There is a drawback to using a television. You may find the type difficult to read
00:51 and the flickering may drive you crazy. Fortunately, this is only a temporary requirement.
00:57 Later on, I'll show you how to communicate using VNC, which removes the need for any
01:01 monitor, whatsoever. There is also the option of using HDMI,
01:06 typically found on more expensive computer monitors and flat screen TVs.
01:11 For our needs in this class, HDMI is overkill and an expense you can avoid.
01:16 If you have an HDMI monitor sitting around the house, that's fine, but it's not
01:20 necessary to run out and purchase one. If you purchase an HDMI to DVI adapter
01:25 cable, you could also use a DVI monitor.
01:27
Collapse this transcript
Other components you'll need
00:00 The designers of Raspberry Pie worked hard to reduce costs and use standard components.
00:05 As a result, any USB mouse or keyboard will work just fine.
00:10 You probably have one laying around your house.
00:13 Or you can pick up a used one from less than 10 dollars.
00:16 Power supplies are a snap. Raspberry Pie uses a standard microUSB
00:21 phone charger. Check the rating on the side.
00:24 You're looking for five volts with at least 700 milliamps.
00:28 You'll be happier if you purchase a power supply branded by one of the larger phone carriers.
00:34 If you have a model a raspberry pie, or have plans for more USB peripherals later
00:39 on, you'll need a USB hub. Be sure to purchase a powered hub with its
00:44 own power supply. The raspberry pie doesn't supply enough
00:48 current for devices such as hard drives or some USB WiFi adapters.
00:53 If you're using a powered hub plug it into a switchable power strip along side the
00:58 power adapter for the raspberry pie then use that switch to turn everything on at once.
01:04 This will avoid unexpected voltages at the USB port.
01:08 You'll need an SD card for external memory.
01:10 This will take the place of a hard drive. SD cards are readily available from any
01:16 electronics or camera store. Be sure to buy a regular SD card, not a microcard.
01:22 At a minimum, you'll need eight gigabytes. Anything larger than 16 gigabytes will
01:27 work, but the extra memory is unnecessary. Don't use an SD card that has valuable
01:32 photographs or other files. Those photographs will all be deleted by
01:36 the installation process. You cannot share an SD card with your
01:40 camera or other device. When we get to the chapter on building a
01:44 webcam, you'll need a USB webcam. These are a bit more difficult to find now
01:49 that most laptops have built in cameras. But with some searching you'll find one.
01:53 Almost any brand will work. The sound jack on the Raspberry Pi is standard.
01:59 Any standard earphone will work. In my case, the television I'm using for a
02:04 monitor also had an RCA audio jack. I found a cable with an earphone plug on
02:10 end, and an RCA connector on the other, and now can use the volume control on a
02:14 television to adjust the sound from the Raspberry pie.
02:17
Collapse this transcript
2. Booting Up
Connecting the hardware
00:01 Now that you have all the parts you need, connecting the Raspberry Pi is simple.
00:05 Physically, you can't plug things in wrong, but be careful.
00:09 It is possible to snap connectors off of the board if you use too much force.
00:14 Before you plug in the power, go ahead and connect the Ethernet cable.
00:21 Keyboard, mouse and video. If you wish, plug in the sound, although
00:33 there won't be anything to hear until a later chapter.
00:37 Hold back on plugging in the SD card. If you plug in power right now you'll see
00:42 the red power LED glow, but nothing else will happen.
00:45
Collapse this transcript
Installing the Raspbian Wheezy operating system
00:00 Your Raspberry Pi will do nothing without an Operating System, which is loaded from
00:05 the SD Card. We'll be using a customized version of
00:08 Debian Linux called Raspbian Wheezy. This isn't the only Operating System
00:13 available, there are also specialized OS's that turn the Raspberry Pi into a firewall
00:19 PBX or even an audio server. Loading the Operating System is an easy
00:24 process if you have internet access and can mount an SD card on your computer.
00:28 If you don't have access to wired internet, you might want to consider
00:32 purchasing a pre-formatted SD card. Search Google for Raspbian Preinstalled SD
00:38 card for sources. Okay, we're ready.
00:42 Use a web browser to download a small file called berryboot.zip from berryterminal.com.
00:50 Unpack the resulting zip file. Mount your SD card on your computer,
00:58 either using the available slot or an adapter.
01:02 Copy the files, not the folder, to the SD card.
01:08 Unmount the SD card in the normal fashion. Just a note about SD cards, and the
01:17 Raspberry Pie, unplug the power to the Raspberry Pi when connecting or removing
01:22 the SD Card. Failing to do so might not cause any
01:26 problems, but might also corrupt the card. So, with the power disconnected, insert
01:33 the SD Card into the Raspberry Pi. Make sure the Ethernet cable is connected
01:39 and then connect the power to the Raspberry Pi.
01:46 Berry boot will start up and display this dialogue on screen.
01:50 Adjust the green bars on the monitor so you can see them, and select wired
01:54 Ethernet and your location. And then hit OK.
01:58 Select the top disk to install the software.
02:01 Use No trim, discard, for the file system. And remember, all files will be erased
02:09 from this SD card. If that's okay, then go ahead and hit Format.
02:14 If that's not okay, go find a different SD card.
02:18 When you see the ad OS screen, choose Debian Wheezy Raspbian.
02:24 Those other options look fun, but save them for later exploration.
02:28 Once you've selected this, and hit OK, let it run.
02:31 BerryBoot will download the necessary files from the internet and configure the
02:37 SD card it could take about 15 minutes or more depending on your internet speed.
02:42 When it's done, exit out of BerryBoot and Raspberry Pi will boot into Wheezy.
02:47 Here's an interesting thing to keep in mind.
02:50 If you somehow mess up this SD card, simply reformat and repeat the install process.
02:56 You may lose a few files along the way, but you won't physically break the card by
03:01 deleting a necessary file. Proceed boldly, and with no fear.
03:05 The rasby config screen gives you a series of options that you can use to configure
03:11 your Raspberry Pi. But for the most part, you can simply
03:15 ignore them, move to finish with your arrow keys, and hit Return.
03:19 If you selected something you don't like during the configuration process, you can
03:29 restart the configuration by typing sudurasbyconfig.
03:30
Collapse this transcript
Testing, starting a desktop, and shutting down
00:00 If the Raspberry pi was correctly figured, you'll see a series of Linux boot messages
00:05 scroll by followed by a request to log in. The default user log in is pi, and the
00:12 password is raspberry. Now you'll be presented with a standard
00:16 Linux prop. Congratulations, your Raspberry pi is up
00:20 and running... Let's use the Linux command Clear to get a
00:24 clear screen. Weezy comes with a graphic user interface.
00:28 Simply type start x, start x and you'll see a colorful user interface complete
00:38 with games, word processors and web browsers.
00:41 This is LXDE, the lightweight X11 desktop environment.
00:46 Spends some time exploring. You'll find it very familiar, although a
00:50 bit slower than your high powered desktop computer.
00:54 When you're done with LXDE, simply log out.
00:57 And you'll arrive back at the Linux prompt.
01:03 For the sake of the information on your SD card, it's important to gracefully shut
01:07 down your Raspberry pi. Before you yank out the power cord, issue
01:12 a shut-down command. Sudu shutdown -h now.
01:21 This will make sure that everything is written to the SD card before all the
01:25 processes are shut down. Now you can safely pull out the power cord
01:30 and that's the extent of the on off switch for the Raspberry pie.
01:33
Collapse this transcript
3. Just Enough Linux
Frequently used Linux commands
00:00 This is a good time to cover a few basic Linux commands.
00:04 We have an in depth course called Unix for Mac OS X Users you might want to refer to.
00:09 Don't be put off by the Mac OS X part, Unix commands are pretty much universal
00:14 regardless of the platform. You'll often want to list the contents of
00:18 a directory. To do this in Linux, type ls, short for list.
00:23 Predictably, Linux responds with a list of all the files in the current directory.
00:28 If you'd like a more detailed list, you can also add dash al.
00:32 So, the command looks like ls space dash al.
00:38 Every Linux command has a range of options.
00:40 You probably don't know them all by heart since they're thousands of commands.
00:45 Not to worry, use man to display the manual page for each command.
00:50 Typing man ls gives us the manual for ls, showing us all the available options.
00:58 Man works for every Linux command. Many times, you'll need to switch to the
01:05 current directory. That command is cd.
01:08 For example, cd space slash takes us to the root directory.
01:16 Simply typing cd will return you to your home directory.
01:19 Typing cd space dot dot will move you to the directory just above the current directory.
01:28 There is a tremendously handy feature in most Linux systems called tab completion.
01:34 This can save you time, but more importantly, it will help you edit the
01:37 correct file. Here's how it works.
01:40 Let's switch to the root directory by typing CD slash.
01:44 Typing ls shows us a list of the directories and files in the current directory.
01:49 If I wanted to switch to the home directory, I could type cd home, or I
01:53 could type cd then an h followed by the Tab key.
02:01 This tells Linux to auto complete with the file or directory that matches with what
02:05 I've typed. In this case, it completes with Home.
02:08 If I tried to switch to a nonexistent directory, I'll know immediately that I've
02:12 done somethings wrong. For example I'd like to switch to the
02:16 zebra directory. I could type in cd zebra and get nothing.
02:23 Or I could type in cd z followed by the Tab key, and immediately see it doesn't exist.
02:32 This will be particularly useful when we are editing files.
02:35 Issuing a command to edit a nonexistent file normally causes that file to be
02:40 created, which we may not want to happen. Tab completion will prevent that.
02:45 Clear. Now, let's talk about sudu.
02:48 Sudu allows us to do things we normally shouldn't be able to do.
02:53 So, use it cautiously. Think of it as super user do.
02:59 You've already seen this used once when we shut down the Raspberry Pi.
03:03 A normal user shouldn't be allowed to turn off a computer, especially when more than
03:06 one person is using it. Shutdown dash h will generate an error.
03:13 Only a super user should be allowed to do that.
03:16 So, we can first type in sudu followed by the command we want to run as a super user.
03:26 In the upcoming chapters, we'll need to edit some configuration files.
03:30 To do that, we'll use a text editor called nano.
03:33 I can edit files in my local directory by entering cd to switch to my directory,
03:40 then typing nano followed by the name of the file I want to edit.
03:44 We'll edit a file called yellow. If the file doesn't exist, nano creates it.
03:50 Make your changes, then hit Ctrl+O to output from nano to disc and Ctrl+X to
03:59 quit nano. In some cases, you'll need to edit files
04:04 located outside of your home directory. Perhaps the etc directory.
04:09 Trying to nano/etc/newfile and then writing Ctrl+O, will produce an error
04:15 message, because we don't have permission. A simple fix is to sudu nano/etc/new file.
04:30 Now, we're allowed to do this. This is a new file.
04:36 Now, I hit Ctrl+O to write to disk, and were successful.
04:40 Again, be careful, you don't want to sudu delete all files.
04:46
Collapse this transcript
Killing a process
00:00 In an upcoming exercise, we'll need to start a program and then stop it.
00:04 In Linux, programs that are currently active are known as processes.
00:09 You can show a list of all the active processes by typing psux.
00:14 There's a wealth of information about each process.
00:17 We're mainly interested in the process ID or PID.
00:21 If you're looking for the process id of a certain command, use ps dash capital c
00:26 followed by the command. For example, ps -C k helper tells us the
00:35 process id for khelper is 8. Once you know a processes' ID you can stop
00:40 that process. Be careful with this, killing the wrong
00:44 process can be a bad thing. I'm going to start a background process we
00:48 can safely kill. Let's call up a manual page for the LS command.
00:51 Enter man, ls, followed by an ampershand. To tell it to run in the background.
00:57 Use ps ux to identify the PID for our new command.
01:03 Here the PID is 2102, now kill -9 2102 and that will kill the process.
01:13 The -9 is just a simple way of saying, yes I really do mean to do this, ps will
01:20 confirm that the man process is no longer running.
01:24 We can also kill a process by name. Let's restart man ls epershand, use ps ux
01:32 to see the process, and here it is. Now, use pkill -9 man, ps ux shows us that
01:43 the process is gone. Again, be careful when killing processes.
01:47 If you kill something important, you may have to reboot.
01:51
Collapse this transcript
4. Setting Up VNC
Why VNC is useful
00:00 VNC is the acronym for Virtual Network Computing.
00:04 It allows you to control one computer from another over a network.
00:08 It provides a graphical user interface, including the mouse and keyboard.
00:13 In our case, it will allow us to see and use the Raspberry Pi GUI without the need
00:19 for a physical keyboard. Right now, this is a convenience, and if
00:22 you're happy with your current mouse, keyboard and monitor setup, you can skip
00:26 this chapter. When you begin experimenting with devices
00:29 that require one or more USB ports, VNC will become a necessity.
00:34 There are four steps to setting up VNC. Setting up a static IP address, installing
00:41 VNC on the Raspberry Pi, setting up to start at boot, and then connecting to VNC
00:48 with a client.
00:48
Collapse this transcript
Setting up a static IP address
00:00 Connecting with the Raspberry Pie over VNC requires a static IP address one that
00:06 doesn't change. IP addresses look like 192.168.0.102, and
00:15 every computer accessing the internet gets one.
00:18 Usually they are provided for a temporary period of time called dynamic.
00:23 If you have a system administrator, ask them for a static IP address and the
00:27 gateway address. They may ask you for a MAC address.
00:31 I'll show you how to get that in just a minute.
00:34 If you are on a home network you'll need to discover a usable I P address.
00:39 To do this, turn to your Raspberry Pi and type I F config.
00:46 One of the entries will be labeled with ETH0.
00:49 Look for a line that starts with inetaddr. This is the IP address currently being
00:56 used by the Raspberry Pi. Write that number down.
00:59 We're mainly interested in the first three sets of numbers, in this case192.168.0.
01:09 Replace the last number with 50 and write that down.
01:13 If your system administrator asks for the Mac address of your Raspberry Pie, look
01:18 for HWADR followed by letters and numbers punctuated by colons.
01:24 In this case, my Mac address is b8:27:eb:af:60:31.
01:36 I'm going to clear the screen, you'll also need to know your gateway address.
01:41 If you didn't get this from your system administrator or our on home network,
01:46 simply type netstat - r. A table is displayed, one column is
01:54 labeled gateway. The first row is default and displays an
01:58 IP address for the gateway. In this case, my gateway address is
02:02 192.168.0.1 write that down. Setting up a static IP should really be
02:05 done at the router controlling your network.
02:09 If you have a system administrator, they will do this for you.
02:15 If you have a home computer you may be able to get away with being a little bit
02:19 sloppy and not reserving the address. However, if you start receiving error
02:24 messages about 'this IP Address is already in use by another computer'.
02:28 Change the 50 to a larger number or refer to the documentation for your router for
02:33 instructions on how to reserve an IP address.
02:36 If you do reserve an IP address at your router, go ahead and reboot your Raspberry
02:41 Pi right now. Now that you have a static IP address,
02:45 you'll need to set the raspberry pi to use it.
02:48 From a command line prompt, enter sudunano/etc/network/interifaces.
03:04 Remember that Sudu allows us to execute commands as a super user.
03:09 Nano is a text editor and interfaces is a network configuration file.
03:16 Your screen will display the contents of the interfaces config file.
03:20 Look for the line with iface eth0 inet dhcp.
03:24 Then use the cursor keys and Delete key to remove it.
03:30 Use the cursor keys to move to the bottom of the screen.
03:34 You'll need to add some text, here are the new lines: iface eth0 inet static.
03:45 address And then enter the static IP address you obtained from i f config.
03:52 In my case it's 192.168.0.50. Now enter net mask space 255.255.255.0
04:11 then, gateway. And then enter the gateway number you
04:16 obtained from NetStand in my case, 192.168.0.1.
04:22 When you're satisfied, type Ctrl + O to output the file from nano to disk, and
04:32 then type Ctrl +X to quit nano. Reboot the Raspberry Pie to implement
04:36 these changes, use sudo_shut down_r for reboot now.
04:47
Collapse this transcript
Installing VNC on a Raspberry Pi
00:00 Now that you have a static address, you can install a VNC server on Raspberry pie.
00:05 If you're using Rasbia-weezy /g, this is simple.
00:09 At a command prompt enter pseudo apt-get for apt-get, space, install, tight VNC
00:20 server, that's T I G H T V N C, S E R, V E R...
00:27 You'll be asked, Do you want to continue? Yes or No?.
00:31 Answer with a capital Y and take a break. When the install is finished, enter VNCSERVER.
00:39 You'll be asked to create a password, I use raspberry.
00:47 It notes that the password is longer than eight characters, go ahead and retype raspberry.
00:55 Next you'll be asked, would you like to enter a view only password?
00:58 Enter N for no. And congratulations.
01:02 You're running VNC on your Raspberry pi.
01:06
Collapse this transcript
Using the Macintosh VNC client to connect
00:00 Before going any further, let's check to make sure everything is working correctly.
00:05 To do this, you'll need a VNC client. If you're using a Macintosh with a recent
00:10 version of OS 10, this is simple. Go to the finder, then.
00:16 Go from the top menu and down to Connect to Server.
00:19 Enter vnc:// and the IP address you have given to your Raspberry Pie.
00:27 In my case, 192.168.0.50 followed by a colon.
00:36 And the number 5901. 5901 is the number of the port the
00:41 Raspberry Pi VNC server is listening to. Hit Connect.
00:47 And don't worry about the screen sharing encryption, hit Connect again.
00:53 Now type in the password you created earlier, raspberry.
00:58 If everything is working correctly, you'll see a large raspberry.
01:03 Congratulations.
01:04
Collapse this transcript
Using the Chrome VNC client to connect
00:00 If you're not on a Macintosh computer, you'll need to download a VNC client.
00:04 You can obtain free viewers from realvnc.com.
00:09 There are clients for Windows, IOS, Android and the Chrome browser.
00:13 Yes, you can control your Raspberry Pie from your cell phone.
00:18 In case you're not working on a Mackintosh, let's step through the Chrome browser.
00:22 You can use Chrome on any platform, Windows or Macintosh, which makes it
00:28 pretty convenient. It may be a bit slower than using an
00:32 application, but the Raspberry Pie is moving pretty slow anyway, so performance
00:37 really doesn't matter. Installing VNC into a Chrome browser is simple.
00:42 I'll assume you've already installed the Chrome browser on your computer.
00:45 If not, use your existing browser to search the Internet for Google Chrome.
00:51 The first entry will be a link to the download, follow the instructions from there.
00:54 To install the VNC extensions, start Chrome just like normal.
00:58 Go to Window, Extensions, and then get more extensions to browse the gallery.
01:06 This takes you to the Chrome web store. Search for VNC and choose the VNC Viewer
01:13 from RealVNC. If you're not signed in, you'll need to do
01:18 so now. Click on ADD TO CHROME.
01:24 Click Add, to accept the warning, and after a minute, you'll find the VNC Viewer
01:29 has been installed. Any time you open up a new tab, you'll see
01:32 the VNC Viewer icon. Click to start VNC, enter the Static IP
01:38 Address for the Raspberry Pi, in this case, 192.168.0.50:5901 and hit return.
01:50 Go ahead and hit Connect. And type in your password, raspberry and
01:59 hit Presto. You're connected to the Raspberry Pie.
02:01
Collapse this transcript
Running VNC at boot
00:00 As you become more advanced you may not always need VNC, but for now let's assume
00:06 you want VNC to run every time you start your Raspberry pi.
00:10 This involves installing a start up file which we can do from the VNC client.
00:15 We'll need a file from the exercise files that are on the flash drive you created earlier.
00:20 Insert the flash drive in a USB port on the Raspberry pi.
00:24 In my case, I had to unplug the mouse to open a port.
00:28 In the lower left corner is a startup menu.
00:30 Go to Accessories, then File Manager. Look for the flash drive you've just
00:36 inserted and copy the exercise files to the Pi directory.
00:40 You'll need super-user access to copy the VNC server file to the proper location.
00:46 Open LX Terminal and cd to the home directory.
00:49 Then use sudo to copy the files to the init.d directory.
00:55 Sudo, copy, exercise files using tab completion.
00:59 Tight vncserver/etc/init.d. Now we need to tell the system to use this
01:10 file at startup. Enter sudo update-rc.d tightvnc server default.
01:22 And you can ignore the INS serve warnings. Restart your Raspberry Pi using sudo shut
01:34 down dash r now. Now every time you start your Raspberry
01:38 Pi, VNC will be available. If you ever want to shut off the VNC
01:43 server, use sudo update-rc.d tightvncserver remove.
01:52
Collapse this transcript
5. Working with Sound
Introducing sound on the Raspberry Pi
00:00 The Raspberry Pi can produce high-quality streaming sound, but not out of the box.
00:06 You'll need to install extra software and jiggle a few controls.
00:09 In this movie, we'll go over the basics of setting up sound and making sure it works.
00:14 Sound can come from the HDMI ports, or the 3.5 millimeter audio jack.
00:20 The audio jack is the simplest, so let's start there.
00:23 If you're going to use speakers be sure to they're powered and have an amplifier, as
00:27 the Raspberry Pi only puts out two watts and won't be very audible.
00:31 Let's run a quick check to make sure everything is connected correctly.
00:35 At a command line prompt type, speaker-test.
00:40 The Raspberry Pie will play white noise through the speaker.
00:45 You should be able to hear static, press Ctrl+C to stop the test.
00:50 If you didn't hear any sound, check to make sure the plug is firmly seated in the jack.
00:55 Sometimes, it doesn't get pushed in all the way.
00:58 Check your speakers with a different sound source, just to make sure they're working.
01:03 In some cases HDMI monitors will stop sound.
01:07 A solution is to simply unplug the HDMI monitor and rely on VNC connection.
01:12 If that's not the problem we can check the Raspberry Pi mixer.
01:15 At a command prompt alsamixer, alsamixer. You'll see a thermometer showing the
01:23 volume level. Use the arrow keys to increase or decrease
01:27 the volume. Hit Escape to exit.
01:32 Raspberry Pi comes with a simple sound playing command called Aplay.
01:36 Here's a quick demonstration. Change to the User Share Sounds alsa
01:42 directory, cd /usr/share/sounds/alsa, and then list the contents.
01:54 You'll see a list of available sound files.
01:58 To play a sound simply type aplay, and the name of a wav file.
02:02 In this case, Front Center. >> Center.
02:10 >> If you're feeling adventurous, you can use Linux to find and play all sounds on
02:14 the system CD to your home directory. Then type in find/, to start at the top of
02:20 the directory, dash name, star, .wav to find all wav files.
02:28 And then dash exec aplay with some curly braces a backslash and a semi-colon, (MUSIC).
02:47 >> This will play an amusing series of sounds until you type Ctrl+C.
02:52 Some sounds may not play, aplay is somewhat finicky about what files it will perform.
02:57 There are other more robust sound utilities available.
03:00 Search online for raspberrypie.mpg
03:05
Collapse this transcript
Playing a sound with Python
00:00 The Raspberry Pi comes with several programming languages installed and ready
00:04 for use. You'll find C, Bash, Lua, Scratch, Squeak,
00:09 and two versions of Python. If you're familiar with Linux, you'll be
00:13 right at home. But, even if you've never seen Linux
00:15 before today, it's easy to get started. I'm going to build on our recent
00:19 discussion about using sound on Raspberry Pi with a programming example in Python 3.
00:25 Let's write a program that plays a sound for each day of the week if at any time
00:29 you get confused or need help I've included the finished program as part of
00:33 the exercise files. To launch a Python development environment
00:37 double click on the desktop icon labelled IDEL 3 don't use this plain IDEL that's
00:43 for Python 2.7 and we want to use Python 3.
00:47 If you can't see the icon, look in the start up menu under programming.
00:54 It will take a minute, but the Raspberry Pie will launch idle.
00:57 The standard integrated development environment for Python.
01:01 It defaults to a shell that allows experimentation with Python, so let's try
01:05 something simple. At the triple arrow prompt type in
01:08 Datetime dot now parentheses. You'll see an error message telling us
01:15 that datetime isn't defined. That's easy to fix.
01:19 Type from datetime import Date time, now repeat our last command datetime dot now parentheses.
01:31 And Python will print today's date and time.
01:34 Now let's write a program, if you're not familiar wit Python you may want to brush
01:39 up with Python three Essential Training here on Lynda dot com.
01:43 Let me open up the exercise file and explain how it works.
01:47 Use file open, navigate to the home pie exercise files and open Pythons sales dot py.
01:58 The first thing we do in our program is import the os library and then from the
02:03 date time library we import a function called date time Throughout the program,
02:08 there are several debug functions that may be useful.
02:11 An easy way to turn them on and off is to include a debug variable.
02:14 i'm going to set it to false for now. If you need to debug the function, you can
02:20 change this to true. Next, define a function that will be used
02:24 to play the sound and show diagnostic information.
02:27 death play a sound in parenthesis end colon.
02:31 And let's add a couple of lines for debugging.
02:33 If debug equals true, colon, then print, n, comma, end, the dash.
02:40 And then print day sounds, bracket, end bracket, parentheses.
02:45 Be careful with parentheses and brackets. And that's the end of the debugging block.
02:50 Move out by one indent level to show the end of the code block.
02:53 In Python Three the easiest way to play a sound is to use the system level command A
02:58 Play to pass a complete system command as a string.
03:03 So let's create that string. Today sound, equals, quote A Play, space,
03:10 plus, say day directory plus DaySounds bracket n bracket plus quote .wav space
03:18 dash R 1 quote. Then you send it to the system, os.system
03:24 parentheses todaySound parentheses. Now we need a variable that points to the
03:29 directory holding the sound files. We've provided a set of sound files in the
03:34 exercise files for your use. Earlier, I showed you how to use tab
03:38 completion to build a path, and it works in idle as well.
03:42 (UNKNOWN) directoy equals "/home/pie/exercise files, and don't
03:50 forget to use a back slash in front of the space between exercise and files.
03:56 Then slash day of week sounds slash quote. Day sounds is an array of the names of
04:02 wave files to be played for each day of the week.
04:06 In the exercise files we've used understandable names.
04:09 Day sounds equals bracket quote Monday, start with Monday.
04:13 In a minute we'll ask the raspberry pie for the day of the week and it will return
04:18 an integer where zero equals Monday One equals Tuesday and so on.
04:22 In Python the first element of an array is indexed to zero.
04:27 So that's where we put Monday. Then put in the rest of the names of the week.
04:31 Now we have two lines of code to retrieve the day of the week.
04:34 Today's date equalls datetime.now parenthesees.
04:39 And today's day equals datetime.weekday(today's date).
04:43 Playing todays sound is done by passing the day of the week index to the play a
04:51 sound function. Play a sound(today's date.) Finally a bit
04:56 more debug code. This will go through the array of sounds
05:00 and make sure they are all playable. If DEBUG == True; then print "Other sounds
05:06 are..." and then a for, for n in range (0,7): playASound(n).
05:16 To run your program, use Run > Run Module, the Python Shell will come to the front
05:26 and play your program. >> Wednesday.
05:28 >> If there are errors, they will appear along with details on where to find the problem.
05:34 Remember, the complete program is also located in the exercise files.
05:38 If you get confused check your program against my original.
05:41
Collapse this transcript
6. Building a Webcam Website with Python
Introduction to a webcam project
00:00 In this project, we'll step through the process of using the Raspberry Pi for a
00:04 very simple webcam. This project will combine several skills
00:08 to help you understand how to use the Raspberry Pi for projects.
00:12 And will give you a jumping off point for projects of your own.
00:16
Collapse this transcript
Obtaining and installing a webcam
00:00 You'll need to obtain a USB webcam. These used to be very easy to obtain but
00:05 now that cameras are built into every laptop, they're becoming rare.
00:09 I found mine at a thrift store. But you can also purchase them online if
00:14 they aren't available at a local electronics store.
00:19 Pretty much any webcam will work, but if you're unsure, consult the list at elinux.org.
00:24 Just make sure it has a full size USB connector, and note that some webcams
00:30 require a powered USB hub. Installation is easy.
00:34 Just plug it in to the USB connector.
00:37
Collapse this transcript
Using fswebcam to drive the camera
00:00 The Raspberry Pi doesn't come with software for a webcam.
00:04 Fortunately it's easy to install, we can use apt-get to install fswebcam.
00:11 Here's how, sudo apt-get install fswebcam. This will show some activity.
00:21 There's nothing for you to do except just watch.
00:24 When it finishes, cd will take you to your home directory.
00:29 Now, with the webcam plugged in, type fswebcam test.jpg.
00:37 Smile, the webcam should take your picture.
00:41 You can take a look at the picture by opening the file manager.
00:49 Click on pi, then open up the Image Viewer, there I am.
00:54 How flattering. If your image is chopped up it may be
00:59 taking a minute for your webcam to respond.
01:01 You can tell fswebcam to delete the first two images by typing fswebcam --skip 2
01:12 test.jpg, and that will skip the first two frames.
01:20 You can also tell fswebcam to take a series of pictures, fswebcam --loop 2, a
01:29 number of seconds, and then background to run in the backrgound and we'll tell it to
01:37 skip the first image. And save the result to test.jpg.
01:45
Collapse this transcript
Using Python as a web server
00:00 Now that the webcam is capturing an image, let's set up a web server, so that we can
00:05 see the image on a different computer. There are lots of web servers available
00:09 for the raspberry pi, but the easiest is the web server built into the Python
00:14 programming language. And already available on your raspberry pi.
00:18 To start a web server simply enter python3 -m http.server 8000.
00:30 That's all, were running this in a foreground so Ctrl+C, will stop it.
00:36 While the web server is running, you can test it by going to another computer on
00:41 your local network and entering http://. Followed by the static IP address you
00:47 created earlier. In my case, 192.168.0.50 followed by colon 8000.
00:56 8000 is the port the web server is listening to.
01:00 You'll see a very simple home page. If you'd like to see the image you've
01:04 captured with a web cam. Either click on test.jpeg or follow the
01:10 8000 with slash test.jpeg, I've provided a simple HTML file you can use as a homepage.
01:19 It's located in the exercise files and is called index.html.
01:24 It simply shows the test image, and then refreshes the page every second.
01:34 To copy this to your home directory, simply drag it on top of the pi icon.
01:40 When you point a browser at the raspberry pi, that updated image is now sent to the browser.
01:45
Collapse this transcript
Starting the webcam at boot
00:00 Starting up the webcam server at boot requires starting FS webcam and the Python
00:06 Web Server with a script. This is done the same as when we installed
00:09 VNC to run at boot. First, you'll need a script to turn the
00:13 camera and the web server on. I've provided a script in exercise files
00:17 that will do this, all you need to do is install it.
00:20 You'll need super user access to do so. Let's start by cding to our directory and
00:26 then, sudo, copy, exercise, use tab completion to fill out the name of the file.
00:34 And I'm looking for a file called, py webcam serve.
00:37 If I type in py Nothing happens. That's because there's probably more than
00:42 one file that starts with py. To get a list of those, I can hit Tab twice.
00:48 And that gives me a list of all of the files in that directory that start with py.
00:52 I can see the pyWebCamServe has a capital w.
00:56 Now if I hit Tab I see it completes it with pyWebCamServe.
00:59 I complete the rest of the line with /etc/init.d.
01:05 Now I need to tell the system to use this file at start up.
01:08 Sudo update - rc.d piewebcamserve defaults.
01:20 You can ignore the INS serve warnings. Now reboot.
01:24 Sudo shutdown dash r now. There are lots of things you could do to
01:33 improve this project the rest is up to you and your creativity.
01:37
Collapse this transcript
7. Using GPIO
What is GPIO?
00:00 The Raspberry pi has a set of pins for general purpose input/output or GPIO for short.
00:07 It's right here on the board. A double row of 13 pins for 26 pins in all.
00:13 Using these pins, you can control external devices like motors or lights and receive
00:18 signals from switches or sensors. Hooking devices up to the Raspberry Pi
00:23 requires a knowledge of electronics. You'll need to know a bit about resistors,
00:28 transistors, possibly how to solder. And what a short circuit is and how to
00:32 avoid it. But it's all worth it, because hooking the
00:35 Raspberry Pi up to another device is where the fun truly starts.
00:39 Unfortunately, we don't have enough time in this course to walk step by step
00:43 through construction of a project. But I can give you a couple of pointers
00:48 that will start you on your way. As an example, I'm going to animate this
00:52 rubber fish. It's perfect.
00:54 It comes with simple servo motors a built in speaker a battery compartment and it's amusing.
01:00
Collapse this transcript
Creating interface circuits
00:00 The first thing you should be aware of is that the GPIO isn't buffered, that is to
00:05 say, be careful. If you hook up something wrong you may
00:08 short it out. A loud snap, a quick puff of smoke and
00:11 you'll be buying a new Raspberry Pi. So, when you're starting out, look online
00:16 for circuit diagrams and followed them closely.
00:20 In general, unless you're buffering the IO, do not connect the Raspberry Pi GPIO
00:26 to anything that puts out voltage or pulls current.
00:28 An alternative to building your own circuit board is to buy a pre-assembled
00:34 buffer board. You'll find a long list of them at elinux.org.
00:40 If you don't have electronics experience, this is your only choice, but it's a good choice.
00:45 The rubber fish comes with three simple servo motors.
00:49 Applying outage to a motor moves it out. Turning off voltage allows the spring to
00:54 return to a resting position. The motors pulls about four watts a
00:58 current, which is more than the Raspberry pie can provide.
01:01 So, I set up a simple transistor circuit, and tested the connection.
01:07 Connecting the interface to the correct GPIO pins, requires a bit of study.
01:14 Some pins provide power. Some provide input or output depending on
01:19 how they're configured. Some are simply ground.
01:24 And the physical pins don't correspond to the GPIO numbers.
01:28 For example, the seventh bottom pin is noted as GPIO 27 unless you're using a
01:36 revision one board board in, which case it is GPIO 21.
01:40 Don't worry if that doesn't make any sense at first.
01:43 It's confusing for everyone. Again figuring out GPIO pin out are a bit
01:47 beyond this course. It will require some knowledge of electronics.
01:52 Familiarity with a volt O meter and some soldering skills.
01:56 This is just a walk through, so you understand how they work.
01:59
Collapse this transcript
Controlling a device with GPIO in Python
00:00 Once the hardware is all correctly connected, we can write a program to
00:04 control or read those pins. Let's walk through a Python program that
00:08 will control the rubber fish. The complete program is located in the
00:12 exercise files and you can open it up using the Python Idol editor, located on
00:16 your Raspberry Pi desktop. First, we need a module that will allow us
00:20 to communicate with a GPIO ports. Python has one called rpi.gpio.
00:25 If you're using raspbian wheezy, this module is already installed, and you can
00:31 simply import it. The first line does that, import rpi.gpio
00:37 as GPIO. I'm also going to use a sleep timer so I
00:41 grab that from the time module. From time import sleep.
00:45 I need to tell the GPIO module that I'm going to refer to the actual pin number
00:49 instead of the designated signal number. GPIO.setmode uses GPIO.BOARD to indicate that.
00:58 This means I can simply count pins on the raspberry pie to figure out what to connect.
01:02 This doesn't mean I can just choose any pin.
01:05 Some pins are always 3.3 volts, some are ground and some are used to provide 5
01:12 volts to the raspberry pie. In my case, I'm going to connect to GPIO 18.
01:18 Which is present on physical pin 12, which is the sixth pin from the left on the
01:24 bottom row, and yes this is confusing. Don't just guess, you'll most likely guess
01:30 wrong and fry your Raspberry pi. Pins can be configured to either read a
01:35 signal, say from a switch, or write a signal...
01:39 The following line sets up pin 11 to accept input.
01:42 GPIO.setup(11, GPIO.IN). Then to tell the Raspberry pi to send a
01:51 signal out of pin 12, just simply use GPIO.setup(12, GPIO.OUT).
02:00 Now, all that remains is to set a pin high or low.
02:04 Setting it high will set the voltage of the pin to 3.3 volts, setting it low will
02:09 set the pin to 0 volts. I've put this in a loop so it will turn
02:13 the pin on, pause, then off, pause, then on.
02:18 So I've set it up while true colon sleeper time equals 3, which will control the
02:23 amount of pause between the commands. And then GPIO dot output to pin 12, set it
02:29 low with GPIO.LOW. Pause three seconds, GPIO dot output,
02:34 parentheses 12, and then you set the pin to high with GPIO.HIGH.
02:39 And then sleep for another three seconds. Accepting input is equally as simple.
02:44 You just simply read the value from the pin.
02:47 In this case, I'm setting the variable input_value equal to the state of
02:51 GPIO.input number 11. Save the program, then run it using sudo.
02:58 sudo python3 tryGPIO. Any time you use the GPIO pins you have to
03:07 do so as the super user. This example is in Python but there are a
03:13 wide range of other languages you can use with the Raspberry Pi.
03:19 Including C, Bash, Lua, Scratch, and two versions of Python.
03:25 Plus more that can be installed from the internet.
03:27 You'll find a growing list at elinux.org.
03:31
Collapse this transcript
Conclusion
Where to go from here?
00:00 Now that you have a functioning Raspberry Pi and an understanding of how it works,
00:04 the rest is up to you and your ingenuity. Join the community on Facebook, follow the
00:09 blog at Raspberrypi.org and above all, experiment.
00:13 I appreciate your time, and I hope your enjoyed watching this course as much as I
00:17 enjoyed making it. Please take a moment to provide feedback
00:20 through the course homepage on lynda.com. Thank you.
00:25
Collapse this transcript


Suggested courses to watch next:

Python 3 Essential Training (6h 36m)
Bill Weinman

Unix for Mac OS X Users (6h 35m)
Kevin Skoglund


Are you sure you want to delete this bookmark?

cancel

Bookmark this Tutorial

Name

Description

{0} characters left

Tags

Separate tags with a space. Use quotes around multi-word tags. Suggested Tags:
loading
cancel

bookmark this course

{0} characters left Separate tags with a space. Use quotes around multi-word tags. Suggested Tags:
loading

Error:

go to playlists »

Create new playlist

name:
description:
save cancel

You must be a lynda.com member to watch this video.

Every course in the lynda.com library contains free videos that let you assess the quality of our tutorials before you subscribe—just click on the blue links to watch them. Become a member to access all 104,069 instructional videos.

get started learn more

If you are already an active lynda.com member, please log in to access the lynda.com library.

Get access to all lynda.com videos

You are currently signed into your admin account, which doesn't let you view lynda.com videos. For full access to the lynda.com library, log in through iplogin.lynda.com, or sign in through your organization's portal. You may also request a user account by calling 1 1 (888) 335-9632 or emailing us at cs@lynda.com.

Get access to all lynda.com videos

You are currently signed into your admin account, which doesn't let you view lynda.com videos. For full access to the lynda.com library, log in through iplogin.lynda.com, or sign in through your organization's portal. You may also request a user account by calling 1 1 (888) 335-9632 or emailing us at cs@lynda.com.

Access to lynda.com videos

Your organization has a limited access membership to the lynda.com library that allows access to only a specific, limited selection of courses.

You don't have access to this video.

You're logged in as an account administrator, but your membership is not active.

Contact a Training Solutions Advisor at 1 (888) 335-9632.

How to access this video.

If this course is one of your five classes, then your class currently isn't in session.

If you want to watch this video and it is not part of your class, upgrade your membership for unlimited access to the full library of 2,024 courses anytime, anywhere.

learn more upgrade

You can always watch the free content included in every course.

Questions? Call Customer Service at 1 1 (888) 335-9632 or email cs@lynda.com.

You don't have access to this video.

You're logged in as an account administrator, but your membership is no longer active. You can still access reports and account information.

To reactivate your account, contact a Training Solutions Advisor at 1 1 (888) 335-9632.

Need help accessing this video?

You can't access this video from your master administrator account.

Call Customer Service at 1 1 (888) 335-9632 or email cs@lynda.com for help accessing this video.

preview image of new course page

Try our new course pages

Explore our redesigned course pages, and tell us about your experience.

If you want to switch back to the old view, change your site preferences from the my account menu.

Try the new pages No, thanks

site feedback

Thanks for signing up.

We’ll send you a confirmation email shortly.


By signing up, you’ll receive about four emails per month, including

We’ll only use your email address to send you these mailings.

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

By signing up, you’ll receive about four emails per month, including

We’ll only use your email address to send you these mailings.

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked