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.
If the dependencies are already installed, you must make sure you update them through the Arduino Library Manager before loading the example!
// 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.
Text editor powered by tinymce.