DS 3502 with Teensy 4.1

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
jim53
 
Posts: 6
Joined: Tue Sep 07, 2021 8:59 pm

DS 3502 with Teensy 4.1

Post by jim53 »

Hello, I have been trying to get the DS 3502 variable potentiometer working with my Teensy 4.1. I first tested it with an Adafruit Metro 328 which had been set to run with 3.3 V, similar to the Teensy. On the Metro, when running the example code, I got what was expected, reading 0V for wiper of 0, 1.66V for wiper of 63 and 3.3 V for wiper of 127. When connecting it the same way to the Teensy, I instead get 0 V for wiper of 0, 1.33V for wiper of 63 and 3.3V for wiper of 127. I also usually need to unplug the power supply whenever I reinitiate the code, or it will give me strange values. I switched the wiper values in the loop to 0, 90, 127 and got 1.65 for 0, 1.21 for 90 and 2.87 for 127. If I then unplug Vcc and plug it back in, I get more reasonable voltages, but with the wrong wiper values. 3.3 for 0, 0 for 90 and 2.42 for 127. All in all, I am quite confused as to why all of this is happening when it works fine on a Metro 328. I even tried a different Teensy 4.1 and a different DS3502 found the same values.

The wiring is currently SCL to 19, SDA to 18, Ground to Ground, Vcc to 3.3V and RW to A0. The Ground is then connected on the breadboard to RL while the Vcc is connected to RH. The code is below. Any help would be appreciated.

Code: Select all

#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() {
  //Wire.setSCL(16);
  //Wire.setSDA(17);
  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");
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);
}

void loop() {
  Serial.print("Wiper voltage with wiper set to 0: ");
  ds3502.setWiper(0);
  float wiper_value = analogRead(WIPER_VALUE_PIN);
  wiper_value *= 3.3;
  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(90);
  wiper_value = analogRead(WIPER_VALUE_PIN);
  wiper_value *= 3.3;
  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 *= 3.3;
  wiper_value /= 1024;
  Serial.print(wiper_value);
  Serial.println(" V");

  Serial.println();
  delay(1000);
}

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”