Tutoring Day 2 - Python

Tutoring Day 2 - Python

Today was day 2 of the tutoring session for a coworker's daughter. She's into 3D printing, coding, and electronics, so I volunteered to help her learn the topics.

Today, she wanted to start learning how to program, so we wired up some LEDs to her Raspberry Pi and opened the IDLE IDE for Python 3.

The first thing we did was a quick review from her Summer camp, where they used breadboards to make game controllers for the Raspberry Pi.

We wired up a single LED to pin 17 on the Pi and wrote a quick Python program to turn it on and off again in an infinite loop.

The next thing I had her do was build a traffic light circuit with three LEDs. Here is the circuit that she built...

Traffic Light Circuit for Raspberry Pi (those are 220Ω resistors)

Here is the final source code for the traffic light:

# import libraries
from gpiozero import LED
from time import sleep

# initialize variables
green = LED(17)
yellow = LED(27)
red = LED(22)

# run traffic light simulation
while True:
    # green state
    # yellow state
    # red state

She went through a few permutations before finally getting it right. It was great watching her finally get it right and celebrate when her traffic light worked.

Here is a video of the traffic light circuit:

We also developed the same thing in Node-RED, but the asynchronous nature of it was a little too much for her. We may revisit that in the future, but she told me that she likes typing the Python code better because it's easier than Node-RED.

I had never used Python until last night, but teaching it was easy. It's a great first language and having it built into the Raspberry Pi is nice. Especially considering that you can wire up LEDs and quickly write code to make them blink.

She said that she wants to get back to 3D printing at the next session, so I'll put together some design lessons. I'll try to cover them here after the lessons so that I have a place to put things so I can remember them in the future.