53
Getting Started with Raspberry Pi Otronicon: 18 January 2013 Developed by Wednesday, January 30, 13

Getting Started with Raspberry Pi v1.2

Embed Size (px)

DESCRIPTION

Getting Started with Raspberry Pi is one of 4 daily workshops put on by FamiLAB at Otronicon 2013.

Citation preview

Page 1: Getting Started with Raspberry Pi v1.2

Getting Started withRaspberry PiOtronicon: 18 January 2013

Developed by

Wednesday, January 30, 13

Page 2: Getting Started with Raspberry Pi v1.2

Welcome!

Getting Started with Raspberry Pi

Let’ get started!

This will be fun and you will learn a lot today.

Please follow instructions and only use the Raspberry Pi when instructed to do so.

Your Raspbery Pi should be running the latest Raspbian OS available here:http://www.raspberrypi.org/downloads

Okay... Let’s go!

Wednesday, January 30, 13

Page 3: Getting Started with Raspberry Pi v1.2

Let’s Play!

Getting Started with Raspberry Pi

For the first ten minutes today we will play. Go ahead and right click on the Python Games icon on the desktop and select open. Click OK on the audio dialog box.When we are working on the desktop today we will be opening files by right clicking. Opening files and programs can be a little slow to start from the desktop environment.

Also, if you double click multiple times, you will open several versions of the same program, so we’ll use the right click method to open things as opposed to the wrong click method today!

Select a game and play!

Wednesday, January 30, 13

Page 4: Getting Started with Raspberry Pi v1.2

Shut down!

Getting Started with Raspberry Pi

Shut down Python games by clicking on the close button (x) in the upper right corner of the Python Game Launcher window.

From the lower left corner of the desktop, left click and select logout from the pop up menu.

Click on the shutdown button in the LXDE window.

Don’t worry, we’ll be turning the Raspberry Pi back on in a few minutes after we discuss how to use it and look at some amazing examples!

Wednesday, January 30, 13

Page 5: Getting Started with Raspberry Pi v1.2

Why buy a Pi?The official Raspberry Pi Foundation description:

“The Raspberry Pi is a credit-card sized computer that plugs into your TV and a keyboard. It’s a capable little PC which can be used for many of the things that your desktop PC does, like spreadsheets, word-processing and games. It also plays high-definition video. We want to see it being used by kids all over the world to learn programming.”

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 6: Getting Started with Raspberry Pi v1.2

Eben UptonThe Raspberry Pi was built so that learning about computers and programming could be fun! Eben Upton, the inventor of the Raspberry Pi, used to have fun playing on and tinkering with computers when he was younger. Once he started teaching computing at the University of Cambridge, he noticed that students were no longer having fun coding with computers. They were just playing games rather than making them. To improve the situation, he got together with some friends, started the Raspberry Pi Foundation, and got to work creating a wonderful little computer that would be fun to program and play with!

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 7: Getting Started with Raspberry Pi v1.2

Eben Upton

CNN Moneywatch featured Eben Upton and the Raspberry Pi:

$35 computer can get kids coding

Eben Upton, the man behind Raspberry Pi, hopes to bring computer programming skills to a new generation.

http://money.cnn.com/video/technology/innovation/2012/12/10/t-raspberry-pi-kids-coding.cnnmoney/

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 8: Getting Started with Raspberry Pi v1.2

How is it used?The Raspberry Pi is used in a lot of ways!It runs on a Linux Operating System so…how it works depends on the linux build.

Some builds are very easy to use like Raspian “Wheezy” the one you are using here today, while others are customized for specific tasks. Some other examples are Raspbmc (a media center distribution), Risc OS, or Plan 9 from Bell Labs. This operational diversity is one of the benefits of the Raspberry Pi. But to get started and to remain consistent, we suggest using Raspbian Wheezy.

http://www.raspberrypi.org/downloads

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 9: Getting Started with Raspberry Pi v1.2

Look, up in the Sky!1) Project Black Sky:https://vimeo.com/user14504880

Project Black Sky is a science project done by a 13 year old that took a Raspberry Pi up to 85,000 feet in a weather ballon!

“The Raspberry Pi performed flawlessly during the mission. While other more expensive electronic devices in the capsule failed (the Canon camera and the Spot GPS), the Raspberry Pi never stopped functioning, even through extreme low temperature and pressure, and a violent descent.”http://www.projectblacksky.com/

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 10: Getting Started with Raspberry Pi v1.2

...in a SNES2) Ted’s Super Nintendo Emulated System:

This project uses the Raspberry Pi to replace the main logic and graphical components in a SNES. This is one of the more sophisticated projects done on a Raspberry Pi.

