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 January 21, 2025
Text editor powered by tinymce.