Raspberry Pi Crash Course 2017
What will we be doing today? Part 1 Background Information: Learn about the Raspberry Pi See demos of what the Pi can be used for Brief intro to Linux Break
What will we be doing today? Part 2: Hands On Setup the Raspberry Pi RetroPie Learn how to use the command line Learn how to use the Pi Camera Check out Python games
Part 1: The Boring Stuff
Why was the Pi created? Concern over the decline in computer literacy In the 1990s most new Computer Science students were experienced hobbyist programmers. The 2000s were very different; a typical applicant may have only done a little web programming.
Raspberry Pi Foundation Educational charity based in the UK The Foundation s goal is to advance the education of adults and children in the field of computers, computer science, and related subjects. https://www.raspberrypi.org/about
What is the Raspberry Pi? Affordable credit-card sized computer Plugs into a computer monitor or TV Uses standard keyboard and mouse Can browse the internet and play HD video Can also interact with the outside world!
What can you do with it? Limitless possibilities GPIO Pins allow the Pi to connect to outside world The Pi can become: Streaming device File Server Wireless Printer Server Home Security System Weather Station 5 Projects
Evolution of the Raspberry Pi August 2011 - First Alpha Board January 2012 - Model B is created
Evolution of the Raspberry Pi November 2012 - Model A created April 2014 - Compute Module
Evolution of the Raspberry Pi July 2014 - Model B+ Created November 2014 - Model A+ Created February 2015 - Pi 2 Created
Raspberry Pi 3 Model B Stats 1.2GHz quad-core ARM Cortex-A53 CPU 64-bit 1GB RAM 4 USB ports Full HDMI port Ethernet port Micro SD card slot Combined 3.5mm audio jack and composite video Camera and display interface 40 General Purpose Input / Output pins (GPIOs) On board 802.11n Wifi and Bluetooth 4.1 Classic
Raspberry Pi Schematic
ARM vs x86 Architecture The Raspberry Pi uses ARM processors ARM is RISC, while x86 is CISC Using RISC leads to smaller silicon areas and better power efficiency, while CISC processors are larger and more power-hungry, but can process data faster. Cell phones use ARM processors, while most desktops and laptops use CISC processors.
Intro to Linux...again Linux is an operating system used around the globe You may not know it, but Linux is all around you. Android uses a version of the Linux kernel. A kernel is the portion of an OS that interacts directly with the hardware.
Linux History Linux was created by Linus Torvalds In 1991, as a student, Linus created a free operating system kernel which became known as Linux. The Linux kernel paired well with the GNU system, free software based off of UNIX.
What is a distribution? There are different flavors of GNU/Linux A distribution(distro) of Linux is an operating system that uses the Linux kernel, and is typically based around a package management system. The most popular distros are: Mint, Debian, Ubuntu, OpenSuse and Red Hat. You ll see another distro later on today.
Desktop Linux Desktop experience is improving in Linux Linux as as dekstop can be more complicated than Linux for a server. Linux as a desktop has several different pieces are parts. Unlike Windows and Mac, the entire interface can change.
Desktop Linux Different components of Desktop Linux Bootloader The shell (CUI or Command Line Interface) Graphical Server (X.org, Wayland) Desktop Environment (uses Graphical Server)
Desktop Linux Popular Desktop Environments Gnome 2 and Gnome 3 Cinnamon XFCE KDE Unity
KDE
Desktop Linux
Distribution Differences Common Differences Desktop environment Package Manager Init System Default software packages
What is a Package Manager? A package management system is a collection of tools to properly install, uninstall, upgrade, and configure programs or software for an operating system. dpkg is the package manager for.deb packages. We will be using apt-get, which is a user friendly interface to dpkg.
Helpful Websites Official Raspberry Pi website https://www.raspberrypi.org/ The MagPi, online Raspberry Pi magazine https://www.raspberrypi.org/magpi/ PiWeekly, online Raspberry Pi newsletter http://piweekly.net/ Raspberry Pi IV Beginners https://www.youtube.com/user/raspberrypibeginners The Raspberry Pi Guy http://www.theraspberrypiguy.com/
Your Raspberry Pi Raspberry Pi 3 Model B Camera Kit
Camera Kit Contents Raspberry Pi 3 B Raspberry Pi Case Micro SD Card Power Supply Pi Camera
Assembling the Pi To setup the Raspberry Pi, the following components are needed. (HDMI cable) Camera Kit Supplies Additional Hardware
Hands-On: Assembling the Pi 1. 2. Gently pull on each side of the tab for the camera slot. Insert the Camera tape with the connection facing the HDMI port and close the tab.
Hands-On: Assembling the Pi 3. Remove the plastic wrap from the clear case. 4. Separate the two pieces by squeezing and pulling upward.
Hands-On: Assembling the Pi 5. Examine how the pegs line up, taking special attention to the notches on the right side.
Hands-On: Assembling the Pi 6. Place the edge of the PI near the GPIO pins under the notches in the case.
Hands-On: Assembling the Pi 7. Snap the PI into place 8. Insert the microsd card into the slot on the underside of the Pi case
Hands-On: Assembling the Pi 9. Line up the holes of the camera with the areas of the top portion of the case. Snap it into place. 10. Snap the top portion of the case onto the bottom.
Hands-On: Assembling the Pi 11. 12. 13. 14. Plug in keyboard and mouse Plug in monitor using the HDMI to DVI cable Make sure monitor is turned on DVI source Do not plug in the power supply just yet
Hands-On: Assembling the Pi Where is the power button? The Raspberry Pi doesn t have a power button. It boots up as soon as you plug in the power supply. If you ve completed all the previous steps, plug in the power supply to boot the Raspberry Pi.
Hands-On: Configuring the Pi Installing the Operating System The micro SD that you have comes pre-installed with software named NOOBS. This stands for New Out Of Box Software. We will use it to install Raspbian, which is a fork of another Linux distribution called Debian.
NOOBS We are going to install Raspbian Once NOOBS has booted, you should see a light background with a prompt showing Raspbian as an available OS to install. Select Raspbian and click Install in the upper left corner of the prompt.
NOOBS Click OK on the prompt once NOOBS is done. You will see a lot of text zipping past on the screen, don t panic the desktop will appear shortly. Now you should be looking at the Raspbian Desktop. It is similar to Windows and Mac s desktop interfaces. Next we will change our language and location settings.
Hands-On: Configuring the Pi Setting up Wifi 16. Outside of the shell, you will see a network icon towards the top right of the screen. Click the icon, and select ND Guest
Hands-On: Configuring the Pi Configuring the Raspberry Pi for the first time Launch the Raspberry Pi Configuration Tool Type the following into the shell: ~$ sudo raspi-config
Hands-On: Configuring the Pi Changing Password Select 1. Change User Password and press Enter
Hands-On: Configuring the Pi Changing Password Type your new password, make it easy to remember!
Hands-On: Configuring the Pi Enable Camera Navigate to 5. Interfacing Options and press Enter
Hands-On: Configuring the Pi Enable Camera Make sure P1 Camera is highlighted and press Enter Then, Press the left arrow key and hit Enter for <Yes>
Hands-On: Configuring the Pi Exit Configuration Once back at the main configuration screen, press the Right Arrow Key twice to highlight Finish. Press Enter.
Hands-On: Configuring the Pi Exit Configuration Reboot the Pi
RetroPie RetroPie is another fun way to use a Raspberry Pi 3
What is RetroPie? An operating system containing a collection of emulators that allows the Raspberry Pi to play retro video games It can be installed on its own or on top of Raspbian.
What is an emulator? A piece of software that allows for a computer to act as if it were another piece of hardware. Video game consoles and older computers (DOS, C64, Amiga, etc.) are common targets for emulation. Emulators often use ROM s, which are files that simulate video game cartridges
Attention! You will need a few additional materials beyond the Pi itself: a computer with an SD card reader, and a USB flash drive. In addition, you will need 7zip or a similar program if you use Windows to extract the RetroPie image.
https://retropie.org.uk/download/
Extracting and Installing Extracting: Linux/Mac: use command line: tar xzf retropie-4.x.x-rpi2_rpi3.img.gz Windows: use 7-Zip or a similar program Installing the image to the SD card: Windows: Win32DiskImager Mac: Apple Pi Baker Linux: dd command
Adding ROMS Plug the USB drive into your computer and create a folder called retropie. Plug the drive into your Pi and unplug it once it stops blinking. Plug it back in and add your ROMS. Make sure you add it to the right category within the roms folder! Plug the drive back in and restart the Pi.
Hands-On: The Command Line The command line gives you more control Click on the Terminal button in the top left menu bar. This will give you access to a console that can do everything the GUI can and more.
Hands-On: The Command Line Learning how to use the command line As we go through the command line lesson you can also have your file system opened in the GUI so you can see some of the changes we make.
Hands-On: The Command Line Learning how to use the command line You have already used a command during this presentation. ~$ sudo raspi-config Now we can learn some more commands. Try each command as we go through them.
Hands-On: The Command Line Learning how to use the command line echo will print the argument to the console.
Hands-On: The Command Line Learning how to use the command line If you ever want to run the same command again you just typed, press the Up arrow key and it will automatically fill the prompt with your last command.
Hands-On: The Command Line Learning how to use the command line man will show you the manual page for the argument. Press Q on the keyboard to exit the manual page.
Hands-On: The Command Line Learning how to use the command line apropos is used to search the manual page descriptions for the specified keyword. You can find commands with copy in their descriptions as an example.
Hands-On: The Command Line Learning how to use the command line clear will move the prompt to the top of the console window. This effectively clears the console. You can also try Ctrl and L at the same time to clear the shell.
Hands-On: The Command Line Learning how to use the command line pwd will print the current working directory path. This is basically where you are with this console.
Hands-On: The Command Line Learning how to use the command line ls will list the directories in the current working directory.
Hands-On: The Command Line Learning how to use the command line Most commands have options (arguments) that change their behavior. The options usually start with a - and are typed after the command. ~$ ls -a Display hidden files ~$ ls -l List files in long format
Hands-On: The Command Line Learning how to use the command line You can combine most arguments. Try using both a and l after the ls command.
Hands-On: The Command Line Learning how to use the command line mkdir will create a new directory with the name you specify after the command. Use mkdir and then use ls to see the directory you created.
Hands-On: The Command Line Learning how to use the command line cd is used to change the current working directory. Specify the directory or directory path after the command. You can also use the tab key to auto-complete directory and file names in the console once some of it is typed.
Hands-On: The Command Line Learning how to use the command line Type the pwd command again to see how the current working directory path has changed.
Hands-On: The Command Line Learning how to use the command line Create and open a simple text file with leafpad myfile.txt This creates a text file called myfile.txt and opens it in a text editor called LeafPad automatically. Type a short message
Hands-On: The Command Line Learning how to use the command line Use the ls command to see the new text file. If you want to view the contents of the text file without opening LeafPad back up, use the cat command followed by the file name.
Hands-On: The Command Line Learning how to use the command line cp will copy your file to the specified directory. In this example you can type ls /home/pi to see the copied file.
Hands-On: The Command Line Learning how to use the command line rm will remove the specified file or files. Add the argument -v (verbose) to have an explanation of what is being done printed to the console.
Hands-On: The Command Line Learning how to use the command line To navigate back one directory use cd.. To return to your home directory use cd ~
Hands-On: The Command Line Learning how to use the command line Use rmdir -v stuff to remove that directory we created earlier in the lesson.
Hands-On: The Command Line Learning how to use the command line In case you used a command awhile ago and forgot it, or just curious to see into your past, you can use the history command. ~$ history
Hands-On: The Command Line Learning how to use the command line There is a useful operator called a Pipe that allows commands to interact with each other. It is typed by Shift + \(Key above Enter). It looks like:. Try using the pipe with: ~$ lscpu less lscpu shows CPU information, and less shows contents of files. Press Q to exit.
Hands-On: The Command Line Preparing to update the Pi sudo means Super-User DO and is followed by a command that requires the super-user to complete. apt-get is a package manager that you use to install, update, and upgrade your software. nano is a terminal text editor which is easy to use, but not the most powerful available.
Hands-On: The Command Line Preparing to update the Pi Type the following to update the repository the package manager searches for software. This does not update your system or Raspberry Pi. ~$ sudo apt-get update
Hands-On: The Command Line Preparing to update the Pi Now we are going to do some prep-work that is not necessary but will be fun later. This is using the package manager to install two commands we will use later. Type the following into your shell. ~$ sudo apt-get install cowsay ~$ sudo apt-get install fortune
Hands-On: Shell Script Preparing to update the Pi Now we are going to create our shell script. Start by creating a text file named update.sh by typing: ~$ nano update.sh
Hands-On: Shell Script Creating shell script Once you ve opened nano, type the following commands into the file: #!/bin/bash sudo apt-get update #updating repositories sudo apt-get dist-upgrade #updating the system sudo apt-get autoremove #removing old packages When everyone is done typing this in, we will move on. Keep nano open!!!
Hands-On: Shell Script Creating shell script The bulk of the update script is made, so let's enter a few more commands into it: echo #creating spacing fortune cowsay This uses the Pipe to have fortune s output shown through cowsay (shift + button above Enter)
Hands-On: Shell Script Creating shell script Now that we are done with our script, we can exit nano. Press Ctrl and X at the same time to save it, it will ask for confirmation, press Y then press Enter to save changes.
Hands-On: The Command Line Updating the Raspberry Pi Now that we ve made our shell script, let's take a look at it to verify everything is typed correctly. Your s should look like this one below. ~$ cat update.sh
Hands-On: The Command Line Updating the Raspberry Pi Try to run the shell script by typing the following: ~$./update.sh What happened?
Hands-On: The Command Line Updating the Raspberry Pi You need to set permissions for the shell script file. Type ls -l to see the permissions for the files in ss2015. R = read, W = write, X = execute Owner Group World rwx rwx rwx
Hands-On: The Command Line Updating the Raspberry Pi We want the file to have full permissions for the owner, and read/execute permissions for all others. We will use the chmod command to accomplish this. ~$ chmod 755 update-script.sh
Hands-On: The Command Line Updating the Raspberry Pi You can use ls -l to see that the file now has the proper permissions. -rwxr-xr-x
Hands-On: The Command Line Updating the Raspberry Pi Now you can run the shell script! ~$./update.sh If you are prompted to confirm any of your updates, just press Y and then press ENTER. Also, the update may create the oldconffiles directory.
Hands-On: PiCamera Controlling the Pi Camera Go ahead and take a quick picture with the camera: ~$ raspistill -v -o ss2017.jpg
Hands-On: PiCamera Controlling the Pi Camera This command will take a picture with the Pi Camera using the default settings. The picture will be called ss2016.jpg (unless you called it something else). The text that printed out are all options that we can control.
Hands-On: PiCamera Controlling the Pi Camera Now try using some of these options for the camera: -w 600 h 800 q 70 ifx cartoon
Hands-On: PiCamera Controlling the Pi Camera You can also take video with the camera: ~$ raspivid -o myvideo.h264
Hands-On: PiCamera Controlling the Pi Camera Use this command to see a small preview of your video: ~$ omxplayer --win 0 0 320 240 myvideo.h264 Or this to see it full size: ~$ omxplayer myvideo.h264
Hands-On: PiCamera Options for the raspistill and raspivid commands -o -w -h -sh -co -br -sa -vf -hf output file name (-o picture.jpg or vid.h264) width (-w 600) height (-h 800) sharpness, -100 to 100 (-sh 75) contrast, -100 to 100 (-co 50) brightness, 0 to 100 (-br 65) saturation, -100 to 100 (-sa 85) vertically flip image horizontally flip image
Hands-On: PiCamera Options for the raspistill and raspivid commands -q -ifx jpeg image quality, 0 to 100 (-q 70) image effects (-ifx negative, solarise, sketch, oilpaint, hatch, pastel, film, watercolour, emboss, blur, cartoon, and more!) There are many more options for the Pi Camera: https://www.raspberrypi.org/documentation/raspbian /applications/camera.md
Hands-On: Python and Games Using Python programming Python is a fun and easy way to learn programming language with wide use in the professional development world. If all went well you ve already been through python bootcamp so some of this will seem familiar.
Hands-On: Python and Games Using Python to manipulate games Raspbian comes with a few games pre-installed on the system. These games are written in Python. This means we can manipulate(mod) them!! The games are located on the Menu, and Games, then Python Games. Click OK to leave Audio as is.
Hands-On: Python and Games Using Python to manipulate games Wormy.py is like the traditional Snake game, where the goal is to eat the apples and not touch the edges of the screen and you can t eat yourself either. Try it out shortly as it is, and then we can start to mess with its code.
Hands-On: Python and Games Using Python to manipulate games Now let's change some things around. We can change the color and the speed of the worm to start out with. In a terminal, change directories to python_games (cd python_games). Then open up wormy s source using: ~/python_games/ $ idle wormy.py
Hands-On: Python and Games Using Python to manipulate games Scroll all the way down to the bottom. You should see a function (after word def) named drawworm. Inside This function, change DARKGREEN to BLACK, to change the outer color of the worm to black.
Hands-On: Python and Games Using Python to manipulate games 1. Now slightly below what we just changed, in the last line in the function, change GREEN to RED. 2. Then, in the drawapple function, where it says RED, change it to GREEN. Now we will have a red worm trying to eat a green apple.
Hands-On: Python and Games Using Python to manipulate games Click File then Save in IDLE, or press Ctrl and S at the same time to save the wormy.py file. Then, in the shell type: ~/python_games/ $ python wormy.py Now we can see our changes. It can be very easy to change little things around in games that are made with python. The next game we will look at is a little more complicated.
Hands-On: Python and Games Using Python to manipulate games If your game Python Games prompt is not longer open, go back to the Menu, Games, and Python Games again to bring up the prompt. Then select squirrel.py and press OK.
Hands-On: Python and Games Using Python to manipulate games squirrel.py is another game made with Python that we can manipulate. The goal is to eat the smaller squirrels and avoid the larger ones. As before, try it out like it is for a bit, then we can change a few things in the code.
Hands-On: Python and Games Using Python to manipulate games Now let s modify the source code. 1. Go back to your terminal and change directories to python_games ( ~$ cd python_games/) 2. Open the source with IDLE (~$ idle squirrel.py) 3. This is the source code for squirrel.py, like wormy.py, it may seem intimidating, don t worry too much about the details right now
Hands-On: Python and Games Using Python to manipulate games 1. To start out, let's change our MOVERATE to 15. 2. Then let s change INVULNTIME to 4. 3. Lastly let s change CAMERASLACK down to 80.
Hands-On: Python and Games Using Python to manipulate games 1. Save the file with Ctrl + S or by clicking File then Save. 2. Run squirrel.py by either the terminal window or the game prompt. GAME MENU PYTHON SQUIRREL
Hands-On: Python and Games Using Python to manipulate games You may have noticed you re quite fast now. It can be easy to modify these settings in some games this way. See if you can figure out how to make the game window just slightly bigger, don t make it any more than 200 larger than what the value already is. Before tinkering too much, you may think about copying squirrel.py and tinkering with the copy!
Raspberry Pi++ Thank you for your time! Feel free to use the remaining time to experiment and play around with your Pi. When you are finished, properly shutdown your Pi. Make sure it is completely off before removing power source!!