I want to control the AD5290 digital potentiometer,with arduino uno

i am trying to control AD5290 using arduino using below attached code, here iam getting the value of pot as 7k ohms. even though i am changing the values of resistance from 0-255. can any one help to fix this problem

#include <SPI.h>

const int CS_PIN = 9;
const int SDI_PIN = 10;
const int SDO_PIN = 11;
const int SCLK_PIN = 13;

void setup() {
// Set pin modes
pinMode(CS_PIN, OUTPUT);
pinMode(SDI_PIN, OUTPUT);
pinMode(SDO_PIN, INPUT);
pinMode(SCLK_PIN, OUTPUT);

// Initialize SPI
SPI.begin();
SPI.setDataMode(SPI_MODE2);
SPI.setBitOrder(MSBFIRST);

// Set initial resistance value (0-255, where 0 is minimum resistance and 255 is maximum)
setResistance(50); // Example: set the resistance to halfway
}

void loop() {
// Your main code logic goes here
// You can change the resistance value using the setResistance() function
}

void setResistance(byte resistanceValue) {
digitalWrite(CS_PIN, LOW); // Set CS low to enable communication with the AD5290

SPI.transfer(resistanceValue); // Send the command to set the resistance value

digitalWrite(CS_PIN, HIGH); // Set CS high to end communication
}

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

You can cross-check your code and circuit with this video: Arduino Nano AD5252 I2C Digital Potentiometer Tutorial - YouTube

Your code only sets the resistance value to 50, it does nothing else

1. Check that you have connected your pot with UNO as per Fig-1.
digitalPotdownload
Figure-1:

2. Upload the following sketch (your one with slight modification).

#include <SPI.h>

const int CS_PIN = 10;//9;
const int SDI_PIN = 12;//10;
const int SDO_PIN = 11;
const int SCLK_PIN = 13;

void setup() 
{
  // Set pin modes
 /* pinMode(CS_PIN, OUTPUT);
  pinMode(SDI_PIN, OUTPUT);
  pinMode(SDO_PIN, INPUT);
  pinMode(SCLK_PIN, OUTPUT);*/

  // Initialize SPI
  SPI.begin();
 // SPI.setDataMode(SPI_MODE2);
 // SPI.setBitOrder(MSBFIRST);

  // Set initial resistance value (0-255, where 0 is minimum resistance and 255 is maximum)
 // setResistance(50); // Example: set the resistance to halfway
}

void loop() 
{
  
}

void setResistance(byte resistanceValue) 
{
  digitalWrite(CS_PIN, LOW); // Set CS low to enable communication with the AD5290

  SPI.transfer(resistanceValue); // Send the command to set the resistance value

  digitalWrite(CS_PIN, HIGH); // Set CS high to end communication
}

3. Connect DVM between across W and GND. Check that DVM reads about 1V.

I had changed the resistance values from 0-255 in that code, but the value of the digipot is showing the same 7k ohm resistance between wiper and VA pins, I need different values of resistance ranging from 0 to 10k ohms. can you help me.

Have you tried @GolamMostafa suggestions?

I have did the same thing what you have said, and connections are made as per block diagram mentioned by you.
but I am getting 4.9v between W and Ground. what should I do now.

Yahh I have tried, but I didn't got the result as my requirement.

Connect the following

Arduino --> AD5290
MOSI (pin 11) --> SDI
SCK (pin 13) --> CLK
SS (pin 10) --> CS
Use this code:

#include <SPI.h>

// set pin 10 as the slave select for the digital pot:
const int slaveSelectPin = 10;

void setup() 
{
  // set the slaveSelectPin as an output:
  pinMode(slaveSelectPin, OUTPUT);
  // initialize SPI:
  SPI.begin();
  SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
}

void loop() 
{

  // change the resistance from min to max:
  for (int level = 0; level < 255; level++) 
  {
    digitalPotWrite(level);
    delay(100);
  }
 

}

void digitalPotWrite(byte value) {
  // take the SS pin low to select the chip:
  digitalWrite(slaveSelectPin, LOW);
  delay(5);
  //  send value via SPI:
  SPI.transfer(value);
  delay(5);
  // take the SS pin high to de-select the chip:
  digitalWrite(slaveSelectPin, HIGH);
}

1 Like

Where to look for output?

The sketch 0f post #5 is modified as follows:

#include <SPI.h>

//const int CS_PIN = 10;//9; if using UNO, then no need
//const int SDI_PIN = 12;//10;
//const int SDO_PIN = 11;
//const int SCLK_PIN = 13;

void setup() 
{
  // Set pin modes
 /* pinMode(CS_PIN, OUTPUT);
  pinMode(SDI_PIN, OUTPUT);
  pinMode(SDO_PIN, INPUT);
  pinMode(SCLK_PIN, OUTPUT);*/

  // Initialize SPI
  SPI.begin();
 // SPI.setDataMode(SPI_MODE2);
 // SPI.setBitOrder(MSBFIRST);

  // Set initial resistance value (0-255, where 0 is minimum resistance and 255 is maximum)
 digitalWrite(SS, HIGH);
setResistance(50); // Example: set the resistance to halfway
}

void loop() 
{
  
}

void setResistance(byte resistanceValue) 
{
  digitalWrite(SS, LOW); // Set CS low to enable communication with the AD5290
  delay(10);
  byte y = SPI.transfer(resistanceValue); // Send command to set resistance value
  delayMicroseconds (10);
  digitalWrite(SS, HIGH); // Set CS high to end communication and to latch data
}

Wouldn't "halfway" be 127 ~ 128? Which of the 3 AD5290s does the OP have?

thank you, I will try withs code for sure and I will update you

How are you measuring resistance?

I will try this code also,
can you predict the the out put for this code and tell me please!!!

I have tried this code, the values are chaining in serial monitor(1 to 255 numbers are generating) but the value of digipot is remaining constant!

By using digital multimeter. between the A & W (terminal A and Wiper) terminals of the AD5290.

now I got my digipot getting changed from 0k ohms to 10k ohms. thank you for the code.

Thank u for this code, can u help me with the code which can keep the resistance of digipot at a constant position, actually this is incrementing the digipot. I want to set it at 2k ohms can u help me with that.