RPi GPIO + Scratch 2.0

In this activity we will use Scratch 2.0 to light LED bulbs and sense a button push.

Begin by lighting a LED bulb with an always on 3.3 v pin and a resistor. If this isn’t working, check your connections or see the post on getting started with GPIO. Change the pin for the 3.3 volt to pin 17 on the GPIO board and open Scratch 2.0.  Follow the steps outlined below.

 

image_pdfGenerate PDFimage_printPrint

RPi Intro to GPIO

On top of the Raspberry Pi are a row of pins that can be given specific tasks to collect or send out data. These are called GPIO (General Purpose Input Output) pins and can be hooked up to a variety of components that either take in or send out data.

These pins are a physical interface between the Pi and the outside world. At the simplest level, you can think of them as switches that you can turn on or off (input) or that the Pi can turn on or off (output). Of the 40 pins, 26 are GPIO pins and the others are power or ground pins (plus two ID EEPROM pins which you should not play with unless you know your stuff!)

It helps to begin by thinking of how a basic circuit works with an LED, a resistor, and a switch.  Note the long tail on one side of the LED connected to the positive side of the battery.  LED bulbs function directionally.  The resistor slows down the amount of current reaching the bulb.   The switch simply is open or closed, allowing current to flow.

The breadboard is a tool that is used to help connect up wires without interacting.   This diagram with the top removed shows how rails connect so that electricity can flow without interacting.

Follow along with the video to connect up a simple circuit with an LED and a button.

image_pdfGenerate PDFimage_printPrint

3D Printing: CAD – Design your thing!

Overview

3D Printing & Computer Aided Design (CAD) will allow students to discover the potential and limitations of 3D Printing through a build intensive design project. Students will learn how to use CAD software such as AutoDesk, SolidWorks, etc. An excellent opportunity for anyone interested in prototyping, creating artworks, or product customizations.

TinkerCAD

TinkerCAD is a simple, online 3D design and 3D printing app for everyone. TinkerCAD is used by designers, hobbyists, teachers, and kids to make prototypes, artworks, and Minecraft models!

TinkerCAD Website

Next Lesson: Slicing your CAD model and sending files to the printer.

image_pdfGenerate PDFimage_printPrint

RPi Minecraft + Networking

In this activity students will learn about networking on the Raspberry Pi using a popular pre installed game called Minecraft.

I use this opportunity to speak about the human networking that happens when a team of individuals work together. Minecraft is known as a sandbox game where blocks can be created or destroyed.   Many students have played Minecraft in a way that players attack each other known as player vs player, or PVP. Establish that this is not the kind of environment that is being created.  Students will work together to build something cool.

Establishing a level of experience with Minecraft is a good way to start.  I like to group advanced users with each other and beginning users together.  Each group needs to brainstorm, plan and build something in a specified amount of time.  I usually give students between 15 and 30 minutes and encourage them to stretch to collaborate.   Groups can range in size from 2 – 5 players.  One student will “host” the world on their device and will need to identify their I.P address to share with partner players.

Immediately upon opening up Minecraft students given an option to join game or create a new world.  If they create a world, it exists on their pi, if they join a world they need to know who’s world they are joining.  This becomes a process of students calling out and identifying who’s pi is at which IP address.  The IP address can be found by hovering over the Wifi signal in the upper right corner of the screen.

Students who have never used Minecraft will need assistance learning to move within the world, to place a block and to change their inventory.  These students should focus on building something very simple.  Advanced students might build a castle or a huge underground maze.  At the end of the build time, join into the world on your Pi and let one of the students from each group share what they created.

If students wish to save the world they are working on, they will need to navigate to the .minecraft folder from and drill down to the folder of the world they were playing in.  The following video goes over how to do this.

image_pdfGenerate PDFimage_printPrint

RPi Scratch Reaction Time

Programing is about giving a computer a set of instructions. Instructions can be given in a text based format or in a visual format. Scratch is a visual programing language that allows a user to easily create interactive stories, games, and animations by dragging specific bits of code to an area and running the program. To get an idea of what Scratch can do, share this overview video.

Scratch can be run in a browser on a regular computer but it is a bit resource intensive to run on a Pi. Two versions come installed on the Raspberry Pi, the classic version labeled Scratch, and an updated version Scratch 2.0.  Scratch 2.0 tends to be a bit less responsive, however it has some very cool features that are explored in a later lesson.

Have students open Scratch (not scratch 2) from the program menu and follow along with the tutorial below.

When students have been able to do some basic functions in a Scratch environment introduce them to this project creating a reaction time game.

Continue reading

image_pdfGenerate PDFimage_printPrint

RPi: Editing Text files and Python Scripts with Raspbian

Getting Started

There are a myriad of ways to edit text files and code built into the Raspbian distribution; several even inside the terminal. But here we will cover some of the easier to use graphical programs.

