diff --git a/ADG72x_Examples/Arduino_ADG728_Plotter/Arduino_ADG728_Plotter.ino b/ADG72x_Examples/Arduino_ADG728_Plotter/Arduino_ADG728_Plotter.ino new file mode 100644 index 000000000..fcf6b8345 --- /dev/null +++ b/ADG72x_Examples/Arduino_ADG728_Plotter/Arduino_ADG728_Plotter.ino @@ -0,0 +1,65 @@ +// SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#include + +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; + } +} diff --git a/ADG72x_Examples/Arduino_ADG729_Plotter/Arduino_ADG729_Plotter.ino b/ADG72x_Examples/Arduino_ADG729_Plotter/Arduino_ADG729_Plotter.ino new file mode 100644 index 000000000..c704b578b --- /dev/null +++ b/ADG72x_Examples/Arduino_ADG729_Plotter/Arduino_ADG729_Plotter.ino @@ -0,0 +1,66 @@ +// SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#include + +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; + } +} diff --git a/ADG72x_Examples/Arduino_ADG72x_Plotter/Arduino_ADG72x_Plotter.ino b/ADG72x_Examples/Arduino_ADG72x_Plotter/Arduino_ADG72x_Plotter.ino deleted file mode 100644 index 66f33dbac..000000000 --- a/ADG72x_Examples/Arduino_ADG72x_Plotter/Arduino_ADG72x_Plotter.ino +++ /dev/null @@ -1,58 +0,0 @@ -// SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries -// -// SPDX-License-Identifier: MIT - -#include - -Adafruit_ADG72x adg72x; - -bool isADG728 = false; // which chip are we connected to? - -int analogIn = A0; -int analogValue = 0; -unsigned long timer = 2000; -unsigned long startTime = millis(); - -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() { - analogValue = analogRead(analogIn); - Serial.println(analogValue); - - if ((millis() - startTime) >= timer) { - for (uint8_t i = 0; i < 8; i++) { - if (isADG728) { - } else { - if (i < 4) Serial.println("A"); - else Serial.println("B"); - } - uint8_t bits = 1 << i; // Shift a '1' from LSB to MSB - if (!adg72x.selectChannels(bits)) { - } - startTime = millis(); - } - } - delay(10); -} diff --git a/ADG72x_Examples/CircuitPython/code.py b/ADG72x_Examples/CircuitPython_ADG728/code.py similarity index 100% rename from ADG72x_Examples/CircuitPython/code.py rename to ADG72x_Examples/CircuitPython_ADG728/code.py diff --git a/ADG72x_Examples/CircuitPython_ADG729/code.py b/ADG72x_Examples/CircuitPython_ADG729/code.py new file mode 100644 index 000000000..6b0dad45c --- /dev/null +++ b/ADG72x_Examples/CircuitPython_ADG729/code.py @@ -0,0 +1,31 @@ +# 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)