Favorite I2C Digital Pot?

Hello all,

Just wondering if the forum has a favorite I2C digital potentiometer. I know the DigitalPotentiometer example is written for the AD5171, but that chip is a little small (SOT23-8) and not highly available.

The chip has to be I2C. Bonus points for chips that meet these criteria:

a) 1 - 2 channels
b) easy SMT package, i.e. SOIC or something with reasonable pitch
c) easy to find at lots of suppliers
d) reasonably priced, i.e. less than a few bucks
e) code already well developed/supported

Any ideas?

ON Semiconductor and Microchip have a good selections.....

Have you tried the Intersil X9C102, X9C103, X9C104, X9C503 series. They are easy to drive (bit bash). I will give you some code if you need.

Marius:
Have you tried the Intersil X9C102, X9C103, X9C104, X9C503 series. They are easy to drive (bit bash). I will give you some code if you need.

Hi Marius, do you have some code to share about the X9C102, X9C103, X9C104, X9C503 series ?
Could you give some idea how to get it wired up with the arduino too ?

Thanks!

I have this in the header file

/**
 * @file x9cxx.h
 * @brief digital pot functions
 */
#ifndef x9cxx_H
#define x9cxx_H
// POT PINS
#define POT_SELECT 6
#define INC 1
#define UD 5
// Pot FUNCTIONS
#define UP 1
#define DOWN 0
#define SELECT 0
#define UNSELECT 1
  void setPot (uint requestedSpeed);
  void resetPot (void);
  void calcPulses (char val[],uint current, uint requested);


#endif // #ifndef x9cxx_H

And this bit is the code I used. Not all the variables are define in this piece of code but yoy should be able to see how it is done. Very easy really.

void setPot (uint requestedSpeed)
  {
    char val[2];
    calcPulses(val,config.motorSpeed, requestedSpeed);
    digitalWrite(INC,HIGH);
    digitalWrite(POT_SELECT,SELECT);
    digitalWrite(UD,val[1]);
    for(char i=1;i<val[0];i++)
    {
      digitalWrite(INC, HIGH);   // sets the pin on
      delayMicroseconds(5000);        // pauses for 50 microseconds      
      digitalWrite(INC, LOW);    // sets the pin off
      delayMicroseconds(5000);        // pauses for 50 microseconds          
    }
    digitalWrite(INC,HIGH);
    digitalWrite(POT_SELECT,HIGH);
    delay(20);
  }


  void resetPot (void)
  {
      pinMode(INC,OUTPUT);
      pinMode(POT_SELECT,OUTPUT);
      pinMode(UD,OUTPUT);
      digitalWrite(INC,HIGH);
      digitalWrite(POT_SELECT,SELECT);
      digitalWrite(UD,DOWN);
      for(char i=0;i<100;i++)
      {
        digitalWrite(INC, HIGH);   // sets the pin on
        delayMicroseconds(5000);     // pauses for 50 microseconds      
        digitalWrite(INC, LOW);    // sets the pin off
        delayMicroseconds(5000);     // pauses for 50 microseconds          
      }
      digitalWrite(INC,HIGH);
      digitalWrite(POT_SELECT,HIGH);
      delay(20);
    
  }


  void calcPulses (char val[],uint current, uint requested)
  {
    //char val[2];
    char RpmPp = config.maxSpeed / 100;
    if(current < requested)
    {
      val[0] = (requested - current)/RpmPp;
      val[1] = UP;
    }else 
    if(current > requested)
    {
      val[0] = (current - requested)/RpmPp;
      val[1] = DOWN;
    } 
  }

Marius, thanks for your quickly reply!
I just copy and paste the code and I get the error (see the picture) do you know why I'm facing this error ? Also I perform a test with other versions of Arduino IDE, but I got the same error!

Just taking Advantage, do you have some schematic to wire up with Arduino ?

Thanks in Advance!

You included the header file in your sketch instead of the code file. I included the header so that you can see how the chip was wired and to better understand the code. My code has many other files and was not done in the Arduino IDE but rather with a makefile.

This will compile. Please look at the comments for connection data. Also look at the spec sheet of the chip. There are only three signals in all.

NOTE: I did not initialize the pins in this sketch, you must do it in the setup section.

#include "Arduino.h"
 
 // POT
#define POT_SELECT 6  // connect the pot_cs of the chip to this pin
#define INC 1         // connect the clk of the chip to this pin
#define UD 5          // connect the direction pin of the chip to this pin
// Pot
#define UP 1
#define DOWN 0
#define SELECT 0
#define UN_SELECT 1
#define uint unsigned int

 void setPot (uint requestedSpeed)
  {
    char val[2];
    //calcPulses(val,config.motorSpeed, requestedSpeed);
    digitalWrite(INC,HIGH);
    digitalWrite(POT_SELECT,SELECT);
    digitalWrite(UD,val[1]);
    for(char i=1;i<val[0];i++)
    {
      digitalWrite(INC, HIGH);   // sets the pin on
      delayMicroseconds(5000);        // pauses for 50 microseconds      
      digitalWrite(INC, LOW);    // sets the pin off
      delayMicroseconds(5000);        // pauses for 50 microseconds          
    }
    digitalWrite(INC,HIGH);
    digitalWrite(POT_SELECT,HIGH);
    delay(20);
  }


  void resetPot (void)
  {
      pinMode(INC,OUTPUT);
      pinMode(POT_SELECT,OUTPUT);
      pinMode(UD,OUTPUT);
      digitalWrite(INC,HIGH);
      digitalWrite(POT_SELECT,SELECT);
      digitalWrite(UD,DOWN);
      for(char i=0;i<100;i++)
      {
        digitalWrite(INC, HIGH);   // sets the pin on
        delayMicroseconds(5000);     // pauses for 50 microseconds      
        digitalWrite(INC, LOW);    // sets the pin off
        delayMicroseconds(5000);     // pauses for 50 microseconds          
      }
      digitalWrite(INC,HIGH);
      digitalWrite(POT_SELECT,HIGH);
      delay(20);
    
  }

  void calcPulses (char val[],uint current, uint requested)
  {
    //char val[2];
    char RpmPp = 550; //config.maxSpeed / 100;
    if(current < requested)
    {
      val[0] = (requested - current)/RpmPp;
      val[1] = UP;
      //return (*val);
    }else 
    if(current > requested)
    {
      val[0] = (current - requested)/RpmPp;
      val[1] = DOWN;
      //return (*val);
    }else
    {
      //return (0);
    }
    
    
  }
  
  void setup(void)
  {

  }
  
  void loop(void)
  {
    
  }

Hi Marius, thanks alot for your help and your time !
I found the datasheet: HTTP 301 This page has been moved

Sorry for so many questions, but could you help a newbie in the Arduino how can I modify your code to "dim" a Led Bright ? I mean about to increase the brightness and decrease it by Serial command for example !

Thanks again!

What I normally do is to look at the examples. I copy and paste parts that I need. Look at the Analog examples and the Serial examples. You will have to scale your setting according to the value of the pot and the range that it represents in your circuit. The better way though is to use PWM (analogWrite(pin, value)) to a pin in stead of the pot. Look at the analogWrite examples in the libraries and use pin 13 on the UNO. The LED is coupled there.