It’s important you know your way around the terminal before continuing, please see the terminal tutorial -> here

Editing config files with leafpad

Leafpad is a lightweight notepad-like text editor that is bundled with Raspbian; we will use it here to edit simple config files in the file system.
For example the led ring tutorial directs us to edit the /boot/config.txt and comment out some lines.
To do this navigate to the /boot/ directory in the terminal; and then run ‘sudo leafpad config.txt’, this is similar to other commands you have seen taking a path as an argument, the important difference is the ‘sudo’ prefix which tells the terminal to run this command as a ‘super user’. This allows us to overwrite important system files and access gpio pins ect. You’ll have to use it often but you should still be careful.

We get an editor window like notepad on windows, we can insert a ‘#’ before dptparam to comment it out, and then save with control s
after exiting the editor you will regain control of your terminal.

Editing and running python scripts with Thonny

Next we can use a slightly complicated editor, Thonny is specifically for python ‘.py’ files and has some features that make debugging scripts easier.
Thonny can be found in the menu in the top left corner, or again opened from the terminal with ‘sudo thonny’.
Most scripts accessing the GPIO require sudo powers to work correctly, so its best to get used to running it as sudo.
You open a file to edit by navigating to it in the thonny gui; like notepad on windows.


We can enter python scripts line by line into the main window, and at any moment run our script with F5 or the gui button (green arrow).
Here is what it looks like to run a simple program inside thonny.
note the output in the lower window, this is the result of pressing F5 or the run button

image_pdfGenerate PDFimage_printPrint

RPi Sense HAT+Minecraft

The Sense HAT was developed by the folks at Raspberry Pi as an add on board that contains a number of sensors and a LED display. In this lesson we can demonstrate how to use the Sense HAT in conjunction with Minecraft to visualize real world data and control the LED Screen.

I use this lesson primarily to get students excited about the connection between a sensor and the way that we can visualize data through Minecraft.  This worksheet from the folks at the Raspberry Pi foundation is an excellent resource. In the latter portions of the lesson it goes into methods of collecting data from the Sense HAT and displaying it within the Minecraft world.

https://www.raspberrypi.org/learning/exploring-space-with-minecraft/

Follow along with the Sense HAT installation and the first several worksheets of this project.

image_pdfGenerate PDFimage_printPrint

4. Github Intro

Github is known as a repository for cool programs that can be used in all sorts of ways on your Pi. In this lesson we will learn how to install programs from Github using the terminal.

First lets install a program that can do screen captures. Something that is handy when students have created something amazing in their Minecraft world.

Lets follow the instructions for taking screenshots provided by Martin O’Hanlon.

http://www.stuffaboutcode.com/2016/03/raspberry-pi-take-screenshot-of.html

Here is a video going through the process.

Students will be really excited when they learn to download programs that can run within their Minecraft world. Lets go back to Martin’s API tutorial and have students select one of the first three items, clock, cannon, or snake video game.

http://www.stuffaboutcode.com/2013/04/minecraft-pi-edition-api-tutorial.html

In each of these examples, there is a section of code that should be copied into the terminal. When enter is pressed on the keyboard, a bunch of code will appear and a new program file will be placed in the home directory on the Pi

Have students navigate to the file folder and open the file with the .py extension by right clicking on the file and selecting open with python 2 from the drop down menu.  If the program is run while Minecraft is open it will place an exciting new feature in the Minecraft world. This will hopefully trigger a desire to try downloading other python programs to modify their Minecraft worlds.

image_pdfGenerate PDFimage_printPrint

RPi: Terminal + Python Intro

Navigating with the terminal

Like on windows or any other computer, files in Linux are arranged in a hierarchical directory structure; meaning starting at root there is a sort of tree of folders containing files and other folders.
The terminal has a concept of ‘working directory’ ; using the metaphor of navigating an office building this is simply what room the terminal is in. If you use a command to list files it will look around the current directory and return you a list of files currently visible.

After opening a terminal with the icon in the upper left you will be confronted with something like this (but most likely with a different color-scheme and font)

upon opening terminal

We can now use the ‘pwd’ print working directory command to see what directory or room we are in; the result is returned to us in simple text:

Now we know what directory we are in, but we still don’t have any idea what accompanies us; for that we can use ‘ls’ list command; which returns us a list of files and directories in our working directory.

I have added a file here to demonstrate that files are coloured differently to directories.
Now we can try entering one of the directories listed, for this we can use the cd change directory command. This command takes a ‘path’ as an argument. Paths are just strings of text describing the location of a directory or file; pwd returns the ‘path’ of our current working directory. Another path could be ‘/home/pi/Documents/’. Paths can also be relative to our current location, so if our current working directory is ‘/home/pi’ then ‘Documents’ would be a valid path.

Most of the time you will use relative paths, they are shorter and easier to work with too.
To navigate to a directory relative to our own we first use ls to see what our options are.

