Block I Illinois Library Illinois Open Publishing Network

Orange Unit: A Person-Centered Launch

4D: Coding Electronics

As a final exploration for this unit, we’ll bring the hardware together with software, implementing Python code to turn the LED lights on or off. So far, your LEDs and mechanical switches have functioned together directly as part of isolated circuits coming together as a larger circuit on the breadboard. Physical motion of the switches is used to communicate choices to other parts of the circuit. Now, let’s rewire them to add digital communication using an application to build a programmable circuit, adding still another layer of complexity into the system.
NOTE: there are many microcontrollers, such as the Circuit Playground Express we’ll use in the Blue Unit, that have sufficient digital IO pins and can run the Python code we’ll use in this concluding chapter. However, we’re using the Raspberry Pi, as it builds from the previous exercises of this session of the Orange Unit. Further, the use of the Raspberry Pi here sets the stage for use of Python code with this RGB LED breadboard prototype in the Rainbow Unit to provide digital switching using a web browser!

Exercise: Connecting a Breadboard to a Raspberry Pi

In the previous two chapters of this Orange Unit session, 4B: Meet the Microcomputer and 4C: Getting Started with the Raspberry Pi, we began familiarizing ourselves with the application of computer building blocks specifically to the Raspberry Pi microcomputer. After meeting the hardware, we went on to set up a Raspberry Pi-based Linux operating system, an organic (that is, self-luminous) light-emitting diode (OLED), and a bootup script to display some essential current data on the functioning of the Raspberry Pi. The result looked something like this:

Working PiOLED on Raspberry Pi 3. The Adafruit flower icon at the upper left points to the hole that is connected to the 5-volt pin on the GPIO.

But in doing so, we’ve also reserved access to six of the General Purpose Input Output (GPIO) pins, including the only two 5-volt power pins.

On the left is an image of a Raspberry Pi Model 3 with protective acrylic case providing GPIO labels. On the right is a table displaying a second common format used for the GPIO pins. The table also provides the formal GPIO pin numbers in which pin 1 is at the upper left and is associated with a 3.3 volt power source for both formats.

Above, you can see two different displays of the pin layout formats commonly used with the Raspberry Pi GPIO[1].

Look through these and note that some, like #10, #9, and #11 just below the middle 3.3V pin, can be used for multiple purposes, such as digital inputs and outputs, or as a serial peripheral interface (SPI) connector with Master Out/Slave In, Master In/Slave Out, and Master Clock pins.

The use of the terms “master” and “slave” is rightly discomforting for many. As noted in the tween zine Beyond Dark Matter, “The master/slave relationship has been used for centuries in technology, often to explain situations where one master process or component controls a slave process or component” (p. 31, Beyond Dark Matter).

Efforts are made periodically to move away from this embedded framing of the master/slave relationship within core aspects of all our electronics. This blockquote seeks to unpack further the hidden sociopolitical and economic realities that remain encoded within our sociotechnical technologies and systems.

While there are many other pins for us to use than the ones covered by the PiOLED attached directly to the GPIO, this layout has proved less than optimal for later exercises, in which the Raspberry Pi is used with the breadboard electronics. This is particularly the case when a shared Raspberry Pi is connected and disconnected with different breadboards as each person tests out their own prototype[2].

For the next exercise, we’ll remove the PiOLED from the Raspberry Pi GPIO, and instead connect a 40-pin ribbon cable to the 2×20 GPIO of the Raspberry Pi. This can then be attached to a Cobbler or T-Cobbler on a full-sized breadboard. As we’ve used columns 1-30 for past exercises in the Orange Unit, we’ll now attach the T-Cobbler to columns 44-63 of the breadboard.

Breadboard RGB Switch with Cobbler Connection to Raspberry Pi
Breadboard connected to Raspberry Pi via Adafruit Cobbler and ribbon cable
Breadboard RGB Switch with T-Cobbler Connection to Raspberry Pi
Breadboard connected to Raspberry Pi via Adafruit T-Cobbler and ribbon cable

