21
RMOUG QUARTERLY EDUCATION WORKSHOP Family Coding Day, August 7 th , 2015 Elitch Gardens, Denver, CO

RMOUG QEW Family Coding Event- Raspberry PI

Embed Size (px)

Citation preview

RMOUG QUARTERLY

EDUCATION WORKSHOP Family Coding Day, August 7th, 2015

Elitch Gardens, Denver, CO

HARDWARE REQUIRED

Raspberry Pi, (any version)

Pibrella board, (this can be done without, but

requires the motor to be wired directly to the pi,

which is definitely not as easy… )

Accessories- monitor, keyboard, mouse and

power supplies

HOOKUP AND STARTUP YOUR RASPBERRY

PI

Ensure the Pibrella is already installed, if not,

the next slide will cover and handouts are

available from Kellyn.

YOU MUST protect your HDMI port from the

Pibrella board. If you don’t have a buffer,

(cardboard, foam, etc.) between the two, cut out a

piece of cardboard or similar to stick between the

metal contacts on the bottom of the pibrella

board and the top of your HDMI port.

INSTALL PIBRELLA, (IF NOT DONE)

https://pypi.python.org/pypi/Pibrella

ART PROJECT TODAY

Using a LIGHT art project, we’ll attach

the small item to a motor and control it

code.

Can be a character that will dance in

circles, or animal/flower that spins.

A flyer that will be launched

The art must attach to a small wooden

“toothpick” or a flat stand.

What you create is UP TO YOU!

THIS PROJECT WILL WORK WITH DIFFERENT

VERSIONS OF PYTHON…BUT

Python3 will allow you to utilize all features of

the Pibrella.

Connected to the wifi, install this libraries and

then re-install the pibrella with new lib files:

>sudo apt-get install python3-pip

>sudo pip-3.2 install pibrella

AGAIN- THE GOAL OF TODAY’S

PROJECT

Create a Rotating Project of YOUR OWN design

with code-

Using a simple motor and provided supplies.

Be creative and build what you want that will

attach to a base or wooden stick.

Think about the different uses for this project.

Think about enhancements for your project while

you’re working with it!

ENTER TIMING FIRST!

Once the wheel and motors have been assembled

and attached to the Pibrella, it is time to program

them to do what they were built for... turning!

On your Raspberry Pi:

Open a terminal window and type vi

<file_name>.py and press Enter on the

keyboard. This will open a blank text editor file

in which you can type your code.

IMPORT THE LIBRARIES

Begin your code by importing the Pibrella Python

library needed to control the motor by typing:

import pibrella

Underneath, import the time library in the same

way so that you can add time delays to your

program:

import time

CODING AFTER TIME ENTRY

Leave a blank line of code by pressing Enter.

Underneath, you can now write the sequence of

instructions to control the attached motor:

pibrella.output.e.on() time.sleep(10)

pibrella.output.e.off()

To exit out of the program, type in:

quit()

Press Esc :wq to save and quit.

CODE SHOULD LOOK LIKE THIS

import pibrella

import time

<enter break line in code>

pibrella.output.e.on() #turn on

time.sleep(10) #spin for 10sec

pibrella.output.e.off() #turn off

quit()

HOOK UP YOUR ENGINE TO THE PIBRELLA

Your Setup should

look like the

following:

Wires red to

posistive, black to

negative.

Most likely hooked

up to D, but could

be to E, (top right

of red button for a

few)

ATTACH YOUR ART PROJECT AND RUN

Now that you tested successfully, add your art

project with whatever type base to the motor and

run again.

RUN THE CODE

Python

sudo python –i <file name>.py

Python 3

sudo python3 <file name>.py

Now this just runs the engine as soon

as you execute it and no control

outside of that.

MORE ADVANCED BUTTON CONTROL

import pibrella

import time

<line break in code>

while true:

<4 spcs>if pibrella.button.read():

<indent 8 spcs> pibrella.output.e.on()

<indent 8 spcs> time.sleep(0.01)

<indent 8 spcs> pibrella.output.e.off()

<indent 8 spcs> pibrella.output.e.on()

<indent 8 spcs> time.sleep(0.02)

<indent 8 spcs> pibrella.output.e.off()

<indent 8 spcs> break

Save File

RUN THE CODE

Python

sudo python –i <file name>.py

Python 3

sudo python3 <file name>.py

NOW, push the button to execute the

spin!

How did you spin timing and motor power

combination do?

Do you need to add or subtract time to your

project?

LAUNCHING “FLYERS”

Attach your Flyer, (spinner or other design) to

your engine.

Ensure it’s stable enough to spin, but not too

tight that it won’t launch.

CODE THE FOLLOWING

import pibrella

import time

<line break in code>

while true:

<4 spcs>if pibrella.button.read():

<indent 8 spcs> pibrella.output.e.on()

<indent 8 spcs> time.sleep(30)

<indent 8 spcs> pibrella.output.e.off()

<indent 8 spcs> break

quit()

Save File with name “launch_flyer.py”

RUN THE CODE

Python

sudo python –i launch_flyer.py

Python 3

sudo python3 launch_flyer.py

The current time for the spin is 30 seconds-

Is this too much? Does the engine spin long after

the flyer has launched and you need to decrease

it?

Is it not long enough? Increase the time from

time.sleep(30) to time.sleep(45) to see if that is

enough.

ENHANCING YOUR PROJECT

How would you build out your project?

What kind of additional coding would you add?

Would your project be cooler if you added:

Sound?

Light?

Additional Motors?

Art?

HAVE QUESTIONS?