Then we use the cd command with a path to enter one, we’ll use the python_games directory because we know ahead of time its not empty: cd python_games

Another valid and equivalent command would again be cd /home/pi/python_games

Once we enter the directory we can use the ls command to orient ourselves.

We can see dozens of files and no directories, here we can practice running and terminating a python script.

Running and Exiting python scripts

Just like the cd command there is a python command pre-installed that takes a python script as an argument, python scripts are files with a .py extension.
To run a game choose any file with a .py extension and use it as an argument to run python.

To exit the program at any time use the Control-C keybind, this sends a kill signal to the python process we just started; this will also be used regularly when you want to exit python scripts you are testing.

Next we will navigate back home using terminal commands and create our own directories and files.
Apart from relative and absolute paths that we already covered there are some more special cases, for example the ‘..’ path refers to the directory one level above our current working one. This makes it easy to navigate upwards out of whatever area we entered.
To navigate back to the home directory use ‘cd ..’, and then use ‘pwd’ to check if you made it back.

Finally we will create our own directory and some files to populate it. Just like the cd command there exists a mkdir command which again takes a path. This command simply spawns a folder with our chosen path, for example..

At first we have no indication that our command did anything, but a simple ls will reveal all.

We don’t want to spam files all over our home directory, so before we start making them lets enter our directory with cd.
The command for creating files in the terminal is called touch, it takes a path and creates an empty file whereever we tell it too, or if the file already exists it just ‘touches’ it; updating its last modified date ect.

Now that we are safely in our own directory we can try it out:

There does exist a rm command to remove files, but it can be dangerous if you accidentally delete some script or important document you were just working on!
as you can guess it takes a path as its argument; here we can see it at work.

Last of all we can clean up after our empty directory, navigate back to the home using cd, and then use the sister to rm, rmdir to remove our directory.

Conclusions

In this tutorial we reminded ourselves what directories and files are, how to find our current working directory in the terminal, how to list files and folders, how to enter and leave directories, how to run and exit python scripts, and how to create and delete files / folders.

image_pdfGenerate PDFimage_printPrint

1.1 Box Build

If you are setting up the box for the Raspberry Pi Kit, here are the steps you need to follow.

Step 1: Glue the bottom of the box together. Use a tiny bit of glue on each tab. Let the box dry for at least 2 hours.

It should look like this:

Step 2: Screw the hinges

Step 3: Screw the hinges on to the top part of the box with the screen attached.  Be sure to insert the HDMI cable and the power cable for the screen through the appropriately sized holes.

Step 4: Put the side panel on the box lid.

Step 5: Put the top of the box on.

Step 6: Put the post screw with the wooden hinge on the side panel, make sure to align with the hole in the base.

Step 7: Fit the side panel with the hinge on the box and do the same thing on the other side.

Step 8: Connect the wooden hinge to the box with another post screw

Step 9: Put all the screws and square nuts on the sides of the box

And your done!!

image_pdfGenerate PDFimage_printPrint

1. Getting Started

In this lesson students will learn about the Raspberry Pi computer and the components provided in the kit.  Having a completed kit as an example will be helpful but not necessary.  Begin by showing this short video about a raspberry Pi.

If the boxes have not been assembled have students refer to this post for building instructions.

The kits include these parts:

Raspberry Pi 3 + support
  • Raspberry Pi 3
  • Micro SD card 16GB – With Raspbian
  • Micro USB Cable
  • USB Power Supply 3 Port
Screen / Interface Parts
  • LCD 7″ 1024×600 with speakers
  • 30CM HDMI Cable
  • Keyboard – wired compact – full size keys
  • Mouse – wired retractable cord
Accessory Parts
  • RPi Compatible 5MP Camera – Not official
  • RPi GPIO Reference Card
  • Jumper Wire 20pcs 20CM 2.54mm M-F
  • Jumper Wire 20pcs 20CM 2.54mm F-F
  • Jumper Wire 20pcs 20CM 2.54mm M-M
  • Alligator clip jumper 2 pieces random color
  • Breadboard 400 holes
  • 5x LEDs 5MM
  • 4x Push Buttons – Breadboard Compatible
  • 20x 100R Resistor
  • 20x 330R Resistor
  • 20x 470R Resistor
  • 20x 1K Resistor
  • 20x 10K Resistor
  • 20x 100K Resistor
  • Piezo passive speaker
  • PIR infrared motion sensor
  • Ultrasonic Distance Sensor
  • DHT11 humidity + temp sensor
  • RGB LED Ring 12 pixels – WS2812
  • 2x 9g Servo
Growth Mindset
  • 2x Brushbot kit
Packaging

The video below introduces the various components and describes how to to power on the Raspberry Pi computer.

image_pdfGenerate PDFimage_printPrint

RPi Python: LED Ring Clock WS2812

Prereqs:

