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 ADG729 Dual 1-to-4 Analog Matrix Switches to connect between two sets of four analog signals, much like 8 mechanical switches. These chips tend to be tiny surface mount parts, so this breakout will let anyone use the ADG729 switch for signals up to 5V, without fiddly soldering.
The ADG729 uses I2C to select which of the 8 channels switches to turn on or off. Four channels connect to the DA analog pin, and the other four channels connect to the DB analog pin. Note that unlike digital switches and multiplexers, these are not 'input' and 'output' because the signal is bidirectional. You could have the DA or DB signal be an input to 4 outputs, or the 4 inputs to one output.
Also, the ADG729 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 DP4T where you select which signal is routed to the D pin, you can also turn on multiple switches to 'merge' the signals together. If you want all 8 signals to be able to route to a single pin, check out the ADG728.
Unlike a relay or mechanical switch, analog switches don't wear out, and the switch time is near instant, about 100nS. The ADG729 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 DA/DB 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 two D pins that can be switched to, there are also two I2C address pins so you can change the default address from 0x44 up to 0x47.
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 17, 2024
Text editor powered by tinymce.
Pinouts
The default I2C address is 0x44.
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
- 1A/B - 4A/B - The two sets of four analog switch channels. Unlike digital switches and multiplexers, these channels are not strictly 'inputs' or 'outputs' because the signal is bidirectional.
- DA and DB - The analog pins for the switch. DA is connected to channels 1A-4A and DB is connected to channels 1B-4B. These pins can act as input or an output.
This breakout isn't really a 'selecting multiplexer', a matrix switch with 8 independent switches. You could treat it like an DP4T where you select which of the 4 channels are routed to the DA or DB 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 0x44. The other address options can be calculated by "adding" the A0/A1 to the base of 0x44.
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 0x44 + A1 + A0 which would be 0x47.
If only A0 is soldered closed, the address is 0x44 + 1 = 0x45
If only A1 is soldered closed, the address is 0x44 + 2 = 0x46
The table below shows all possible addresses, and whether the pin(s) should be high (closed) or low (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 17, 2024
Text editor powered by tinymce.
CircuitPython
It's easy to use the ADG729 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 external analog input to 1A and 1B.
-
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 DA (purple wire)
- Board A1 to switch DB (pink wire)
- Analog signal to switch 1A (orange wire) and switch 1B (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 DA (purple wire)
- Board A1 to switch DB (pink wire)
- Analog signal to switch 1A (orange wire) and switch 1B (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_DA = AnalogIn(board.A0)
analog_in_DB = AnalogIn(board.A1)
i2c = board.I2C()
switch = adafruit_adg72x.ADG72x(i2c, 0x44)
c = 0
switch_time = 3
clock = time.monotonic()
while True:
if (time.monotonic() - clock) > switch_time:
if c < 4:
channels = "A"
else:
channels = "B"
print(f"Selecting channel {(c % 4) + 1}{channels}")
switch.channel = c
c = (c + 1) % 8
clock = time.monotonic()
print((analog_in_DA.value, analog_in_DB.value,))
time.sleep(0.1)
Every two seconds, the ADG729 switches channels being sent to pins DA and DB. In the .GIF below, you'll see analog signals on channel 1 (1A and 1B) being read from pin DA to board pin A0 and pin DB to board pin A1 as their channels are turned on.
Page last edited April 17, 2024
Text editor powered by tinymce.
Arduino
Using the ADG729 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 board's VIN.
Here is an Adafruit Metro wired up to the breakout using the STEMMA QT connector. You'll connect your external analog input to 1A and 1B:
-
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 DA (purple wire)
- Board A1 to switch DB (pink wire)
- Analog signal to switch 1A (orange wire) and switch 1B (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 DA (purple wire)
- Board A1 to switch DB (pink wire)
- Analog signal to switch 1A (orange wire) and switch 1B (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".
// SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries
//
// SPDX-License-Identifier: MIT
#include <Adafruit_ADG72x.h>
Adafruit_ADG72x adg72x;
int analogInA0 = A0;
int analogInA1 = A1;
int analogValueDA = 0;
int analogValueDB = 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!");
}
// Maybe they have an ADG729?
else if (adg72x.begin(ADG729_DEFAULT_ADDR, &Wire)) {
//Serial.println("ADG729 found!");
}
else {
Serial.println("No ADG72x 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) {
analogValueDA = analogRead(analogInA0);
analogValueDB = analogRead(analogInA1);
Serial.print(analogValueDA);
Serial.print(",");
Serial.println(analogValueDB);
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 ADG729 switches channels being sent to pins DA and DB. In the .GIF below, you'll see analog signals on channel 1 (1A and 1B) being read from pin DA to board pin A0 and pin DB to board pin A1 as their channels are turned on.
Page last edited April 17, 2024
Text editor powered by tinymce.
Downloads
Page last edited April 17, 2024
Text editor powered by tinymce.