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.
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.
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
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
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.
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 ..
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!
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.
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()
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.
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.
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
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!
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.
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.
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.
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!