Wiring
Wiring the DS3502 to communicate with your microcontroller is straight forward forward thanks to the I2C interface. For these examples we can use the Metro or Arduino to measure the voltage changes as the DS3502 adjusts its resistance. The instructions below reference a Metro, but the same applies to an Arduino
- Connect the Metro 5V to Vcc on the DS3502
- Connect GND on the Metro to GND on the DS3502
- Connect the SCL pins on the Metro and DS3502
- Connect the SDA pins on the Metro and DS3502
- Connect RL to GND
- Connect RH to Metro 5V
- Connect RW to the A0 pin on the Metro, to allow us to measure the voltage
Using a STEMMA QT cable makes it super easy. Pick a cable length and plug one into a STEMMA QT capable controller and the other end into the DS3502.
Library Installation
Once wired up, to start using the DS3502, you'll need to install the Adafruit_DS3502 library. The library is available through the Arduino library manager so we recommend taking that approach.
From the Arduino IDE, open up the Library Manager:
Click the Manage Libraries ... menu item, search for Adafruit DS3502, and select the Adafruit DS3502 library and click Install:
Follow the same process to install the Adafruit BusIO library.
Load Example
Open up File -> Examples -> Adafruit DS3502 -> ds3502_test and upload to your Metro wired up to the DS3502 breakout as shown above. Once you upload the code, you will see the wiper settings and measured voltage being printed when you open the Serial Monitor (Tools->Serial Monitor) at 115200 baud, similar to this:
Example Code
The following code is part of the standard library and illustrates the basic function of using the variable resistance of the DS3502 to change the voltage measured at pin A0:
#include <Adafruit_DS3502.h> Adafruit_DS3502 ds3502 = Adafruit_DS3502(); /* For this example, make the following connections: * DS3502 RH to 5V * DS3502 RL to GND * DS3502 RW to the pin specified by WIPER_VALUE_PIN */ #define WIPER_VALUE_PIN A0 void setup() { Serial.begin(115200); // Wait until serial port is opened while (!Serial) { delay(1); } Serial.println("Adafruit DS3502 Test"); if (!ds3502.begin()) { Serial.println("Couldn't find DS3502 chip"); while (1); } Serial.println("Found DS3502 chip"); } void loop() { Serial.print("Wiper voltage with wiper set to 0: "); ds3502.setWiper(0); float wiper_value = analogRead(WIPER_VALUE_PIN); wiper_value *= 5.0; wiper_value /= 1024; Serial.print(wiper_value); Serial.println(" V"); Serial.println(); delay(1000); Serial.print("Wiper voltage with wiper set to 63: "); ds3502.setWiper(63); wiper_value = analogRead(WIPER_VALUE_PIN); wiper_value *= 5.0; wiper_value /= 1024; Serial.print(wiper_value); Serial.println(" V"); Serial.println(); delay(1000); Serial.print("Wiper voltage with wiper set to 127: "); ds3502.setWiper(127); wiper_value = analogRead(WIPER_VALUE_PIN); wiper_value *= 5.0; wiper_value /= 1024; Serial.print(wiper_value); Serial.println(" V"); Serial.println(); delay(1000); }
Text editor powered by tinymce.