http://www.raspberrypi.org/archives/2984http://tinyurl.com/SNES-FamiLABhttp://tinyurl.com/snes-hackaday

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 11: Getting Started with Raspberry Pi v1.2

... as a Media Center3) An XBMC is an open source, cross platform media center originally designed to run on the Xbox. Many people are buying Raspberry Pi’s to use as dedicated media centers. There are many media center builds. We’ll demonstrate one here:

Play clip from “Push Pause Play” on openELEC RP.

http://wiki.xbmc.org/index.php?title=Raspberry_Pi

Push Pause Play may be downloaded here:https://vimeo.com/34608191

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 12: Getting Started with Raspberry Pi v1.2

...as a Camera Controller4) Lance R. Vick’s Raspberry Pi Camera Controller:

Lance made his camera rig at FamiLAB. Some of the FamiLAB members helped him cut the bracket out of MDF board on a CNC mill to make the camera mount. Other FamiLAB members helped him build the gears for the rig on their 3D printers! Lance uses an open source C library called gphoto. He also uses Python code to bind the C code into very useful software modules.

https://vimeo.com/50499145http://lrvick.net/http://gphoto.sourceforge.net/proj/

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 13: Getting Started with Raspberry Pi v1.2

...as a Server5) Raspberry Pi as a web server:

“How to” by Jeremy Morganhttp://tinyurl.com/piwebserver

Solar Powered FTP!:http://tinyurl.com/solarftpserver

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 14: Getting Started with Raspberry Pi v1.2

...Minecraft?6) Minecraft Pi Edition:

Mojang and the Raspberry Pi foundation announced Minecraft Pi Edition in November. It is due to be released soon!

http://www.raspberrypi.org/archives/2872

Keep an eye on the main Raspberry Pi foundation blog and forums to see what else is happening on the RP!

http://www.raspberrypi.org/

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 15: Getting Started with Raspberry Pi v1.2

Getting Started with Raspberry Pi

Raspberry Pi Model B

The B model is the first RP to come off of the production line. It has gone through at least 3 major revisions in the last year. Every revision has brought major improvement yet not affected the $35 price point.

Wednesday, January 30, 13

Page 16: Getting Started with Raspberry Pi v1.2

Getting Started with Raspberry Pi

Raspberry Pi Model A

The A model is scheduled to start shipping soon. Lacking an ethernet connector and having only one usb port allows the A model to ship at a price of $25. This simplified version will also require less power which will be attractive for some projects.

Imagine having a “B” model to use a developers machine, and using “A” models to deploy in projects.

Many projects will not require wired networks and a usb hub can provide many alternatives.

Wednesday, January 30, 13

Page 17: Getting Started with Raspberry Pi v1.2

Handling the RPThe Raspberry Pi was built to be used, but not abused. Every Printed Circuit Board (PCB) should be handled with care.Handle the RP only by the edges of the board itself.Avoid touching or holding any of the components on the board.

Rough handling can cause solder points to fail and may result in short circuits.

Experiment, but be careful with the GPIO pins as well. A great reference is the Raspberry Pi Users Guide:

http://www.raspberrypi.org/archives/tag/gareth-halfacree

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 18: Getting Started with Raspberry Pi v1.2

Order of operations:Connections to the Raspberry Pi include power, video, audio, network, usb and general purpose input and output (GPIO). It is important to make your connections at start up and shut down in a certain order.

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 19: Getting Started with Raspberry Pi v1.2

Order of operations:Power:As a general rule regarding connectors, power to a system should be the last thing to be connected and the first thing to be disconnected after a shutdown.

If power is supplied before other connections are made, bad things can sometimes happen.

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 20: Getting Started with Raspberry Pi v1.2

Order of Operations:Make connections in this order:

1) Operating System (SD card) 2) Audio Visual Display and audio3) USB peripherals Mouse, keyboard, hub, etc.4) Network5) GPIO (optional)6) Power

See the official Quick start guide here:http://www.raspberrypi.org/quick-start-guide

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 21: Getting Started with Raspberry Pi v1.2

Power up!Please plug the power cable back into your Raspberry Pi.

As your RP boots up, you will see a report streaming down the monitor. Eventually the boot sequence will finish and you will find yourself at the prompt! Don’t worry, this is a good place to be. A very good place!

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 22: Getting Started with Raspberry Pi v1.2

Let’s do an update.Enter the following text into the terminal:

sudo apt-get updateApt stands for Advanced Packaging Tool. It is used in the terminal to manage, download and install packaged files.

