Raspberry Pi — Expanding My Mind with the GPIO

Raspberry Pi Board

I love technology and tinkering with it. After fifteen years of being a devout Apple fanboy, I switched to Linux. While there were many reasons for this significant change, at the core, it was about learning. Since the switch, I’ve learned more about how computers work, both the hardware and software. I’ve built a desktop computer and breathed new life into older computers with Linux. My recent acquisition of the Raspberry Pi 400 started me on a new journey learning physical computing.

Since the Raspberry Pi 3 release in 2016, I’ve been using Pis for single-purpose servers. I’ve set up a network print server, Home Assistant server (home automation), Plex server (media server, mostly for streaming home videos), and a Pi-Hole (network ad blocker and DNS server). I once set up a cluster of Raspberry Pis to emulate a high availability web hosting environment.

Raspberry Pi rack.

As a career software developer, with most of that experience building websites, I’m comfortable writing programs that humans use to interface with information. I’ve also interfaced with software systems to share data, but I have never written software to interface with the physical world; lights, sensors, and devices.

Enter the Raspberry Pi GPIO.

This article is an overview of the things I’m learning in my first experiences with physical computing.

GPIO

The General Purpose Input/Output (GPIO) header on the Raspberry Pi allows you to interface with the physical world. The GPIO has 40 pins used for input and output. Four pins provide power (3v3 and 5v), eight are ground, twenty-six GPIO, and two for advanced use, which does not apply to me yet.

Pi 400 GPIO — Image source: Magpi Magazine

Getting Started

In addition to a Raspberry Pi, you need a few more things to get started with physical computing.

Breadboard —A breadboard, also know as a solderless breadboard, allows you to connect electronic components without soldering.

Full size breadboard

Components — There are many components you can interface with, including LEDs, temperature sensors, moisture sensors, motors, and switches.

Miscellaneous components

Cobbler — A cobbler connects the GPIO header directly to the breadboard, eliminating the need to connect jumper wires directly to the GPIO. A cobbler is not required, but it makes wiring easier — more about this below.

Cobbler

Starter Kits — You can find starter kits online as low as $10USD. The larger your budget, the more components you will get. I recommend choosing a kit that includes a full-size breadboard and Raspberry Pi cobbler.

Starter kit with full-size breadboard and cobbler ~ $28 USD.

First Project — Step 1

While I was lucky to have access to a Personal Computer relatively early in my life (1979 — Heathkit H-88), I never touched electronics, and if I did, it wasn’t memorable and didn’t stick with me. Now, in my fifties, I’m learning basic electronics. The photo below shows a breadboard with a yellow and red LED, two resisters, and a power supply module. While it’s easy to get the LEDs to illuminate, it’s challenging to understand how and why it works. this is what I learned:

  • Series and Parallel Circuits — In a series, components are connected in a chain. “If one goes out, they all go out.” In a parallel configuration, there is more than one path for an electrical flow.
  • Resisters — Resisters are Pi 400needed to limit the amount of current going to a component.
  • Ohms Law — Ohms Law is a formula used to calculate the relationship between voltage, current, and resistance in an electrical circuit
First LED project on a breadboard.

The LEDs illuminated when the power turned on. While this project is simple, it is exciting to see the LED come alive. My wife wasn’t so impressed when I proudly presented the yellow and red lights I had been working on for hours.

As I learned some electronic basics, I’ve only scratched the surface. I’m still trying to get my head around some of the basic concepts.

First Project — Step 2

After understanding how this circuit works, the next step was to replace the power module with the Raspberry Pi 400. I didn’t want to get cocky about my new found skills, so I simplified my project using only one LED. The GPIO has three pins that provide power and eight ground pins. I wired one of the power pins to the positive rail on the breadboard and the ground pin to the negative rail. The LED lit, as expected — another win!

Breadboard wired directly to GPIO.

Since I use the Pi 400 as an everyday computer, having the breadboard wired directly to the Pi 400 is not convenient. This is where the cobbler comes in. It’s connected to the Pi via a ribbon cable, then all of the wires are on the breadboard. It’s easy to remove the ribbon and put the project aside.

Cobbler replaces direct wiring.

First Project — Final Step 3

At this point, the LED is continuously on. My goal is to control the LED with software. The only wiring change required is moving the positive wire from the power pin to a GPIO pin; I chose GPIO 21. The next step is to write a Python program to turn GPIO 21 on and off, making the LED blink.

As I mentioned earlier, the software side is my comfort zone, but this was my first Python program and first time accessing the Pi GPIO. I’m impressed with how Raspberry Pi Foundation has made this easily accessible for people of all skill levels. There are many resources available to step you through a Pi project, from physical books to videos and blog posts.

I chose a tutorial on RaspberryPi.org and used the Thonny IDE to write and execute Python. After a few lines of code, the LED was blinking.

Thonny — Thonny is a Python IDE for beginners provided with Python 3.7. It’s is available from the Programming menu in Raspberry Pi OS. An IDE, Integrated Development Environment, is an editor that makes programming easier. It’s a good place to start with Python.

Thonny and my first Python program.
Yes — it blinks.

Next Projects

The starter kit I purchased came with several components. I’ve had fun experimenting with them. I was also lucky to get my hands on the new Raspberry Pi Pico, the new flexible $4 microcontroller board. I’m going to continue learning through some of the typical Raspberry Pi projects that build your skills and then take on a more significant project.

LCD controlled by Pi 400.
Raspberry Pi Pico.

Pi 400

While I’m using the Raspberry Pi 400, everything covered in this article can be accomplished with previous generations of the Raspberry Pi. The form factor of the Pi 400, as a complete personal computer, allows you to use the Pi as a computer and maker tool at the same time. It’s an excellent way to approach the Raspberry Pi for a non-techie.

Resources

The books and magazines produced by the Raspberry Pi Foundation are available for free in digital format. The physical books are high quality, loaded with information, and well worth the price.

Official Raspberry Pi Guides

Final Thoughts

Over the years, I haven’t spent much time on hobbies. With a mindset of ‘not wasting time,’ I’ve focused my time on activities that forward my career and have an end goal. One gift of the global pandemic is time. The quarantine kept us home with more free time than in the past. In my home, the amount of time we watched TV dropped. We started playing more games, reading, and other activities.

The Raspberry Pi 400 and GPIO has given me an avenue to expand my mind and start a new hobby in a subject area that interests me. I’m not going to be an electrical engineer, but I’ve learned it’s okay to do something because it’s interesting and fun.

The Raspberry Pi Foundation makes learning affordable, fun, and accessible for all ages.


Originally posted on Medium – https://medium.com/linuxforeveryone/raspberry-pi-expanding-my-mind-with-the-gpio-ffece43600ba?source=friends_link&sk=0b171299b27bf85120262128cb6a981a

Leave a Reply