Overview
Analog switches are a solid state alternative to relays, when you want a smaller, lower-power technology that won't wear out mechanically. And, as the name implies, you can use the Adafruit ADG728 1-to-8 Analog Matrix Switch to connect between eight analog signals, much like a set of 8 mechanical switches. These chips tend to be tiny surface mount parts, so this breakout will let anyone use the ADG728 switch for signals up to 5V, without fiddly soldering.
The ADG728 uses I2C to select which of the 8 channels switches to turn on or off, to connect that channel to the single analog 'D' pin. Note that unlike digital switches and multiplexers, these are not 'input' and 'output' because the signal is bidirectional. You could have the D signal be an input to 8 outputs, or the 8 inputs to one output.
Also, the ADG728 isn't really a 'selecting multiplexer', it's a matrix switch with 8 independent switches. That means that yes, you could treat it like an SP8T where you select which signal is routed to the D pin, you can also turn on multiple switches to 'merge' the signals together.
Unlike a relay or mechanical switch, analog switches don't wear out, and the switch time is near instant, about 100nS. The ADG728 chip also guarantees break-before-make so the deselected switches will open before selected switches close.
However, there's a few things to watch out for:
- The VIN power pin (the red wire if using a STEMMA QT cable) must as high as the highest analog voltages you want to switch. That means if the analog signals are no more than 5VDC, the V+ pin must be higher than 5V. You cannot power this pin with 3.3V and switch 5V signals.
- It cannot switch signals below ground. No negative voltages can be applied to the Switch or D pins!
- Analog switches are for signals, not power! Since this is not a mechanical switch, the signals pass through circuitry that is not designed to source or sink current. This is great for analog signal voltages, and is not good for providing more than a few mA of current.
In addition to the 8 switch S pins and the D pin that can be switched to, there are also two I2C address pins, so you can change the default address from 0x4C up to 0x4F. There's also a reset pin if you want to immediately set all the switches to open.
To get you going fast, we spun up a custom-made PCB in the STEMMA QT form factor, making it easy to interface with. The STEMMA QT connectors on either side are compatible with the SparkFun Qwiic I2C connectors. This allows you to make solderless connections between your development board and the ADG or to chain it with a wide range of other sensors and accessories using a compatible cable.
Page last edited April 16, 2024
Pinouts
The default I2C address is 0x4C.
Power Pins
- VIN - this is the power pin. To power the board, give it the same power as the logic level of your microcontroller - e.g. for a 5V microcontroller like Arduino, use 5V. It also needs to have the same voltage as the highest signal you are switching. That means if the analog signals are no more than 5VDC, the VIN pin must be higher than 5V. You cannot power this pin with 3.3V and switch 5V signals.
- GND - common ground for power and logic.
I2C Logic Pins
- SCL - I2C clock pin, connect to your microcontroller's I2C clock line. This pin can use 3-5V logic, and there's a 10K pullup on this pin.
- SDA - I2C data pin, connect to your microcontroller's I2C data line. This pin can use 3-5V logic, and there's a 10K pullup on this pin.
- STEMMA QT - These connectors allow you to connectors to dev boards with STEMMA QT (qwiic) connectors or to other things with various associated accessories
Analog Switch Pins
- S1-S8 - The 8 switch channels. Unlike digital switches and multiplexers, these channels are not strictly 'inputs' or 'outputs' because the signal is bidirectional.
- D - The analog pin for the switch. D can act as input or an output. It can be an input to the 8 channel outputs, or the 8 channel inputs can be output to D.
This breakout isn't really a 'selecting multiplexer', a matrix switch with 8 independent switches. You could treat it like an SP8T where you select which of the 8 channels are routed to the D pin. You can also turn on multiple channels to 'merge' the signals together.
There are a few things to keep in mind when using these pins:
- The switch signals cannot be below ground. No negative voltages can be applied to the Switch or D pins!
- Analog switches are for signals, not power! Since this is not a mechanical switch, the signals pass through circuitry that is not designed to source or sink current. This is great for analog signal voltages, and is not good for providing more than a few mA of current.
Address Pins
On the back of the board are two address jumpers, labeled A0 and A1. These jumpers allow you to chain up to 4 of these boards on the same pair of I2C clock and data pins. To do so, you solder the jumpers "closed" by connecting the two pads.
On the front of the board are two address pins, labeled A0 and A1. Just like the jumpers, these pins allow you to change the I2C address to connect multiple boards by connecting them to VIN.
The default I2C address is 0x4C. The other address options can be calculated by "adding" the A0/A1 to the base of 0x4C.
A0 sets the lowest bit with a value of 1 and A1 sets the next bit with a value of 2. The final address is 0x4C + A1 + A0 which would be 0x4F.
If only A0 is soldered closed, the address is 0x4C + 1 = 0x4D
If only A1 is soldered closed, the address is 0x4C + 2 = 0x4E
The table below shows all possible addresses, and whether the pin(s) should be high (closed) or low (open).
Reset Pin
- RST - This is the reset pin for the ADG728. You can tie it to GND to immediately set all the switch channels to open.
Power LED and LED Jumper
- Power LED - In the upper left corner, above the STEMMA connector, on the front of the board, is the power LED, labeled on. It is a green LED.
- LED jumper - This jumper is located on the back of the board, in the upper right corner. It's labeled LED on the board silk. Cut the trace on this jumper to cut power to the "on" LED.
Page last edited April 16, 2024
CircuitPython
It's easy to use the ADG728 with CircuitPython and and the Adafruit_CircuitPython_ADG72x module. This module allows you to easily write Python code to control the matrix switch.
CircuitPython Microcontroller Wiring
First wire up the switch to your board exactly as follows. The following is the switch wired to a Feather RP2040 using the STEMMA QT connector. You'll connect your two external analog inputs to S1 and S5.
-
Board STEMMA 3V to switch VIN (red wire)
-
Board STEMMA GND to switch GND (black wire)
-
Board STEMMA SCL to switch SCL (yellow wire)
- Board STEMMA SDA to switch SDA (blue wire)
- Board A0 to switch D (purple wire)
- Analog signal 1 to switch S1 (orange wire)
- Analog signal 2 to switch S5 (green wire)
Make sure to share all grounds between the incoming analog signals and the circuit.
The following is the switch wired to a Feather RP2040 using a solderless breadboard:
-
Board 3V to switch VIN (red wire)
-
Board GND to switch GND (black wire)
-
Board SCL to switch SCL (yellow wire)
- Board SDA to switch SDA (blue wire)
- Board A0 to switch D (purple wire)
- Analog signal 1 to switch S1 (orange wire)
- Analog signal 2 to switch S5 (green wire)
Make sure to share all grounds between the incoming analog signals and the circuit.
CircuitPython Usage
To use with CircuitPython, you need to first install the Adafruit_CircuitPython_ADG72x library, and its dependencies, into the lib folder on your CIRCUITPY drive. Then you need to update code.py with the example script.
Thankfully, we can do this in one go. In the example below, click the Download Project Bundle button below to download the necessary libraries and the code.py file in a zip file. Extract the contents of the zip file, and copy the entire lib folder and the code.py file to your CIRCUITPY drive.
Your CIRCUITPY/lib folder should contain the following folder and file:
- adafruit_bus_device/
- adafruit_adg72x.mpy
Example Code
Once everything is saved to the CIRCUITPY drive, connect to the serial console to see the data printed out!
# SPDX-FileCopyrightText: Copyright (c) 2024 Liz Clark for Adafruit Industries
#
# SPDX-License-Identifier: MIT
import time
import board
import adafruit_adg72x
from analogio import AnalogIn
analog_in = AnalogIn(board.A0)
i2c = board.I2C()
switch = adafruit_adg72x.ADG72x(i2c)
c = 0
switch_time = 2
channels = [0, 4]
clock = time.monotonic()
while True:
if (time.monotonic() - clock) > switch_time:
print(f"Selecting channel {channels[c] + 1}")
switch.channel = channels[c]
c = (c + 1) % 2
clock = time.monotonic()
print((analog_in.value,))
time.sleep(0.1)
Every two seconds, the ADG728 switches channels being sent to pin D. In the .GIF below, you'll see analog signals on channel 1 (S1) and channel 5 (S5) being read from pin D to board pin A0 as their channels are turned on.
Page last edited April 16, 2024
Arduino
Using the ADG728 breakout with Arduino involves wiring up the breakout to your Arduino-compatible microcontroller, installing the Adafruit_ADG72x library, and running the provided example code.
Wiring
Wire as shown for a 5V board like an Uno. If you are using a 3V board, like an Adafruit Feather, wire the board's 3V pin to the sensor VIN.
Here is an Adafruit Metro wired up to the breakout using the STEMMA QT connector. You'll connect your two external analog inputs to S1 and S5:
-
Board 5V to switch VIN (red wire)
-
Board GND to switch GND (black wire)
-
Board SCL to switch SCL (yellow wire)
- Board SDA to switch SDA (blue wire)
- Board A0 to switch D (purple wire)
- Analog signal 1 to switch S1 (orange wire)
- Analog signal 2 to switch S5 (green wire)
Make sure to share all grounds between the incoming analog signals and the circuit.
Here is an Adafruit Metro wired up using a solderless breadboard:
-
Board 5V to switch VIN (red wire)
-
Board GND to switch GND (black wire)
-
Board SCL to switch SCL (yellow wire)
- Board SDA to switch SDA (blue wire)
- Board A0 to switch D (purple wire)
- Analog signal 1 to switch S1 (orange wire)
- Analog signal 2 to switch S5 (green wire)
Make sure to share all grounds between the incoming analog signals and the circuit.
Library Installation
You can install the Adafruit_ADG72x library for Arduino using the Library Manager in the Arduino IDE.
Click the Manage Libraries ... menu item, search for Adafruit_ADG72x, and select the Adafruit ADG72x library:
If asked about dependencies, click "Install all".
If the "Dependencies" window does not come up, then you already have the dependencies installed.
// SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries
//
// SPDX-License-Identifier: MIT
#include <Adafruit_ADG72x.h>
Adafruit_ADG72x adg72x;
bool isADG728 = false; // which chip are we connected to?
int analogIn = A0;
int analogValue = 0;
unsigned long switchTimer = 1000; // 1000 ms = 1 second for channel switch
unsigned long readTimer = 10; // 10 ms for analog read
unsigned long lastSwitchTime = 0; // Last time the channels were switched
unsigned long lastReadTime = 0; // Last time the analog was read
uint8_t currentChannel = 0; // Current channel being selected
void setup() {
Serial.begin(115200);
// Wait for serial port to open
while (!Serial) {
delay(1);
}
// Try with the ADG728 default address first...
if (adg72x.begin(ADG728_DEFAULT_ADDR, &Wire)) {
Serial.println("ADG728 found!");
isADG728 = true;
}
// Maybe they have an ADG729?
else if (adg72x.begin(ADG729_DEFAULT_ADDR, &Wire)) {
Serial.println("ADG729 found!");
isADG728 = false;
}
else {
Serial.println("No ADG device found? Check wiring!");
while (1); // Stop here if no device was found
}
}
void loop() {
unsigned long currentTime = millis();
// read and print analog value every 10ms
if ((currentTime - lastReadTime) >= readTimer) {
analogValue = analogRead(analogIn);
Serial.println(analogValue);
lastReadTime = currentTime;
}
// switch channels every 1 second
if ((currentTime - lastSwitchTime) >= switchTimer) {
uint8_t bits = 1 << currentChannel; // Shift a '1' from LSB to MSB
if (!adg72x.selectChannels(bits)) {
Serial.println("Failed to set channels...");
}
/*Serial.print((currentChannel % 4) + 1);
if (currentChannel < 4) Serial.println("A");
else Serial.println("B");*/
currentChannel = (currentChannel + 1) % 8; // Move to the next channel, wrap around at 8
lastSwitchTime = currentTime;
}
}
Upload the sketch to your board and open up the Serial Plotter (Tools -> Serial Plotter) at 115200 baud. You'll see the analog data printed to the plotter. Every two seconds, the ADG728 switches channels being sent to pin D. In the .GIF below, you'll see analog signals on channel 1 (S1) and channel 5 (S5) being read from pin D to board pin A0 as their channels are turned on.
Page last edited April 16, 2024
Downloads
Page last edited April 16, 2024