The Apt command you have just entered has updated and synchronized all of your Raspbian packages.

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 23: Getting Started with Raspberry Pi v1.2

Let’s find Joe.Let’s search for and install a useful program:Enter the following text into the terminal:

apt-cache search joeWhen you hit your enter key, you will see a list of resources pouring down your terminal. These are all of the resources that include the string “joe” in the current Raspbian build on the Raspberry Pi.Apt-cache search explores a repository of known software for the current Raspbian build of the RPs operating system. It requires a live network connection to locate the remote files.

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 24: Getting Started with Raspberry Pi v1.2

Let’s install JoeIf we see Joe, let’s get Joe. Joe is a programmer’s text editor that has syntax highlighting for Python and C. We’ll use Joe to make our first program on the Raspberry Pi!

Enter the text:

sudo apt-get install joe

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 25: Getting Started with Raspberry Pi v1.2

Let’s work with JoeOnce Joe is done installing, the prompt will show up in the terminal. When it does, let’s type in the following line:

joe helloworld.pyThe command above “calls” up the program Joe, and opens a new document. It also names the file helloworld.py. If the file had already existed, then Joe would have simply opened it. But since we just installed Joe, this single line of code just created and named a new file.

That’s pretty cool!

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 26: Getting Started with Raspberry Pi v1.2

Let’s make codeThis new file needs some content. Let’s type in the following in Joe’s editor section:

print “hello world”Next, type Ctrl+K to save the file and “X” to exit Joe.

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 27: Getting Started with Raspberry Pi v1.2

Let’s run codeAfter we have used Joe to write our Python code, we’ll simply use the built in interpreter to run the program. Type the following into the terminal:

python helloworld.pyThe program will run and return the string of text “Hello world” to the terminal.You have now written and run your first program on the Raspberry Pi.

Nice work!

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 28: Getting Started with Raspberry Pi v1.2

Utility timeBefore we move to the desktop environment and get deeper into coding, let’s learn a few more things about the terminal.Let’s look for devices! Enter the following:

lsusbLsusb lists (usb devices detected) This command shows all USB devices detected and gives pertinent data for each. With this information, you can search through “repositories” that contain software and firmware updates related to the devices.

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 29: Getting Started with Raspberry Pi v1.2

More utility timeLet’s have a look at which modules are running. Enter the following:

lsmodLsmod (lists modules) displays modules open in the linux kernel.What’s a linux Kernel? The kernel is the central program that manages the OS.A Shell is another program that is used to allow the user to communicate with the OS. The terminal that you are using now is a shell.

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 30: Getting Started with Raspberry Pi v1.2

One More Thing!Before we go ahead and leave the terminal, we shall gather one more set of resources and unpack them. Please enter:wget http://www.raspberrypi.org/game.tar.gzWait for the files to load.

tar xvfz game.tar.gzThis uncompresses the gzipped archive.Next, enter:cd game

and finally:

python snake.py

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 31: Getting Started with Raspberry Pi v1.2

Snake!DId you see that? It’s a snake! Made out of the letter “o.”

Use your arrow keys to pick up as many digits as you can.

Play Snake for a few minutes and take a short break!

when you are done playing Snake, enter:

Ctrl+Z

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 32: Getting Started with Raspberry Pi v1.2

Terminal At this point we have reached the end of our terminal session. We hope your fingers are not too tired, as we will be hacking and mousing around the LXDE next.

So, for your last terminal command please type:

startxinto the terminal and then quickly remove your hands from the keyboard!

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 33: Getting Started with Raspberry Pi v1.2

Desktop SessionWhen the desktop environment loads, please do not open any programs!

The Raspberry Pi can be very slow in the desktop environment. Many linux applications run slow in this environment, so in order for you to be able to operate follow instructions!

Don’t click on any icons yet!

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 34: Getting Started with Raspberry Pi v1.2

Shortcuts!Overview:

Scratch - Block based programming for kids.IDLE and IDLE 3 - That’s right - 2 versions of Python!Midori - Default web browser.PiStore - The new place to get RP stuff.Debian Reference - The manual that hackers read.Wifi Config - A gui wifi set up programLX Terminal - A windowed version of the terminal.Python Games - A python game arcade.

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 35: Getting Started with Raspberry Pi v1.2

Scratch Demo!Let’s right click on the Scratch icon on the desktop!The cat is named “Scratchy!” She’s a pretty cool cat.

Wait for it! The LXDE may take a few seconds to load things on the RP processor.

When Scratch opens, click on the control button in the upper left window (the block palette) to call up the control blocks.

