Skip to content

Commit 5325095

Browse files
committed
adding ADG729 examples
adding ADG729 examples for Arduino and CircuitPython
1 parent 297910a commit 5325095

File tree

5 files changed

+162
-58
lines changed

5 files changed

+162
-58
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
#include <Adafruit_ADG72x.h>
6+
7+
Adafruit_ADG72x adg72x;
8+
9+
bool isADG728 = false; // which chip are we connected to?
10+
11+
int analogIn = A0;
12+
int analogValue = 0;
13+
unsigned long switchTimer = 1000; // 1000 ms = 1 second for channel switch
14+
unsigned long readTimer = 10; // 10 ms for analog read
15+
unsigned long lastSwitchTime = 0; // Last time the channels were switched
16+
unsigned long lastReadTime = 0; // Last time the analog was read
17+
uint8_t currentChannel = 0; // Current channel being selected
18+
19+
void setup() {
20+
Serial.begin(115200);
21+
22+
// Wait for serial port to open
23+
while (!Serial) {
24+
delay(1);
25+
}
26+
27+
// Try with the ADG728 default address first...
28+
if (adg72x.begin(ADG728_DEFAULT_ADDR, &Wire)) {
29+
Serial.println("ADG728 found!");
30+
isADG728 = true;
31+
}
32+
// Maybe they have an ADG729?
33+
else if (adg72x.begin(ADG729_DEFAULT_ADDR, &Wire)) {
34+
Serial.println("ADG729 found!");
35+
isADG728 = false;
36+
}
37+
else {
38+
Serial.println("No ADG device found? Check wiring!");
39+
while (1); // Stop here if no device was found
40+
}
41+
}
42+
43+
void loop() {
44+
unsigned long currentTime = millis();
45+
46+
// read and print analog value every 10ms
47+
if ((currentTime - lastReadTime) >= readTimer) {
48+
analogValue = analogRead(analogIn);
49+
Serial.println(analogValue);
50+
lastReadTime = currentTime;
51+
}
52+
53+
// switch channels every 1 second
54+
if ((currentTime - lastSwitchTime) >= switchTimer) {
55+
uint8_t bits = 1 << currentChannel; // Shift a '1' from LSB to MSB
56+
if (!adg72x.selectChannels(bits)) {
57+
Serial.println("Failed to set channels...");
58+
}
59+
/*Serial.print((currentChannel % 4) + 1);
60+
if (currentChannel < 4) Serial.println("A");
61+
else Serial.println("B");*/
62+
currentChannel = (currentChannel + 1) % 8; // Move to the next channel, wrap around at 8
63+
lastSwitchTime = currentTime;
64+
}
65+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
#include <Adafruit_ADG72x.h>
6+
7+
Adafruit_ADG72x adg72x;
8+
9+
int analogInA0 = A0;
10+
int analogInA1 = A1;
11+
int analogValueDA = 0;
12+
int analogValueDB = 0;
13+
unsigned long switchTimer = 1000; // 1000 ms = 1 second for channel switch
14+
unsigned long readTimer = 10; // 10 ms for analog read
15+
unsigned long lastSwitchTime = 0; // Last time the channels were switched
16+
unsigned long lastReadTime = 0; // Last time the analog was read
17+
uint8_t currentChannel = 0; // Current channel being selected
18+
19+
void setup() {
20+
Serial.begin(115200);
21+
22+
// Wait for serial port to open
23+
while (!Serial) {
24+
delay(1);
25+
}
26+
27+
// Try with the ADG728 default address first...
28+
if (adg72x.begin(ADG728_DEFAULT_ADDR, &Wire)) {
29+
//Serial.println("ADG728 found!");
30+
}
31+
// Maybe they have an ADG729?
32+
else if (adg72x.begin(ADG729_DEFAULT_ADDR, &Wire)) {
33+
//Serial.println("ADG729 found!");
34+
}
35+
else {
36+
Serial.println("No ADG72x device found? Check wiring!");
37+
while (1); // Stop here if no device was found
38+
}
39+
}
40+
41+
void loop() {
42+
unsigned long currentTime = millis();
43+
44+
// read and print analog value every 10ms
45+
if ((currentTime - lastReadTime) >= readTimer) {
46+
analogValueDA = analogRead(analogInA0);
47+
analogValueDB = analogRead(analogInA1);
48+
Serial.print(analogValueDA);
49+
Serial.print(",");
50+
Serial.println(analogValueDB);
51+
lastReadTime = currentTime;
52+
}
53+
54+
// switch channels every 1 second
55+
if ((currentTime - lastSwitchTime) >= switchTimer) {
56+
uint8_t bits = 1 << currentChannel; // Shift a '1' from LSB to MSB
57+
if (!adg72x.selectChannels(bits)) {
58+
Serial.println("Failed to set channels...");
59+
}
60+
/*Serial.print((currentChannel % 4) + 1);
61+
if (currentChannel < 4) Serial.println("A");
62+
else Serial.println("B");*/
63+
currentChannel = (currentChannel + 1) % 8; // Move to the next channel, wrap around at 8
64+
lastSwitchTime = currentTime;
65+
}
66+
}

ADG72x_Examples/Arduino_ADG72x_Plotter/Arduino_ADG72x_Plotter.ino

Lines changed: 0 additions & 58 deletions
This file was deleted.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2024 Liz Clark for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
import time
6+
import board
7+
import adafruit_adg72x
8+
from analogio import AnalogIn
9+
10+
analog_in_DA = AnalogIn(board.A0)
11+
analog_in_DB = AnalogIn(board.A1)
12+
13+
i2c = board.I2C()
14+
switch = adafruit_adg72x.ADG72x(i2c, 0x44)
15+
16+
c = 0
17+
switch_time = 3
18+
clock = time.monotonic()
19+
20+
while True:
21+
if (time.monotonic() - clock) > switch_time:
22+
if c < 4:
23+
channels = "A"
24+
else:
25+
channels = "B"
26+
print(f"Selecting channel {(c % 4) + 1}{channels}")
27+
switch.channel = c
28+
c = (c + 1) % 8
29+
clock = time.monotonic()
30+
print((analog_in_DA.value, analog_in_DB.value,))
31+
time.sleep(0.1)

0 commit comments

Comments
 (0)