Lab_interaccio/2020/ds3502_test/ds3502_test.ino

72 lines
2.1 KiB
Arduino
Raw Permalink Normal View History

2025-02-25 21:29:42 +01:00
#include <Adafruit_DS3502.h>
#include <Adafruit_ADS1015.h>
Adafruit_DS3502 ds3502 = Adafruit_DS3502();
Adafruit_ADS1115 ads; // Construct an ads1015 at the default address: 0x48
/* 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
*/
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");
// ads.setGain(GAIN_TWOTHIRDS); // 2/3x gain +/- 6.144V 1 bit = 3mV 0.1875mV (default)
// ads.setGain(GAIN_ONE); // 1x gain +/- 4.096V 1 bit = 2mV 0.125mV
// ads.setGain(GAIN_TWO); // 2x gain +/- 2.048V 1 bit = 1mV 0.0625mV
// ads.setGain(GAIN_FOUR); // 4x gain +/- 1.024V 1 bit = 0.5mV 0.03125mV
// ads.setGain(GAIN_EIGHT); // 8x gain +/- 0.512V 1 bit = 0.25mV 0.015625mV
// ads.setGain(GAIN_SIXTEEN); // 16x gain +/- 0.256V 1 bit = 0.125mV 0.0078125mV
ads.begin();
}
void loop() {
Serial.print("Wiper voltage with wiper set to 0: ");
ds3502.setWiper(0);
float wiper_value = ads.readADC_SingleEnded(0);
// wiper_value *= 5.0;
// wiper_value /= 1024;
wiper_value *= 0.1875;
Serial.print(wiper_value);
Serial.println(" mV");
Serial.println();
delay(1000);
Serial.print("Wiper voltage with wiper set to 63: ");
ds3502.setWiper(63);
wiper_value = ads.readADC_SingleEnded(0);
// wiper_value *= 5.0;
// wiper_value /= 32000;
wiper_value *= 0.1875;
Serial.print(wiper_value);
Serial.println(" mV");
Serial.println();
delay(1000);
Serial.print("Wiper voltage with wiper set to 127: ");
ds3502.setWiper(127);
wiper_value = ads.readADC_SingleEnded(0);
// wiper_value *= 5.0;
// wiper_value /= 1024;
wiper_value *= 0.1875;
Serial.print(wiper_value);
Serial.println(" mV");
Serial.println();
delay(1000);
}