Digital i/o: Introduction

Computers on their own are quite a powerful tool, being able to evaluate arithmetic and logical expressions in the fraction of a time it would take a human to do them (especially for larger values). They are also useful for repeatedly performing menial tasks. Imagine if you had to flip a switch once every second for the next two hours. It’s certainly not an engaging task, and your time could be better invested in doing other, more complicated things. Instead, you could leave this flip-switching task to a computer, capable of doing the task for an infinitely long amount of time so as long as it does not malfunction and has power.

But all a computer can do is flip bits and do math with 1’s and 0’s. How can we expect it to operate a switch? On its own, a computer can not do much physically. However, with the use of peripherals, computers become a versatile tool. Peripherals, or auxiliary devices that are not part of the main computer, bridge the gap between digital computations and physical operations. Suppose we made an electrical connection between the switch and the microcontroller such that the switch flips on when receiving a high voltage and flips off when receiving a low voltage. The switch is now acting as a peripheral, and if we assign a bit to that peripheral, we can simply adjust the value of the bit to affect the state of the switch.

(Source: https://www.webopedia.com/TERM/P/peripheral_device.html)

Now, suppose a new model of our microcontroller is released and is more efficient in every possible way than the old model. Seeing as how this arbitrary switch-flipping task could be made more efficient, we buy the newer model, sever the connection between the switch and the old model, and reconnect the switch to the newer model. This is the very nature of a peripheral: the connections between the peripheral and the computer can always be severed or reconnected. Even if you disconnect a peripheral, the computer is still functional. By contrast, disconnecting the memory unit, for example, renders the computer dysfunctional. So the memory unit of a computer does not classify as a peripheral.


For a more practical example, headphones are a type of peripheral for modern laptops. You can connect them through the headphone jack or connect them through Bluetooth, but you can also just as easily disconnect them. The sound that you hear from the headphones is really just a sequence of 1’s and 0’s that the peripheral receives from the computer and translates into sounds. Similarly, styluses are another type of peripheral for modern laptops and tablets. However, this kind of peripheral acts as an input rather than an output. So rather than reading in data from the computer, this peripheral instead provides the computer with data. And as always, this peripheral can be disconnected at any time. In essence, a peripheral can be connected or disconnected at any time, and they can also serve as an input or an output. This nature serves as the basis for general-purpose input/output.