If your IP address changes moving forward, you may need to disconnect the ribbon cable from the GPIO pins of the Raspberry Pi and reconnect the PiOLED temporarily. Alternatively, you can reconnect the Raspberry Pi to a keyboard, mouse, and monitor.

Connecting the Raspberry Pi and Breadboard

While the Fritzing diagrams in the first half of the Orange Unit were illustrated using a half-sized breadboard, these could be (and hopefully were) done using a full-sized breadboard, which would have been demonstrated with a Fritzing image as below. The unused space at the right of the breadboard is just what is needed for this part of the exercise.

Switched RGB LED circuit with on/off switch on full-sized breadboard and connected to 5-volt power
  1. Disconnect the USB-to-TTL cable and associated jumper wires from the breadboard.
  2. Insert an Adafruit T-Cobbler Plus into columns 44-63 of the breadboard. Leave at least two rows accessible above and below the T-Cobbler.
    Connecting the Raspberry Pi and Breadboard, step 1 using T-cobbler
    The T-Cobbler was chosen to ensure that the ribbon cable does not cover the breadboard holes and the GPIO pin labels associated with the top and bottom halves of each column. However, this results in an extended layout of full-sized breadboard, ribbon cable, and breadboard. For some, the Cobbler Plus may be the preferred alternative, keeping the full-sized length and instead adding the ribbon cable and Raspberry Pi to the height of the layout.
    Connecting the Raspberry Pi and Breadboard, step 1 using cobbler
  3. Use male-to-male jumper wires to provide 3.3 volts to the upper red rail, ground to the upper blue rail, 5 volts to the lower red rail, and ground to the lower blue rail.
    • The 3.3-volt GPIO pin immediately above the 5-volt GPIO pin below was chosen instead of the 3.3-volt GPIO pin in the middle of the T-Cobbler to keep the jumper wires to the right when working on later wiring. That said, both 3.3-volt pins and any of the ground pins can be used for this step.
    • Rapid prototyping begins with quick testing of circuits, with jumper wire placement of secondary concern. But wires can sometimes get in the way, and so in your layout of the base system for future exercises, spending a bit of time now to strategically create a platform for further work may be of value.
  4. From here, you can insert a 40-pin ribbon cable between the breadboard and the Raspberry Pi.
    • A common practice for ribbon cables is to use a white non-conductive shell over the conductive metal wire that connects to pin one and black non-conductive shells for the remainder of the wires. For the Raspberry Pi GPIO, pin 1 is the 3.3V pin, which is now the upper half of column 63. A bump-out on the end-frame of the ribbon cable is also often used, and an associated gap is provided on the T-Cobbler to further help assure pin 1 is appropriately aligned.
    • Removing the ribbon cable does take some force. Holding it by the plastic frame or as close to it as possible while steadily pulling it from the T-Cobbler or up from the Raspberry Pi will help maintain the connections of the 40 wires with their metal connectors inside this frame.
    • The GPIO pins tend to bend a bit if the ribbon cable frame is leaned slightly while being removed from the Raspberry Pi. When possible, consider leaving the ribbon cable attached to the Raspberry Pi and instead removing it from the T-Cobbler as needed.
Raspberry Pi connected with T-cobbler on the breadboard using a 40-pin ribbon cable

Try Something New!

The slide switch can continue to be used as a make-or-break switch to turn on and off 5 volts of current to the shared anode leg of the RGB LED. This would then provide a mechanical override of any selections made by code moving forward. However, given that the Raspberry Pi provides both 5-volt and downregulated 3.3-volt power options, the slide switch can also be used to mechanically select between voltages, helping to control the brightness of the lights by running a jumper wire from the 3.3-volt rail to the left throw leg of the switch, as shown below.

Raspberry Pi connected with Breadboard, switch between 3.3- and 5-volt power

Schematically, the RGB LED, resistor, and switches within the breadboard circuitry remain the same. However, now they receive 5V and 3.3V power and ground through the Raspberry Pi by way of the T-Cobbler.

