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.
I 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.
I had the low side of the potentiometer floating. I have now connected it to GND.
I had the high side of the potentiometer already connected to +5 Volts.
I removed the 2.5k Ohm resistor.
The data still looks rather like noise.
Pot Level: 0 Pot Value: 4
Pot Level: 10 Pot Value: 1023
Pot Level: 20 Pot Value: 1023
Pot Level: 30 Pot Value: 455
Pot Level: 40 Pot Value: 4
Pot Level: 50 Pot Value: 5
Pot Level: 60 Pot Value: 1023
Pot Level: 70 Pot Value: 1023
Pot Level: 80 Pot Value: 1023
Pot Level: 90 Pot Value: 1023
Pot Level: 100 Pot Value: 1023
Pot Level: 110 Pot Value: 1023
Pot Level: 120 Pot Value: 1023
Pot Level: 130 Pot Value: 1023
Pot Level: 140 Pot Value: 1023
Pot Level: 150 Pot Value: 1023
Pot Level: 160 Pot Value: 1023
Pot Level: 170 Pot Value: 1023
Pot Level: 180 Pot Value: 1023
Pot Level: 190 Pot Value: 1023
Pot Level: 200 Pot Value: 337
Pot Level: 210 Pot Value: 4
Pot Level: 220 Pot Value: 217
Pot Level: 230 Pot Value: 1023
Pot Level: 240 Pot Value: 1023
Pot Level: 250 Pot Value: 1023
Pot Level: 255 Pot Value: 1023
Pot Level: 245 Pot Value: 1023
Pot Level: 235 Pot Value: 1023
Pot Level: 225 Pot Value: 1023
Pot Level: 215 Pot Value: 1023
Pot Level: 205 Pot Value: 1023
Pot Level: 195 Pot Value: 1023
Pot Level: 185 Pot Value: 1023
Pot Level: 175 Pot Value: 1023
Pot Level: 165 Pot Value: 1023
Pot Level: 155 Pot Value: 1023
Pot Level: 145 Pot Value: 1023
Pot Level: 135 Pot Value: 1022
Pot Level: 125 Pot Value: 1023
Pot Level: 115 Pot Value: 378
Pot Level: 105 Pot Value: 4
Pot Level: 95 Pot Value: 5
Pot Level: 85 Pot Value: 1023
Pot Level: 75 Pot Value: 1023
Pot Level: 65 Pot Value: 1023
Pot Level: 55 Pot Value: 312
Pot Level: 45 Pot Value: 4
Pot Level: 35 Pot Value: 4
Pot Level: 25 Pot Value: 1023
Pot Level: 15 Pot Value: 1023
Pot Level: 5 Pot Value: 299
Pot Level: 0 Pot Value: 4
Pot Level: 10 Pot Value: 1023
Pot Level: 20 Pot Value: 1023
Pot Level: 30 Pot Value: 1023
Pot Level: 40 Pot Value: 1022
Pot Level: 50 Pot Value: 314
Pot Level: 60 Pot Value: 4
Pot Level: 70 Pot Value: 4
Pot Level: 80 Pot Value: 1023
Pot Level: 90 Pot Value: 1023
Pot Level: 100 Pot Value: 1023
Pot Level: 110 Pot Value: 1023
Pot Level: 120 Pot Value: 1023
Pot Level: 130 Pot Value: 1023
Pot Level: 140 Pot Value: 1023
Pot Level: 150 Pot Value: 1023
Pot Level: 160 Pot Value: 1022
Pot Level: 170 Pot Value: 373
Pot Level: 180 Pot Value: 4
Pot Level: 190 Pot Value: 3
Pot Level: 200 Pot Value: 1023
Pot Level: 210 Pot Value: 1023
Pot Level: 220 Pot Value: 1023
Pot Level: 230 Pot Value: 1023
Pot Level: 240 Pot Value: 1022
Pot Level: 250 Pot Value: 1023
Perhaps I have ruined the potentiometer with my tinkering.
I do seem to be getting repeatable responses. The potentiometer does not seem to have been ruined.
I'm thinking that my SPI codes may be incorrect. I'm supposed to send 10-bit commands. Perhaps by sending them as two 8-bit words I am screwing up the order of the bits.
I'm not able to experiment further right now, but will later. Maybe better luck then.
Found the problem. The chip has a not-SHTDWN pin that needs to be connected high. Works fine now. Next time I'll read the datasheet a little more thoroughly.