Have Raspbian Stretch installed, running, and connected to the internet.
You should refresh on how to easily edit files and navigate the filesystem using a terminal in these tutorials:
Terminal Intro
Editing Files Intro

Next some configuration,
To correctly output PWM to control the LED ring we first need to disable the native Raspberry Pi soundcard, to do this navigate to /boot/config.txt and comment out the line ‘dtparam=audio=on’

# Enable audio (loads snd_bcm2835)
#dtparam=audio=on

^ so it looks like this.

Next step is to install some utilities we will need for setting up our led control libraries and the python environment to talk to them; open a terminal and enter

apt-get install gcc make build-essential python-dev git scons swig

this installs some compilers and utilities we will use in the next step

Next navigate to the folder where you want to setup your LED script in a terminal, use ‘mkdir’ to create a new directory if you want; here we will download the library using git
For more help on navigating and creating directories from within the terminal, see this article -> click here

git clone https://github.com/jgarff/rpi_ws281x

Enter the new rpi_ws281x directory and use the ‘scons’ utility we installed earlier to start building the library into something we can use:

sudo scons

Next enter the python directory, and run the setup and build scripts:

sudo python setup.py build install

Hardware:

First off here is a link to the finished project as a reference
To test it, download the file, rename to clock.py, and run as sudo python clock.py

Next to writing the actual script itself…
The first step is a bunch of boilerplate, like telling our library how many LEDs we have and what pin to use ect.
We start off by importing the libraries to control the leds, and read the date and time from the system

from neopixel import *
import time
import datetime

next are the constants that tell which pin to use, and which kind of led ring we are using

LED_COUNT          = 12          # Number of LED pixels.
LED_PIN            = 18          # GPIO pin connected to the pixels (18 usesPWM!).
LED_FREQ_HZ        = 800000  # LED signal frequency in hertz (usually 800khz)
LED_DMA            = 10  # DMA channel to use for generating signal (try 10)
LED_BRIGHTNESS = 10         # Set to 0 for darkest and 255 for brightest
LED_INVERT         = False   # True to invert the signal (when using NPN transistor level shift)
LED_CHANNEL        = 0           # set to '1' for GPIOs 13, 19, 41, 45 or 53
LED_STRIP          = ws.WS2811_STRIP_GRB   # Strip type and colour ordering


strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL, LED_STRIP)

As a brief overview, the important ones for us are:
LED_COUNT: the number of LEDs to try and address, if you have a bigger led ring than normal you might change this; 12 is for the one we gave you

LED_PIN: here we use 18; other pins might be tricky so its probably best to stick with 18

LED_BRIGHTNESS: on full brightness the leds can be super super bright, so we lower it all the way down to 10. Wear sunglasses if you turn it up

Finally with strip we setup the strip using all the constants we just defined.

Logic:

Now we can actually start writing functions and logic for our program. Python scripts usually execute straight from top to bottom in sequential order; but we can essentially jump around our control flow using functionsFunctions take arguments, do things based on these arguments and then exit back to where they were called.

We’ll start with utility functions that will make controlling the ring easier later, before we write the actual clock part. (remember to use tabs for indentation levels).
We start with a function to clear all the leds, essentially turning them all off

def clear (strip):
 for i in range(LED_COUNT):
     strip.setPixelColor(i,Color(0,0,0))
     strip.show()

Let’s go through this function line by line: First we define the function and give it a name ‘clear’, followed by a list of arguments it takesLet’s go through this function line by line:

def clear (strip):

 Next we start a loop to address all the leds, this pattern will appear alot so pay attention!

for i in range(LED_COUNT):

Notice we use the LED_COUNT variable we named earlier, the loop starts i at 0, and then runs its block over and over until ‘i’ reaches the LED_COUNT value

strip.setPixelColor(i,Color(0,0,0))

Here we actually start setting the led colors, we gave this function an argument called ‘strip’ and here its accessing some functionality that the ‘strip’ object holds. In this case ‘setPixelColor’. The ‘setPixelColor’ function demands a pixel number and a color as its arguments so that’s what we give it. We create a color out of R G B values (red green blue) using the ‘Color’ function.

strip.show()

Finally we actually get the leds to update on the physical ring.

And that’s the end of our first function!

Next we’ll make a ‘fill’ function which does almost the same thing; except instead of setting all the leds to off it’ll set them to a color we give as an argument.

The new function will follow the same basic pattern as our old one.

def fill (strip, pixel, color):
 for i in range(pixel):
    strip.setPixelColor(i,color)
    strip.show()

If you compare this and the old function side by side it should be easy to see how they match up and differentiate.

Now we can actually test out our functions and make sure they work.If you compare this and the old function side by side it should be easy to see how they match up and differentiate.

On the line below our functions we can start writing code that will actually execute.

