Raspberry Pi Bots 2019

Wray Mills, 2019-07-22, Classes

device, raspberry pi

Description

Camp Session July 22 - 25, 1 - 4pm

What is a bot exactly? Our campers will learn by creating a bot using a Raspberry Pi and accessories, language skills, coding skills and of course, their imaginations. Materials fee to take home the project.

Instructors

Lead Instructor

Chris

Additional Interns/Instructors

Pre-Requisites

Learning Objectives

Materials

Class

On the line Resources

Raspberry Pi Chatbot Project

On the line Presentations

Repos

Related Blog Notes

(GitHub) Assignments

External References

Day 1

Setup

Plan

Students will set up their Raspberry Pis with the Initial Config instructors below. Instructors will go over the hardware and software of the Raspberry Pi. After students have set up their Raspberry Pi, they will look at the Python code behind the various games on the Raspberry Pi. Instructors will challenge students to find a way to make the game harder or easier to win by changing various elements of the code.

Students that attended the morning camp session will start to work on the bot cirriculum outlined in the days below.

Initial Config

For classes and camps, we always start with an SD card that has raspian (the Operating System) pre-installed. Of course, for the last camp, we started with blank SD cards! So, on that first day, we were actually loading the OS on your cards.

After logging in, we then ran

sudo raspi-config

in order to extend the filesystem, set the correct time, and set the correct keyboard.

We also configured your wi-fi adapter by running the gui

startx

and using the wifi settings to scan for networks, choose the network, type in the password, and connect. Remember, you'll have to do this for your home wireless netework. Try to run startx without sudo. If the GUI doesn't come up, you may have to use sudo. When you are using the LEDS or the temp sensor, you will have to run python as sudo.

Config for LEDs, Minecraft and Temp sensor

In lieu of burning a pre-configured SD, we can run this script on a raspbian pi (model 2 with pre-loaded raspian from Adafruit) in order to get python development tools, the RPi GPIO library and the DHT library from Adafruit. Note, that this setup assumes your pi has network (Internet) connectivity. You can type in these commands separately, starting with the first line not containing a #.

#!/bin/sh
# Run this command using sudo

# Beforehand, you should expand filesystem, turn on ssh
# and of course configure network.

sudo apt-get update
sudo apt-get install python-dev
sudo apt-get install python-pip
sudo easy_install -U distribute
sudo pip install --upgrade RPi.GPIO
sudo apt-get install build-essential
git clone git://github.com/adafruit/Adafruit_Python_DHT
cd Adafruit_Python_DHT
sudo python setup.py install
cd ..

Actual

The campers joining us for the afternoon worked on getting their Pi's running, and we briefly went over the different components. Being that this group is fairly young, we had a discussion about computers, and how the Raspberry Pi is a computer, but just tiny. After everyone was booted up into Raspbian, we spent time getting comfortable with the GUI. I introduced everyone to the concept of a chat bot and how they work. The rest of the class was spent practicing Python and starting to think about how Python would let us create our own chat bots!

Day 2

Setup

Plan

Instructors will go over what bots are and the various things that bots can be used for. Students will work on creating a chatbot on their Raspberry Pis using Scratch with the Raspberry Pi Chatbot Project. Students will also set up their breadboards and LEDs.

LEDs

So, for the Output portion of the I/O lesson (easier than input so you may as well start here), assume a green LED is wired to #20 and a red LED is wired to #21.

import RPi.GPIO as GPIO

DEBUG = 1

GPIO.setmode(GPIO.BCM)
GREEN_LED = 20 
RED_LED = 21
GPIO.setup(GREEN_LED, GPIO.OUT)
GPIO.setup(RED_LED, GPIO.OUT)


def green_led(state):
    GPIO.output(GREEN_LED,state)

def red_led(state):
    GPIO.output(RED_LED,state)

So, a simple session to use these methods would look like this:

sudo python
>>>from led import *
>>>green_led(1)
>>>red_led(1)
>>>green_led(0)
>>>red_led(0)
>>>quit()

Actual

We started the afternoon reviewing the basics of the Raspberry Pi and making sure we felt comfortable navigating the Raspbian operating system: opening Geany, opening Scratch 2, and typing commands into the Terminal. We reviewed our Python code from yesterday and typed up the last couple lines. Next, I introduced the breadboard and demonstrated how we can insert various LEDs, resistors, and wires into it to create miniature circuits that we can control by the code we develop. This group prefers Scratch so we jumped into Scratch and learned how blocks of Scratch code can make our LEDS turn on and off. For the remainder of class we worked on an activity that involved building a Traffic Light with three LEDs on our breadboards.

Day 3

Setup

Plan

Students will finish up working on their chatbot. They will then start to work on a bot that can turn the LEDs on the Breadboards on and off. Instructors will work with students through this project.

Students will also set up their tempature/humidity sensors.

Input Sensor (Temp/Humidity Sensor including in your Tech Em kit)

For the Input part of the lesson, here is some code that provides a single simple method to return temperature and humidity (from a DHT-22 temperature/humidity sensor wired to pin #4).

#
# Template code for temperature and humidity from an Adafruit DHT22
# sensor. Don't forget to update this file if you connect the DHT22 
# to another data pin,
# want to change the delay, or logic for mailing. 
# For example, you may only want to
# send notifications when certain thresholds are exceeded.
# 
# Code provided for Tech Em students and open under Gnu GPL
#
# Wray Mills
# 20141115
#

import os
import time
import Adafruit_DHT
# Tech Em mail utility
# from mailit import *

sensor = Adafruit_DHT.DHT22
pin = 4 

def read_temp_humidity():
    humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
    temp_f = temperature * 9.0 / 5.0 + 32.0
    return temperature, temp_f, humidity

Actual

The campers jumped right into Scratch and reviewed their code blocks from the previous days' Traffic Light activity. They tested everything plugged into their breadboards to make sure it still worked. After feeling pretty confident that we'd gotten down turning LEDs on and off with Scratch, it was time to start thinking about our chatbot and the different things we wanted it to be able to do. To start, it had to ask what your name was and then be able to say back hello plus whatever name you had given it. This required us to create a variable to store the name typed into the chatbot so that it could print the name back out when saying hello. Once we had tested our Scratch programs to make sure it was working how we wanted, everyone spent the remainder of class adding more commands and things that the chatbot could do, like take you to the moon!

Day 4

Setup

Plan

Students will finish up the LED chatbot. If there is extra time, students can continue to look at the code in the python games or start to work on a new bot.

Actual

Everyone continued working through their Scratch projects and finishing up the parts of their chatbot that they wanted too. They have had a lot of fun playing around with the LEDs and adding in the functionality to have instruct their chatbot to turn them on and off. They did a great job with Scratch, and it was hiliarous seeing the things they could make their chatbot respond too.

Day 5- Project Friday!

Setup

Plan

Students will continue to work on an activity of their choosing from the week. This is a more open ended day and will be guided by the interests of the students.

Actual

Everyone worked on a new project of their choice, or chose to continue work on something that they'd done during the week. It was fun seeing them connect some of the things they'd learned throughout the camp and incorporate them into their Scratch projects to create new things. I'll be very curious to see what they come up with in the future!