Announcement: There are FamiLAB Scratch workshops every morning at 10:30 during Otronicon right here in this room!

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 36: Getting Started with Raspberry Pi v1.2

Control BlocksDrag the “When space key pressed” object to the scripts window.

The Scripts window is the center window.

Place the block near the top.

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 37: Getting Started with Raspberry Pi v1.2

Audio BlocksClick on the sound button in the block palette to call up the sound blocks.

Drag the “play sound meow” block onto the stage below the command block. Drag the sound block until it attaches like a puzzle piece to the command block.

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 38: Getting Started with Raspberry Pi v1.2

Motion BlocksClick on the Motion button.

Drag either of the “Turn 15 degrees” blocks so that it connects to the bottom of the sound block.

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 39: Getting Started with Raspberry Pi v1.2

Spin Scratchy!Click on the space bar!

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 40: Getting Started with Raspberry Pi v1.2

Stop Scratchy!Scratch is used to teach young students basic programming structures.

It was developed at the Lifelong Kindergarten Group at the MIT Media Lab.

Quit Scratch, and don’t save!Q. Why quit Scratch? A. We have to get that cat out of here before the giant snake comes back!

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 41: Getting Started with Raspberry Pi v1.2

LXTerminalWe are going to run some more code in python. We have already completed the “Hello World” program back in the terminal using Joe.

Now we are going to run python from the LXTerminal

Go ahead and open the LXTerminal by right clicking on the desktop icon and selecting open.

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 42: Getting Started with Raspberry Pi v1.2

ListAt the prompt, type in:

ls(That’s a lower case L and S!)and hit return.

“ls” lists the files and directories located within the current directory level that you are accessing in the terminal.

We jsut used “ls” to get oriented in the terminal.

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 43: Getting Started with Raspberry Pi v1.2

NavigateAt the prompt enter

cd gameand hit return.

The CD command tells the terminal to change directories and open the game directory.

Entering “ls” again will show us the contents of the game directory.

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 44: Getting Started with Raspberry Pi v1.2

InterpreterIn the game directory you should find snake.py along with a few other python files.

Enter

python snake.pyand hit return.

You have invoked the python interpreter by typing python. Typing snake.py lets the interpreter know which file to load.

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 45: Getting Started with Raspberry Pi v1.2

Snake!Use the arrow keys on your keyboard to guide the snake!

The space bar will restart the game.

Play a few rounds and then exit Snake.

Enter Control + z to exit snake.

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 46: Getting Started with Raspberry Pi v1.2

Hack it!Let’s use Joe to open the .py file and look inside!

Type the following into the terminal:

joe snake.pyHit return. You should see the snake.py fileUse your arrow keys to navigate down until you find the following text:

def snake(scr);This is the code that defines the snake.

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 47: Getting Started with Raspberry Pi v1.2

Yellow Snake!A few lines below the def snake(scr);

change the line that reads:

curses.init_pair(1, curses.COLOR_RED,...

to

curses.init_pair(1, curses.COLOR_YELLOW,...

You may have to enter Shift + S to unlock the text file in Joe. If so you will be prompted when you enter the text.

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 48: Getting Started with Raspberry Pi v1.2

Longer tail!Continue to scroll down the code with the arrow key.

Find the text for the tail:

# empty tail

tail = []length = 10Go ahead and change the length from 10 to a number less than 30.

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 49: Getting Started with Raspberry Pi v1.2

Save it and Exit!Type the following into the terminal:

Ctrl + K and then DThis will save the changes to the file.

Enter

Ctrl + K and then Z

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 50: Getting Started with Raspberry Pi v1.2

Save and Run it!Re-run the script by entering:

python snake.pyDid it work?

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 51: Getting Started with Raspberry Pi v1.2

Thank You!We’ve been through a lot together. Scratchy asked me to thank you for saving her from the large snake!

We’ll spend the rest of this session looking at the examples and exploring the Raspberry Pi. Feel free to play with python or explore the examples with us!

Don’t forget to come visit us at FamiLAB.

Getting Started with Raspberry Pi

Wednesday, January 30, 13

Page 52: Getting Started with Raspberry Pi v1.2

Workshops!Otronicon FamiLAB workshop schedule:

10:30 a.m. - Scratch: Game Programming for Kids

12:30 a.m. - Introduction to Soldering - Build a Game

3:00 p.m. - Getting Started with Raspberry Pi

5:00 p.m. - Introduction to Arduino

For information about workshops and more:http://familab.org/

Wednesday, January 30, 13

Page 53: Getting Started with Raspberry Pi v1.2

Thank You!Learn more about FamiLAB here:

http://familab.org/

Wednesday, January 30, 13