Schematic of Raspberry Pi connected with Breadboard, switch between 3.3- and 5-volt power

From here, consider using resistors to further control the lower level of brightness for that left side of the switch to match your preference for a dim setting.

Try Something New!

Raspberry Pi connected with Breadboard via an Adafruit T-Cobbler. PiOLED is connected to Raspberry Pi via breadboard.There still may be those times when it is helpful to use the 128×32 pixels of the PiOLED to provide important data through code running on the Raspberry Pi, whether the stats are given through stats.py or some other information you’d like sent as part of upcoming exercises.

NOTE: Testing over two semesters and extended conversations with others who have used the PiOLED across the country have indicated that there is significant risk of improperly wiring a breadboard to the PiOLED, thereby resulting in short-circuiting of the PiOLED. This burned-out PiOLED circuit cannot be repaired. Therefore, this has been removed as a normal exercise and instead has been moved to a Try Something New activity. Use caution in proceeding in this selected optional task.

  • To connect the PiOLED to the Raspberry Pi GPIO pins, you now need to run 6 male-to-male jumper wires from the breadboard to the PiOLED.
    • There is an Adafruit flower icon on the upper left side of the PiOLED. This points to the hole associated with 5-volt power.
    • The other two holes in the top row are a second 5-volt hole for power and a hole for ground, in that order.
    • The hole just below the 5-volt power hole is the 3.3-volt power hole.
    • The other two holes in the bottom row are the holes for SDA (serial data) and SCL (serial clock) communications, respectively.
  • Pin 1 of the PiOLED is the lower left hole in the drawing below. It is connected to a 3.3-volt source on the breadboard.
  • Here it is connected to Raspberry Pi GPIO pin 1, which is the upper rows of column 63 of the breadboard. This design choice was made to help align the remainder of the pins of the PiOLED with the appropriate connections on the breadboard.
  • Using an orange-colored jumper wire for the 3.3-volt connection, red jumper wires for the 5-volt connections, and a black jumper wire for the ground connection may help identify the connection points in the future.
  • Once you’ve reached a successful point of “yes,” consider using some electrical tape at the plastic frames of the jumper wires to keep these wires in their assigned layout at the point where they connect to the breadboard, and again at the PiOLED if you will only occasionally be using the PiOLED attachment.
Fritzing diagram of PiOLED connected to the Raspberry Pi via the breadboard

Key Takeaways

The breadboard is a common way to do rapid prototyping. Many different electronic circuits may be tested in rapid succession. It’s also possible to keep multiple breadboards with different versions of an electronic circuit on hand to take with you in testing by a diverse range of communities. While it’s sometimes possible to also bring multiple Raspberry Pi’s, this layout is meant to provide a means by which different breadboards can be attached and detached from a given Raspberry Pi in support of testing of multiple breadboard prototypes.

Digital Switches

So far, we’ve been working with mechanical switches. We’ve used the slide switch to move the flow of current to the anode leg of the RGB LED both between on and off states and between 5-volt and 3.3-volt power sources. We’ve also used the momentary “on” push button switch to temporarily complete the flow of current to ground, thereby turning on the associated red, green, or blue cathode legs of the RGB LED. Like light switches in our house, these mechanical switches can serve a valuable function in our daily lives.

But sometimes the use of a mechanical switch may prove inadequate for a task. Perhaps you still make use of the mechanical switch for regular use of a light, but need a safety switch to override a mechanical on/off switch to quickly turn on the light when a fire alarm sounds. Or maybe access to the mechanical switch is difficult and you’d like to move to a digital control through a phone app.

Digital Input/Output Pins vs. Power and Ground Pins

Before moving on, it’s important that we look a bit closer at the labels on the GPIO pins:

Table of the GPIO pins and associated labels for the functions applied to these pins. The columns one and four provide the labels associated with the function of the pin, while columns two and three provide the odd and even pin numbers, respectively.