strip.begin()
fill(strip,12,color(255,255,255))
time.sleep(.5)
clear(strip)
fill(strip,12,color(255,0,255))
time.sleep(1)
clear(strip)
strip.begin()
fill(strip,12,color(255,255,255))
time.sleep(.5)
clear(strip)
fill(strip,12,color(255,0,255))
time.sleep(1)
clear(strip)

We’ll go over the first few lines to get an idea of how it works:

strip.begin()

First we use the ‘begin’ method on our strip to get it ready for any commands

fill(strip,12,color(255,255,255))

Next we actually call our fill command from earlier, sending it the strip, the number of pixels we want, and a color.

time.sleep(.5)

Next we wait for half a second so we get a chance to admire our work.

clear(strip)

We repeat the process again for another flash, this time a different color.  Of course it would be more impressive if it flashed more than twice, but we don’t want to just keep copying and pasting the same function calls over and over either. And eventually we want our clock to be running indefinitely not just for a few seconds; so we will setup an infinite loop.

strip.begin()
while(True):
 fill(strip,12,color(255,255,255))
 time.sleep(.5)
 clear(strip)
 fill(strip,12,color(255,0,255))
 time.sleep(.5)

When running this script, you can use Control-C to interrupt and exit the program.A while loop repeats everything in its block until the statement we give it isn’t true; ‘True’ is always true so in this case it just loops forever.

Otherwise it’ll just keep flashing your led ring forever!.

Now we have some nice utility tools setup we can actually start writing the clock itself.

First we need to get the time! Luckily we imported the time library earlier.

So start off by erasing our While loop from earlier, because we’ll be writing another one.

strip.begin()
while(True):
 now = datetime.datetime.now()
 time.sleep(.5)

Below our other two functions but above our while loop we’ll put our clock function.Here we fill a variable called ‘now’ with the current time every .5 seconds, but we don’t do anything with it yet. For that we need another function.

def clock (strip, now):
 hours = now.second%2
 hourPixel = (now.hour % LED_COUNT) + 1
 minutePixel = (now.minute / (60/LED_COUNT) % LED_COUNT) + 1

 hourColor = Color(255,0,0)
 minuteColor = Color(0,0,255)

 if (hours):
    fill(strip,hourPixel,hourColor)
 else:
    fill(strip,minutePixel,minuteColor)

hours = now.second%2This turned out to be a pretty simple function so ill go over it section by section.
The most criptic part is the first line:

This is where we work out if we’ll show the hour or the minute hand; the modulo operator is explained in more depth below but basically we are testing if the time in seconds is an even number or not. If it it’s even we set hours to 0 (false) and if it’s odd we set hours to 1 (true).

Next we calculate the hour and minute pixels; which again is explained in the last section below.

hourColor = Color(255,0,0)
minuteColor = Color(
0,0,255)
Here we set the colours we want to use for the hour and minute hands using RGB values

if (hours):
fill(strip,hourPixel,hourColor)
An if statement runs its block of code only if the expression its given is true, the hours variable is set if the seconds are even remember, so every other second we choose to display the hours or the minute hand.
Then we call our fill function from ealier with the desired results.

Finally we put our clock function in our infinite loop from earlier, and our clock is done!

strip.begin()
while(True):
 now = datetime.datetime.now()
 time.sleep(.5)
 clock(strip,now)

And here is the final project again to help fix any errors in your own:Remember to run the script as sudo, like at the start with the strandtest.py example!

https://github.com/keptan/T3RasberryClock/blob/master/alternating_clock.py

Calculating hourPixel and minutePixel:


Looking back over our long clock() function, the most complicated part is the ‘hourPixel’ and ‘minutePixel’ logic; so i’ll go over them in depth here.

hourPixel = (now.hour % LED_COUNT) + 1

hourPixel is a variable which holds a number, the number being which pixel we want to illuminate upto to represent the hour hand of the clock.
We start off with the hour in a 24 hour clock format from now.hour

So if it was 2pm the now.hour would equal 14.

To emulate a 12 hour analog clock we need to convert 14 down to 2.

The ‘%’ operator called ‘modulo’ returns the remainder after doing an integer division; this is very useful for testing if a number if perfectly divisible (the remainder would be zero) and for creating ‘circular numbers’ which never pass a certain value.

If we look test out the modulus operator we can see the pattern:

1 % 12 == 1

2 % 12 == 2

3 % 12 == 3

11 % 12 == 11

12 % 12 == 0 (perfect divisible)

13 % 12 == 1

14 % 12 == 2

So if we enter ‘13’ hours (1pm) into our modulo operator we get a nice conversion straight to 12 hour time (1).

Because our led ring is addressed from 1 instead of 0, (lighting up the 0th led doesn’t work with this library) we add 1 to the result.

So a straight conversion from 13 hours to 1pm, turns into the second led on the ring.

Leaving us with our final algorithm

hourPixel = (now.hour % LED_COUNT) + 1

