In the past two weeks in the Hackers group at CoderDojo Athenry, we have started Python programming on the Raspberry Pi.
The Pi is about the same size as the Arduino that we used earlier, and the Pi Zero is about the size of the Arduino Nano, and both Pi and Arduino have input/output pins for physical computing. However, they have significant differences.
Unlike the Arduino which is a microcontroller (which means it is designed to run a single program that was uploaded onto it), the Raspberry Pi has a full computer operating system, so it is more like a PC to use. It can be programmed in many languages, but Python is a popular choice as it is clear to read and there are lots of libraries to make tasks easier. Because it’s a full computer, you can write and run your programs all on the Pi, without connecting it to a laptop.
The first step in programming is to figure out how to do loops, variables and decisions, as these are fundamental. Here is our first Python program to try out these:
# Python comments start with # age = 14 # a variable holding an int name = "Michael" # variable holding a string # Output print ("My name is", name, "and my age is ", age) # Loop for x in range (1, 5): print ("This is line ", x) # Decision if (age 17): print("Adult") else: print("Teenager")
Next we moved on to using the GPIOZero libraries for controlling lights and buttons. We will continue to explore this in the coming weeks.
The documentation is here: https://gpiozero.readthedocs.io/en/stable/