In particular, compare those whose labels start with “GPIO #” to those labeled as “Ground.” We’ve specifically used labeled “Ground” for the blue grounding rails on the breadboard. Those labeled “GPIO #,” on the other hand, or not designed as a ground source, but are instead general-purpose input/output pins. Digital (IO) are used on microcontroller and microcomputer GPIO pins for binary on or off logic. In code, this is sometimes written as binary High and Low or as digital True or False. The current used for digital IO is relatively small and can include negative as well as positive voltage. This can be important when pushing a speaker cone out with a DC signal that varies between 0 and some positive voltage before pulling the speaker cone back with a DC signal that varies between 0 and some negative voltage. The general-purpose digital IO pins provide a perfect match to the momentary and transistor switches.

As the GPIO digital IO pins do move from positive voltage to relative zero voltage, we could just send our digital outputs straight to the 470 Ω resistors connected to each of the three cathode legs. But as this is not true ground but a relative zero voltage, it is possible there could be a slight glow of color on an LED, even though the digitally switched circuit is an open circuit. The relative difference between power and ground is insufficient to assure the LED is off in keeping with the decision tree within the code.

Digitally Switched RGB LED with Residual Soft Red Lighting
Digitally switched RGB LED with red, green, and blue legs of the RGB connected directly to their assigned GPIO ports.

Digital switches come in multiple classes and types. To address the misuse of the digital IO ports as a ground source instead of its intended digital High or Low role, we will use as digital switches transistors—solid-state electronic devices used as part of much of our daily life electronics, which are designed specifically for tasks like this. We’ll place these between each of the three cathode legs of the RGB LED and their assigned GPIO ports.

Labeled image of transistors which have been added

More on Transistors

Starting in the 1960s, a new term was heard in relation to radios, calculators, and televisions. I remember the commercial that inspired our family to get its first “transistor radio.” I also remember going to the five-and-dime or drug store to purchase a vacuum tube until we finally got that transistor television. Transistors replace those tubes by providing a semiconductor device having at least three legs: a source current terminal; a drain current terminal; and a gate terminal, which controls the output current.