The math works in the same way but with slightly more complicated variables for the minutePixel algorithm, it’s a good exercise to try and work out how it works yourself.

minutePixel = (now.minute / (60/LED_COUNT) % LED_COUNT) + 1

Further Exercise Ideas:

  • Change the colour of the hands depending on if its AM or PM
  • Add a seconds hand to the clock
  • Display the hours and minutes hand simultaneously with different colours for overlapping areas (see github for a hint!)
  • Make a stopwatch
  • Make a counting down timer with minutes and seconds
  • A rainbow effect on the hands
image_pdfGenerate PDFimage_printPrint

RPI Python: DHT-11 Temp / Humidity



Prereqs:

Readers should be familiar with navigating using the terminal and editing / running python scripts.
Tutorials are available here:
Terminal Intro
Editing Files Tutorial

Hardware setup:

Carefully observe the ports and connect the positive line to the 5v, negative to ground, and the data out line to pin-14 also known as TXD on the raspberry pi GPIO.

Software Setup:

Step one is to download the DHT-11 Python library, which is very small and simple to use

Navigate to whatever directory you want in the terminal and use

git clone https://github.com/szazo/DHT11_Python

To download the library.

Then navigate into the directory with cd, and look around with ls

We can already run the example dht11_example.py with

sudo python dht11_example.py

You should see the temperature and humidity displayed on the screen every few seconds.

Use Ctrl+c to kill the process and get back to the terminal.

Next we can move on to writing our own program that uses the sensor.
If you need to see an example, here is the full project we will be writing in this article finished.

First we need some boilerplate

import RPI.GPIO as GPIO
import dht11
import time

#warmup our GPIO pins 
GPIO.setwarnings(False)
GPIO.setMode(GPIO.BCM)
GPIO.cleanup()

#get ready to read data with pin 14 
instance = dht11.DHT11(pin=14)

Next we can start writing our own code. Similar to the clock tutorial we will use a infinite loop to keep our code going

while True:
result = instance.read()
if result.is_valid():
 print("Temperature: %d C" % result.temperature)
time.sleep(1)

Our code actually does less than the dht_11 example, but it’s a bit simpler.

result = instance.read()

First we store our input from the sensor in the ‘result’ variable

if result.is_valid():

Next we use an if statement to only proceed if the result is valid

print("Temperature: %d C" % result.temperature)

In our if block we print the temperature using the print function, the ‘%d’ acts as a placeholder for a number (digits), followed by a list of variables to fill the placeholders

print("number %d %d" % (1, 2))

For example would print “number 1 2” to the terminal

Our output should look something like

"Temperature: 20 C"

After exiting the if block we wait for a full second before running the loop again

time.sleep(1)

Remember to exit the program while its running use Control-C to escape
Here is the full example code from this tutorial

image_pdfGenerate PDFimage_printPrint

T3 Instructors Training Schedule

T3 Alliance Instructor Training Agenda

February 21 – 24, 2018

Reno, Nevada

Tuesday, February 20th – travel day

Welcome to Reno. The Silver Legacy is two miles from the airport. There is a shuttle that runs constantly or there are taxis as an alternative. Check into the Silver Legacy. While the room is pre-paid, the Silver Legacy will require a pre-authorization of $25.00 for each night to cover incidentals/physical room deposit. This pre-authorization will take place upon check-in.

Wednesday, February 21st – UNR Joe Crowley Student Union – third floor 301

8:00  Walk or Shuttle to Joe Crowley Student Union

The Silver Legacy is a little less then one mile from the Joe Crowley Student Union where our training is taking place. Please refer to the attached map if you desire the stroll, or refer to the shuttle schedule and map that will take you directly from the Silver Legacy to the Joe Crowley Student Union. The shuttle cost $0.25 (one quarter) and runs each 15 – 20 minutes and holds about 20 people. There is a web based tracker if you want to see where the bus in at the currently.

The link to the website: https://www.rtcwashoe.com/public-transportation/rtc-sierra-spirit/

Attached is the shuttle route map so you can see the various shuttle stops indicated by a “blue dot” – you’ll notice that the shuttled stops directly in front of the Silver Legacy for pick-ups and drop-offs (corner of 5th St. & Virginia Street). As the shuttle makes its way north on Virginia street toward the University’s Joe Crowley Student Union (1.4 miles). The shuttle conveniently stops at the roundabout (in front of) the Joe Crowley Student Union. For frame of reference, I also added two images to the Shuttle Route Map (The Silver Legacy and the Joe Student Union).

8:30 – 9:00  Breakfast, coffee and casual introductions

  • Grab your plate, get comfortable, find Adam Low, Chester Lowrey or Dayne Broderson and make a smart aleck comment to make them more relaxed
  • Pick up a name tag with State & Name
  • Place a pin on the map for your UB site
  • We want to start on-time and honor your time

