I'm trying out a different digital potentiometer. A month ago some people on this forum helped me out with another digital potentiometer that worked fine, but had some linearity issues. Now this one does not work at all.
The potentiometer is an Analog Devices AD 8402A10, which is 0 to 10k Ohms in 255 steps. The data sheet is:
www.analog.com/static/imported-files/data_sheets/AD8400_8402_8403.pdfI use the following code to step the potentiometer through steps of 10 up to 250, then down from 255. The output measured by running a wire from the wiper to an Arduino analog input pin. That same wiper pin has a 2.5 k Ohms resistor connected to ground.
// include the SPI library:
#include <SPI.h>
#define potInputPin 0
// set pin 10 as the slave select for the digital pot:
const int slaveSelectPin = 10;
int potValue;
void setup() {
// start serial port at 9600 bits per second
Serial.begin(9600);
// clear the serial port buffer
Serial.flush();
// set the slaveSelectPin as an output:
pinMode (slaveSelectPin, OUTPUT);
// initialize SPI:
SPI.begin();
}
void loop() {
// change the resistance from min to max:
for (int level = 0; level < 255; level = level + 10) {
digitalPotWrite(0, level);
Serial.print("Pot Level: ");
Serial.print(level);
Serial.print("\t");
delay(1000);
potValue = analogRead(potInputPin);
Serial.print("Pot Value: ");
Serial.print(potValue);
Serial.print("\n");
}
// wait a second at the top:
Serial.print("\n");
delay(1000);
// change the resistance from max to min:
for (int level = 0; level < 255; level = level + 10) {
digitalPotWrite(0, 255 - level);
Serial.print("Pot Level: ");
Serial.print(255 - level);
Serial.print("\t");
delay(1000);
potValue = analogRead(potInputPin);
Serial.print("Pot Value: ");
Serial.print(potValue);
Serial.print("\n");
}
delay(1000);
}
int digitalPotWrite(int command, int value) {
// take the SS pin low to select the chip:
digitalWrite(slaveSelectPin,LOW);
// send in the value via SPI:
SPI.transfer(command);
SPI.transfer(value);
// take the SS pin high to de-select the chip:
digitalWrite(slaveSelectPin,HIGH);
}
The Arduino analog input pin shows no sign of a step change. It bounces around between a few values, but there seems no rhyme or reason to them.
Any thoughts?