At its most basic level, the transistor serves as a switch. While our momentary switch circuits above required a physical act, the pushing of a button or the sliding of a switch, a transistor switch uses an electrical input to determine the flow of current. Further, transistors are designed such that the switching voltage is less than or equal to the voltage of the current flowing through the transistor. The 3.3- or 5-volt output from the Raspberry Pi GPIO pins can be used to turn on and off not only a 5-volt LED, but also a 40-volt DC motor! In this way the transistor can also serve as an amplifier. “In fact the initial tests of the first transistor involved hooking a speaking to its output and hearing that it was louder than the input. Every modern piece of audio circuitry has transistors at its heart amplifying signals.” (Dave Astels, “Transistors 101”: https://learn.adafruit.com/transistors-101/basic-operation)

Types of Transistors

are built using two different types of semiconductor material. Unlike a jumper wire that is always conductive, a is a substance that can conduct electricity under some conditions, but not under others. An n-type semiconductor is mostly made of negative electrons. A p-type semiconductor is mostly made of positive charge carriers.

When a transistor uses both n-type and p-type semiconductor material, and only those two types of semiconductor material, it is called a bipolar transistor. The bipolar transistors are three-terminal devices with the standard Emitter, Base, Collector (EBC) pinout. The emitter and collector on either end of the transistor are of the same type of semiconductor, while the center base is of the other type of semiconductor. In this way, the base provides a junction between the collector and emitter. When a biasing voltage is applied to the base terminal, the junction breaks down, and current can flow from the collector to the emitter.

Image showing components of a bipolar transistor. The Collector at the top feeds down to the collector at the bottom. There is a base shown on the left which serves as a junction between these.
Image by Simon Monk, Arduino Lesson 13. DC Motors: Transistors, Adafruit. Licensed under CC BY-SA 3.0.

As we’ve been doing with the momentary switches of our parallel red, green, and blue RGB LED circuits, we can use three bipolar transistors as switches to determine the state of each circuit. To do this, we need to decide between the two different configurations of a basic bipolar transistor.

  • The NPN bipolar transistor has a collector and emitter made of N-type negative electrons and a center base made of P-type positive electrons. For our LED circuits to have current flow from the cathode leg of an LED to the collector and emitter of the transistor and thereby to ground, voltage is sent to the base leg of this type of transistor to turn on its gate.
  • The PNP bipolar transistor has a collector and emitter made of P-type positive electrons and a center base made of N-type negative electrons. For our LED circuits to have current flow from the cathode leg of an LED to the collector and emitter of the transistor and thereby to ground, ground is sent to the base leg of this type of transistor to turn on its gate.

Below is a Fritzing drawing and associated schematic in which a momentary switch is used to provide ground to the PNP transistor base and 5 volts to the NPN transistor base. Let’s now use this information as our starting baseline for designing and prototyping our programmable RGB LED switched circuitry.

Image showing PNP and NPN transistors as part of an LED circuit.
Schematic showing PNP and NPN transistors as part of an LED circuit.

Exercise: Control LEDs with Python Code

With the GPIO pins on a Raspberry Pi readily accessible via a Cobbler or T-Cobbler on the breadboard and with a rudimentary understanding of PNP and NPN bipolar transistors, we’re ready to rewire the electronics to use Python code to input data from the momentary switches and to output data to transistor switches connected to the three legs of the RGB LED.

For this exercise, we’ll use GPIO #5, #6, and #12 for the momentary switches, and GPIO #26, #19, and #13 for the base of the transistor switches to be integrated into programming code. The grouping of these pins was selected to roughly match electronics with GPIO pin groupings. But other digital IO pins with a “GPIO #” hash label at their start could have also been used. What works for one may not be ideal for others, which is where alpha and beta testing, along with open channels for feedback after implementation, come in. Feedback from past students doing these exercises has proved essential in improving functionality for diverse audiences.

Part 1: Steps to Rewire the Circuits

Here’s the configuration of our current circuits (without sequin LEDs) as a reminder of where we’re starting:
Raspberry Pi connected with Breadboard, switch between 3.3- and 5-volt power

And here’s the Fritzing image we’re working towards:

Programmable RGB LED circuit. GPIO #5, #6, and #12 are wired to the momentary switches, and GPIO #26, #19, and #13 are wired to the base of the transistor switches. Slide switch remains available to select between 3.3 and 5 volt power source. Instead of using the pressing of momentary switches to directly complete the flow of current from power to ground by way of an associated leg of the RGB LED, a Python program will now continuously collect digital inputs from each momentary switch to determine if they are pressed or released. The code will also continuously send output to the base of each transistor to inform them of the state of the associated momentary switch, thereby electronically switching the red, green, and blue LEDs between on and off.

  1. Repurpose the three male-to-male jumper wires connecting the three momentary switches to the associated red, green, and blue cathode legs of the RGB LED. Connect the right legs of each momentary switch with its associated GPIO digital input pin.
    Diagram illustrating the layout of electronics on the breadboard after completion of step 1
    • Move the jumper wire connected to column 19 to instead connect to the upper rows of column 49, which is associated with GPIO #5. Leave the wire connected to column 3, bringing together the “red” push button with GPIO #5.
    • Move the jumper wire connected to column 21 to instead connect to the upper rows of column 48 which is associated with GPIO #6. Leave the wire connected to column 9, bringing together the “green” push button with GPIO #6.
    • Move the jumper wire connected to column 23 to instead connect to the lower rows of column 48, which is associated with GPIO #12. Leave the wire connected to column 15, bringing together the “blue” push button with GPIO #12.
    • Be sure to leave the male/male jumper wires connecting the left legs of the momentary switches with the blue ground rail on the breadboard.
  2. Add three PN2907A PNP bipolar transistors to the breadboard, connecting the collector legs to the associated red, green, and blue cathode legs of the RGB LED and the emitter legs to ground.
    Diagram illustrating the layout of electronics on the breadboard after completion of step 2
    • These should be placed in the upper rows of the breadboard, with the flat face of each transistor facing the lower rows. In so doing, the emitter leg will be on the left side of the transistors and the collector leg on the right side of the transistors.
    • Place one transistor in the upper rows of columns 25, 26, and 27. Connect column 25 to the blue ground rail. Connect column 27 to the upper rows of column 19.
    • Place a second transistor in the upper rows of columns 29, 30, and 31. Connect column 29 to the blue ground rail. Connect column 31 to the upper rows of column 21.
    • Place a third transistor in the upper rows of columns 33, 34, and 35. Connect column 33 to the blue ground rail. Connect column 35 to the upper rows of column 23.
  3. Finally, connect the base of each transistor with its associated GPIO digital output pin.
    Diagram illustrating the layout of electronics on the breadboard after completion of step 3
    • Connect the transistor base found in column 26 with the upper rows of column 45, which is GPIO #26.
    • Connect the transistor base found in column 30 with the upper rows of column 46, which is GPIO #19.
    • Connect the transistor base found in column 34 with the upper rows of column 47, which is GPIO #13.

In practice, when doing any of these breadboard exercises, your implementation may look a bit different than the Fritzing image to adjust for the actual components at hand. The key is to achieve the designated associations that we’ll next make use of within a Python program.

Part 2: Steps to Run the Code

For Part 2, we’ll now be working in the Raspberry Pi OS. While this can all be done from a terminal window (the standard Linux command-line Interface, or CLI), for most this is best done through a graphical user interface (GUI) using a monitor, keyboard, and mouse. These can either be directly connected to a Raspberry Pi, or as demonstrated in Orange Unit 4C, by using a RealVNC Viewer on your personal computer.

  1. In the web browser on the Raspberry Pi, enter:
    https://go.illinois.edu/switchLED
  2. Download the file “switchLED.py” to the Raspberry Pi. You do NOT need to log in or sign up to successfully open and download the Python code.
  3. Click on the “File Manager” icon in the Raspberry Pi Desktop Menu. Move switchLED.py from the Downloads folder to the /home/pi/Code/Python folder.
  4. Double click on the “switchLED.py” file. By default, files that end with .py will be opened with Thonny, a popular Python integrated development environment (IDE) that comes pre-installed on the Raspberry OS Desktop.
    • Click on the Run icon in Thonny. This is a common method within integrated development environments to test out new code. As such, you will see in the “Shell” window at the bottom the same display that would be shown if this code were being executed in a terminal window in practice moving forward.
    • Click on the Stop icon in Thonny, and then close the Thonny window.
  5. Click on the “Terminal” icon in the Raspberry Pi Desktop Menu. In terminal, type:
    cd /home/pi/Code/Python
    python switchLED.py

    You’ll now fully see the text provided by the switchLED.py code, with instructions for using the programmable switch. It also provides instructions to hold down the <CTRL> key and press the “c” key to exit this program.

Key Takeaways

Take a few minutes to go back to Thonny and skim through the code, especially noting:

  1. The three groupings of components associated with the red, green, and blue parallel circuits.
  2. The outputs are designated by the associated LED that will be lit. The inputs are designated by the associated momentary switch that is mechanically pressed and released.
  3. Your Raspberry Pi GPIO # should match the listed board.D number, being assigned within the digitalio.DigitalInOut library object definitions. For instance, the right leg of the “red” momentary switch should be connected to GPIO #5 to match board.D5 being assigned to switchR.
  4. At the bottom of the code, you’ll find the line “while True:” which starts a Python forever loop. The next three lines will continuously be run to update ledR.value to match the current switchR.value.
    • When a momentary switch is pressed, the digital input has a flow to ground. This sets the current to ground, which is identified as a binary zero. And as setup within the digitalio library, this is identified as a digital False.
    • When the ledR.value is next updated with the switchR.value, it will now be set to digital False/binary zero as well.
    • When the digital False/binary zero output reaches the base of the red transistor, the red rail’s 5-volt current, which flowed through the shared anode leg to the red cathode leg and through the 470 Ω resistor to the collector leg of the transistor, can now flow to the emitter leg of the transistor and then to the blue ground rail. The red circuit is closed, and the light comes on!

In previous sessions of the Orange Unit, circuits were constructed using electronic components without code.
Schematic showing the electronic components of the Momentary Switch Push Button in the previous session of the Orange Unit.

Looking at the new programmable code schematically, we can see three parallel momentary switches and three parallel LEDs as before. But each momentary switch is no longer directly, physically in series with its associated LED. Circuits are instead dynamically constructed and completed through code. This schematic shows us only the electronics of our new system. Code is not shown in schematics, as it can be readily changed to do different acts with the same physical structures. We are now truly opening the literal and conceptual hood of technology in a way that hopefully begins to demystify not just this example, but also more of your electronic components used as part of your daily life.
Schematic of programmable RGB LED circuit. GPIO #5, #6, and #12 of thet-cobbler are wired to the momentary switches, and GPIO #26, #19, and #13 of the t-cobbler are wired to the base of the transistor switches. Slide switch remains available to select between 3.3 and 5 volt power source on the t-cobbler. The schematic further illustrates that each of the 40 pins on the t-cobbler are connected to their counterpart pins on the Raspberry Pi GPIO.

As mentioned at the start of this activity, we chose to use the Raspberry Pi GPIO #5, #6, and #12 for the momentary switches, and GPIO #26, #19, and #13 for the LEDs to be integrated into programming code. In this case, the Raspberry Pi’s GPIO and associated electronics and embedded code together create one, more complex circuit. Code, in this case using the Python programming language, is used to determine the activities based on the state of the momentary switches and the design decisions controlling the state of the LEDs.

In what ways do you find the following true? False? As we move from circuits made exclusively of physical electronic parts to ones that also include programming code, greater opportunities for innovation-in-use become available.

Opening the Hidden Box of Today’s Keyboards

We’ve been steadily exploring different parts of basic electronic circuits, leading to the most recent exercises using a microcomputer to read inputs from a switch when it is pressed to complete a circuit. The microcomputer then provides a designated response, sending a ground signal to the associated cathode leg of an RGB LED to complete that circuit, thereby turning on that color of light.

The Raspberry Pi is a general-purpose microcomputer, allowing us to make use of a range of unassigned GPIO pins to create the electronic circuits and to edit and run Python code to work with these circuits. Take a moment to consider how many other applications are also running right now on the Raspberry Pi.

While general-purpose computers provide considerable flexibility, there are times when single-use computers and microprocessors are instead used. As one example, consider that which is used within a typical keyboard. Each key on the keyboard is physically a momentary switch push button and performs the same base function as that on our own coded circuit. But imagine what this might look like if there were 100+ parallel circuits being used, one for each key of your keyboard. That would be a lot of individual pins going into that microcontroller I/O port!

It’s for this reason that the keyboard uses a key matrix. Conceptually visualize your keyboard’s key matrix like a spreadsheet with rows and columns. Maybe you have a spreadsheet with 6 rows and 18 columns, providing you with 108 cells. By creating a cell map, when you see that one cell has just changed color, you just need to see which row and which column are associated with that cell, and then look at the cell map to determine what’s up.

As I look at the keyboard I’m using right now to type this text, I can see that my left pinky finger is hovering over row four, column four, starting from the upper left of the keyboard. That is, it is hovering over the letter “a” of my keyboard. If I move my right pinky finger to row 5, column 15 of my keyboard, I would hold down the shift key before pressing row four, column four, to get the letter “A” of my keyboard.

Instead of needing 108 IO pins for the keyboard microcontroller, I now only need 6 + 18 = 24 IO pins, plus an associated software character map.

Keyboards are a great case study in how basic circuit building, combined with strategic electronic layout design and data mapping, opens a wide range of human-centered design possibilities. For the Raspberry OS and the Raspbian Configuration program, this means we can quickly change the character map for any attached keyboard to make it work appropriately for the language of the user. Even if the keyboard microcontroller has a different character map with which it associates points on the key matrix of the keyboard, operating system software can often override some or all of that character map. Of course, this doesn’t change the physical characters written on the keyboard itself. But that doesn’t hold back someone who is a touch typist looking at the screen to see which momentary switch push button was just pressed.

One other note of import regarding our review of the keyboard as an introductory case study. The microcontroller inside the keyboard case may have 24 IO pins (probably more, as some are used as outputs for LEDs, and still others to communicate with the keyboard). But a wired keyboard cable is typically only providing four wires: the ground, power, transmit, and receive associated with the USB, or Universal Serial Bus, connection. This serves as another great example of how the electronics around us are often made with a mix of parallel and serial circuits joining and breaking away from other parallel and serial circuits. The keyboard, then, is a helpful case study in how various simple serial and parallel circuits artifacts come together to create a somewhat more complex set of serial and parallel circuit artifacts. Together, these become the system of a keyboard!

Wrap Up

We’ve gone from basic LED circuits in parallel using different levels of resistance and different voltages, to LEDs in series controlled by momentary switches, to integrated circuits, to code-based circuits. We have also taken our first dips into the Raspberry Pi microcomputer pond to see how these electronic parts, along with a range of other electronics, come together to create large, complex systems like computers.

A wide range of individual electronic components can be brought together using power and ground sources and conductors to build individual circuits, like the red, green, and blue LED circuits we created using the RGB LED with common anode. Using a printed circuit board, electronic components can be put together to create an integrated circuit, like the Sequin LED integrated circuit. Integrated circuits and additional electronic components can be further put together with code to create limited purpose microcontrollers like the Circuit Playground Express we’ll use in the Blue Unit, and general-purpose microcomputers like the Raspberry Pi.

We’ve begun to discover that software can open opportunities for further innovation-in-use, as is the case with different character maps for one keyboard key matrix. And in the character map example, we’ve also seen how software can at the same time restrict innovation-in-use, as is the case when an operating system or other software overrides a selected character map with its own standards for keyboard character associations. The configurations of our sociotechnical devices are multi-tiered hardware, software, and social constructs that are far from neutral. These constructs can come into conflict as data and information regarding past design choices are lost or hidden from viewing by current innovators. They shape current work, even as the current work seeks to further shape these sociotechnical devices.

As mentioned in a video segment at the beginning of this session, my history with computers goes back to the mid-1970s in junior high, and my work with general electronics even longer, as I grew up in my family’s sawmill. In this next video, I share my memories of electronics and programming during the late 1980s and early 1990s, as I worked on my research as a PhD student at Rutgers. You may find some similarities to the work we’ve just done!

Comprehension Check


  1. The website https://pinout.xyz/ provides a useful guide on the Raspberry Pi GPIO pins. They also provide a simple program you can run from the terminal window on your Raspberry Pi where you would type: pinout
  2. During beta-testing 2021-2022, the PiOLED was left connected and a half-sized breadboard was used. Male-to-female jumper wires were used to connect the appropriate pins on the Raspberry Pi GPIO with the associated holes on the breadboard. This remains an option for those with ongoing access of the same Raspberry Pi and for whom consistent access of data from the PiOLED and/or the smaller half-sized breadboard has proved of importance.

License

Icon for the Creative Commons Attribution-ShareAlike 4.0 International License

A Person-Centered Guide to Demystifying Technology, 2nd Edition Copyright © 2023 by Martin Wolske Copyright © 2023. Copyright “Ideating and Iterating Code: Scratch Example” © 2020 Betty Bayer and Stephanie Shallcross. Copyright “Introducing the Unix Command Line” © 2020 Martin Wolske, Dinesh Rathi, Henry Grob, and Vandana Singh. Copyright “Security and Privacy” © 2020 Sara Rasmussen. Copyright “Storytelling in the Information Sciences” © 2023 Yingying Han and Martin Wolske. This book is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License, except where otherwise noted.

Share This Book