9:00 – 10:04 Kickoff

  • Welcome statements: Welcome to UNR, Safety Moment and Where are the restrooms and coffee? John Monahan & Maria Sandra Jimenez, UB Reno Asst. Director
  • How did we end up here? John Monahan &  Nicole Norfles
  • Introducing the Team – Implementation Team, Trainers and UB instructors – Everybody

10:04 – 10:16 Break

  • Check out something cool 3D printing in background – you’re going to be doing this soon

10:16 – 11:15 – Growth Mindset & Support

  • Brush Bot activity: Growth Mindset in a world of fixed mindsets – Adam Low & Mark Standley
    • Activity: Brush bots, discuss and share
    • Homework for next day: do the self-assessment

11:15 – 12:30 Lunch in the Joe Crowley Student Union food court, receive a voucher to explore and try out the dining options

12:30 – 1:30   Using the T3 website to its capacity – Adam Low & Chester Lowrey

  • Resources & Support: Adam Low & Chester Lowrey
    • Open website, login, find lesson – comment and share thoughts. To paraphrase, Adam says, he wants you to leave the session “feeling giddy about all the ways they can connect and collaborate”
  • create an account Curriculum Overview – Adam Low
  • Forum – Curriculum & Administrative
    • Moderators – Adam, Corey, Chester
  • Virtual Office Hours (VOH)
    • Google Hangouts – Adam Low & Daryl Albano
    • Events – Calendar
      • Scheduling Experts for VOH – Adam Low

1:30 – 1:45 Break

1:45 – 4:30 Raspberry Pi – Adam, Chester, Dayne

  • Raspberry Pi around the world for education, makers, and builders
  • Intro the the Raspberry Pi, components, and sensors
    • Intro to RaspberryPi units
    • Sensors & Sense HAT
  • Setup a Pi
  • Physical setup of the Pi
  • Personalizing your Pi – playing with OS – Programs
    • Keyboard config
    • Desktop customization
  • Introduction to terminal
    • The Shell: Command Line introduction
    • Rename Pi
    • Securing a Pi (password)
    • Users & Root
  • Connecting to the network
    • Basic connection
  • Review of Installed programs
  • Minecraft
    • Basics of navigation
    • Network minecraft together
    • Learning to edit minecraft using python
    • Learning to download code from github
  • Sense HAT and Minecraft

4:40 – 5:00 – Debrief with John

  • Tie back to FAQ – Growth mindset – making learning fun  
    • Practice posting comments in forum

Group Dinner –  

Talking Points for the table/groups to spark discussion:

  • Growth Mindset – Mark Standley
  • Design Thinking – John Adam & Dayne

Thursday 22nd – UNR Joe Crowley Student Union – third floor 301

8:00 – 8:30 – Coffee and get relaxed

8:30 – 8:45  – Day 2 Kickoff – Monahan & Pips Veazey

  • Preview of day
  • Response to forum comments
  • Revisit key project strategies
    • $3,500 annual resources
    • Academic Year and the 6 week plan for summer

9:00 – 9:50 – Physical computing with Scratch – Adam Low

  • Programming with scratch

9:55 – 11:35 – Hands on for Everyone

  • GPIO pins and breadboards
  • Lighting a LED, and setting up a buzzer with scratch
  • Build a whoopie cushion

11:35-12:30 Lunch in the Joe Crowley Student Union food court, receive a voucher to explore and try out the dining options

2 tracks:

Track 1: UB Directors

  • Monahan and Veazey to discussion strategies to support partnerships
    • Evaluation
    • Connecting to the community
    • Academic Year and Summer Session
    • Q&A

Track 2: – T3 Instructors

12:30 – 4:15 Track 2: Networked Pis

  • Internet of Things & Introduction to Node-Red
    • What is it and basics for using
    • Real World: Hilo Power Monitoring at home – Chester
  • Connecting to your pi NodeRed development from laptop/tablet
  • Revisit our physical computing skills in NodeRed
    • LED blinking
    • Debug Tab
    • Playing a sound from a button
  • Intro to networking between Pis
    • Send & receive messages
      • Button push on Pi 1 sends messages to Pi 2 and causes a light.
    • Query a remote sensor
      • Have a Rpi Sense HAT system already on network and ready to provide temp
    • Query a remote API
    • Provide a remote
  • Internet of Things
  • GUI of graphs
  • Dashboards
  • Cameras
    • live stream camera – underwater & trail cam
  • Motion detectors
  • Weather stations

4:15 – 4:45 Everybody: Group Debrief

  • Group up and round-robin discussion of what worked well, what could be improved, and what you can anticipate
  • Group Photo

4:45 – 5:00 Completing the survey and evaluation

Thursday – DIY Dinner

Friday 23rd – UNR Joe Crowley Student Union – third floor 301 – Getting Comfortable and going into more detail

8:30 – 9:00 Food and Coffee

9:00 – 9:15 John and New Implementation team introductions

