Have everything connected but can’t get a measurement on my meter that shows the value of the pot is changing. A friend helped me with some code from arduino.
My code
// This #include statement was automatically added by the Particle IDE.
#include "DigiPotX9Cxxx.h"
/*
Modified on Dec 12, 2020
Modified by MehranMaleki from Arduino Examples
https://electropeak.com/learn/
*/
/*
* For this example, connect your X9C104 (or the like) as follows:
* 1 - INC - Arduino pin 2
* 2 - U/D - Arduino pin 3
* 3 - RH - 5V
* 4 - VSS - GND
* 5 - RW - Output: Arduino pin A0 for analogRead
* 6 - RL - GND
* 7 - CS - Arduino pin 4
* 8 - VCC - 5V
*/
DigiPot pot(D2,D3,D4);
void setup() {
//Serial.begin(9600);
}
void loop() {
//Serial.println("Starting");
//float voltage;
for (int i=0; i<100; i++) {
pot.increase(1);
//voltage = 5.0 * analogRead(A0) / 1024;
//Serial.println(voltage);
delay(20);
}
for (int i=0; i<100; i++) {
pot.decrease(1);
//voltage = 5.0 * analogRead(A0) / 1024;
//Serial.println(voltage);
delay(20);
}
}
CPP code
/*
* DigiPotX9Cxxx.cpp - Arduino library for managing digital potentiometers X9Cxxx (xxx = 102,103,104,503).
* By Timo Fager, Jul 29, 2011.
* Released to public domain.
**/
#include "Particle.h"
#include "DigiPotX9Cxxx.h"
DigiPot::DigiPot(uint8_t incPin, uint8_t udPin, uint8_t csPin) {
_incPin = incPin;
_udPin = udPin;
_csPin = csPin;
_currentValue = DIGIPOT_UNKNOWN;
pinMode(_incPin, OUTPUT);
pinMode(_udPin, OUTPUT);
pinMode(_csPin, OUTPUT);
digitalWrite(_csPin, HIGH);
}
void DigiPot::reset() {
// change down maximum number of times to ensure the value is 0
decrease(DIGIPOT_MAX_AMOUNT);
_currentValue = 0;
}
void DigiPot::set(uint8_t value) {
value = constrain(value, 0, DIGIPOT_MAX_AMOUNT);
if (_currentValue == DIGIPOT_UNKNOWN) reset();
if (_currentValue > value) {
change(DIGIPOT_DOWN, _currentValue-value);
} else if (_currentValue < value) {
change(DIGIPOT_UP, value-_currentValue);
}
}
uint8_t DigiPot::get() {
return _currentValue;
}
void DigiPot::increase(uint8_t amount) {
amount = constrain(amount, 0, DIGIPOT_MAX_AMOUNT);
change(DIGIPOT_UP, amount);
}
void DigiPot::decrease(uint8_t amount) {
amount = constrain(amount, 0, DIGIPOT_MAX_AMOUNT);
change(DIGIPOT_DOWN, amount);
}
void DigiPot::change(uint8_t direction, uint8_t amount) {
amount = constrain(amount, 0, DIGIPOT_MAX_AMOUNT);
digitalWrite(_udPin, direction);
digitalWrite(_incPin, HIGH);
digitalWrite(_csPin, LOW);
for (uint8_t i=0; i<amount; i++) {
digitalWrite(_incPin, LOW);
delayMicroseconds(2);
digitalWrite(_incPin, HIGH);
delayMicroseconds(2);
if (_currentValue != DIGIPOT_UNKNOWN) {
_currentValue += (direction == DIGIPOT_UP ? 1 : -1);
_currentValue = constrain(_currentValue, 0, DIGIPOT_MAX_AMOUNT);
}
}
digitalWrite(_csPin, HIGH);
}
.h code
/*
* DigiPotX9Cxxx.h - Arduino library for managing digital potentiometers X9Cxxx (xxx = 102,103,104,503).
* By Timo Fager, Jul 29, 2011.
* Released to public domain.
**/
#ifndef DigiPotX9Cxxx_h
#define DigiPotX9Cxxx_h
#include "Particle.h"
#define DIGIPOT_UP HIGH
#define DIGIPOT_DOWN LOW
#define DIGIPOT_MAX_AMOUNT 99
#define DIGIPOT_UNKNOWN 255
class DigiPot
{
public:
DigiPot(uint8_t incPin, uint8_t udPin, uint8_t csPin);
void increase(uint8_t amount);
void decrease(uint8_t amount);
void change(uint8_t direction, uint8_t amount);
void set(uint8_t value);
uint8_t get();
void reset();
private:
uint8_t _incPin;
uint8_t _udPin;
uint8_t _csPin;
uint8_t _currentValue;
};
#endif
I’ve tried measuring resistance between vw, vh, and vl of the chip. The same friend suggested connected vl and vh to gnd and vin respectively and measuring voltage between vin and vw. I get a constant reading that matches vin.
What am I missing?