Digital inputs and outputs (or I/O) are some of the simplest and most powerful ways to interact with hardware. Using digital I/O you can talk to devices with simple on and off signals, like turning a LED on/off or reading if a button is pressed. In CircuitPython using digital I/O is easy with a few modules that this guide will explore.
Before diving in to how to digital I/O works you’ll want to understand what is a digital signal. In the simplest sense a digital signal is a simple on or off signal–i.e. there are only two possible states for the signal to be in. Think of this almost like a binary digit that’s either 0 or 1. With a digital signal it can only ever be 0/off or 1/on, there is no in-between!
At a physical level digital signals are represented with high and low voltage levels. A digital signal that’s on will be at a ‘high’ voltage level, typically 3.3 volts or more (depending on the specifications of your microprocessor or development board), and a signal that’s off will be at a ‘low’ voltage level of zero volts (also called ground). You can actually see this voltage with a multimeter set to measure DC voltage–try connecting a multimeter to a button or LED and watch the voltage as digital signal changes from on to off and vice-versa.
What can you do with a digital signal? It turns out quite a few interesting components are controlled with simple on/off digital I/O!
- Buttons and switches
- Magnetic or hall-effect sensors
- PIR motion sensors
- Simple vibration sensors
- Beam-break sensors
- Liquid level sensors
- Tilt switches
- Simple wireless remote controls
- Single color LEDs
- Relays to control high-power devices
- Solenoids that push or pull objects
- Vibration motors
- Buzzers (not piezo buzzers that require an analog signal though!)
In addition to devices like the above you can also use digital signals for simple communication between two devices. A digital output of one device, like your development board, can be connected to another device’s digital input, like an audio FX board that plays music and sound effects. There are even fast protocols like I2C or SPI for sending large amounts of data over a digital signal, but we’ll cover those in a later guide.