9:15 – 9:40  Brief Intro to Design Challenges – Holly McQuinn & Adam

9:30 – 9:40  Break

9:40 – 11:30

Going into more detail

  • Google Hangouts
    • Do a real world test of this using different rooms with teams/experts
  • Forum Review
    • Post frustrations and feedback
  • Project Planning (share Corey kinds of projects)
  • External Resources and Access
    • walk through a Rpi thing (have a list of a few things to try)
  • Command line skills & networking skills revisited and built up

11:30 – 12:30 Lunch in the Joe Crowley Student Union food court, receive a voucher to explore and try out the dining options

12:30 – 2:15 – Python

  • Hello world
  • Light a lightbulb, and trigger a buzzer with python, using a motion sensor

2:15 – 4:15 – Expanded sensors

  • Connecting a camera, and a motion detector
    • Weather stations
    • Connecting other weather sensors
    • Describe how to create a live stream camera – underwater, or a trail cam.
  • More Networking on Pi

4:15 – 4:45 Everybody: Group Debrief

  • Group up and round-robin discussion of what worked well, what could be improved, and what you can anticipate

6:30 Group Dinner: Silver Legacy – Buffet

  • Moving ahead when you get home
  • Holly talking points about a National Design Challenge
  • EPSCoR National Involvement

Saturday 24th – Silver Legacy Silver Baron Room 1 & 2

9:00 – 10:00 Themed help tables, reviews, project demos & debugging

  • Advanced command line & services

10:00 – 11:30 – 3D Printers

  • 3D Printers – Cory & Adam
    • Tinkercad
    • Material selection
    • Fasteners, clips, and latches
    • Clearances and tolerance

11:30-12:30 Lunch – on your own

12:30 – 2:30 – Future Projects

  • Drones in the future
  • What’s to come – drone mapping
  • Robot Pis
  • Programing servos with a Pi
  • Triggering an email and or a text
  • Building a mousetrap / robot, or some other devices
  • Hydaburg Clock
  • Hydaburg Underwater camera
  • Barrow Ice Cellars

2:30 – 3:00 Wrap-up & Thanks

  • What can we do for you moving forward?
  • Evaluations

3:00 – 5:00 Individual Sessions

  • Enjoy Reno & Catch flights out
image_pdfGenerate PDFimage_printPrint

Growth Mindset: Brushbot competition

This is a continuation of the brush bot activity from the previous class.  It may be helpful to have some sort of prize, a 3d printed item or a certificate.

Begin by asking if students got their brushbots to work?  To move in a way they wanted?  What variables were they able to change?  Ask if they feel like their minds grew and what did they notice about themselves as they were building and testing their robots.

Setup and run the 750 mm races and the Sumo competition.  Here is a link to some rules.

http://www.spacegrant.hawaii.edu/BrushBot_Olympics_Rules.pdf

Most importantly have fun, cheer on everyone, and ask questions for them to describe why and how it works.

For the race, I often have the students calculate the cm/s to get the speed.

image_pdfGenerate PDFimage_printPrint

Growth Mindset: Building a Robot

For this lesson, you will want to have enough Brushbot kits for every student you are working with.

Time: approx. 30 min.

Part 1: Growth mindset and fixed mindset are some patterns that researchers have observed in students.

Here are a series of statements that can be used to assess a person’s fixed or growth mindset.  I like to review them before presenting the activity and encourage students just to note where they fit.  The actual survey can be found here.

The RSA animate video below has an excellent overview of how Growth and Fixed mindsets express themselves and are developed.  To use this with a group of students, plan to pause the video at 4:23 to allow students to talk about the issues raised.  Be careful not to equate a fixed mindset with bad and a growth mindset with good.

After watching this video, allow time to review the questions outlined previously and reflect on why mindset is so important.  Using daily reminders about growth mindset and keeping company with those that support your growth mindset is important.  Make a commitment as a class to support a growth mindset environment and see every setback as a learning opportunity.

Pass out batteries – identify batteries as a technology that today looks common but, was once a science experiment. Have students hold the battery between their thumb and forefinger and envision a tiny bit of electricity moving through their hands.

Pass out the kits – take out the cell phone motor and have students get it moving with the battery.

  • This a moment pregnant with learning potential.
  • The flow of electricity, what is causing the motor to vibrate…
  • What happens if the wires are switched to the opposite side of the battery.

Leave the students with the idea that potential energy is transferred into kinetic energy and that they have the tools in the kit to turn this energy into a robot.

Leave the students to work on their project. This is hard to not help, but control yourself and let them do the exploring. Ask questions to help guide frustrated engineers. Remember, they are learning to exercise growth mindset.

Once it works, have them observe how different ones perform. What can be done to compensate.

At the end of the time help them disconnect their robots and take them home to prepare for the next day’s competition.

image_pdfGenerate PDFimage_printPrint