SPI - Digital Pot-meter - Change the SDI, SDO and CLK pin

Hello Everyone,

I have been trying to work with an MCP4231 Digital Potentiometer, and I recently got it working for both sides! :slight_smile:

I am trying it out before I add it to a larger project I am working on, since this is my first try with SPI. In the tutorial I can only change the CS pin however :S which is unhandy because the default pins for SDI, SDO and CLK are being used in my larger project. I would love to be able to define which pins these are. Is there a way to do this?

Kind Regards,


Digital Pot Control

This example controls an Analog Devices AD5206 digital potentiometer.
The AD5206 has 6 potentiometer channels. Each channel’s pins are labeled
A - connect this to voltage
W - this is the pot’s wiper, which changes when you set it
B - connect this to ground.

The AD5206 is SPI-compatible,and to command it, you send two bytes,
one with the channel number (0 - 5) and one with the resistance value for the
channel (0 - 255).

The circuit:

  • All A pins of AD5206 connected to +5V
  • All B pins of AD5206 connected to ground
  • An LED and a 220-ohm resisor in series connected from each W pin to ground
  • CS - to digital pin 10 (SS pin)
  • SDI - to digital pin 11 (MOSI pin)
  • CLK - to digital pin 13 (SCK pin)

created 10 Aug 2010
by Tom Igoe

Thanks to Heather Dewey-Hagborg for the original tutorial, 2005


// inslude the SPI library:
#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:

void loop() {
digitalPotWrite(1, 255);
digitalPotWrite(1, 0);
// digitalPotWrite(1, 255);
// delay(100);
// digitalPotWrite(1, 0);
// delay(100);

void digitalPotWrite(int address, int value) {
// take the SS pin low to select the chip:
// send in the address and value via SPI:
// take the SS pin high to de-select the chip:

Not for the hardware SPI. You could use software to mimic SPI on any pins, but it will be slower.

Please explain more about your pin conflict.

It may be more simple to reconfigure what is currently using the hardware spi pins 11, 12, and 13 than to go down the road of software SPI

Well in my other project I am using those pins because they coincide with a group of port-registers pins on my Teensy which I use for port-manipulation. I have used all of the grouped port register pins to control 4 multiplexers quickly. I have open pins of course but they can not be 10-13 :S


oh and to add, I am using the Digital-pot meter as a replacement for some pull-down resistors next to my input pins, as I need the pull-down to be High Ohm for a few ticks and then low Ohm for one tick (repeat). The idea is that I provide a short ‘dump out’ of excess voltage remaining in my circuit and then start sensing again with a normal pull-down ohm.

While i get all your reasons to want such a thing, none of them change the fact that it is all hardwired in the chip. Maybe get one that uses I2C instead, it uses different pins. Or if you can take the decrease in speed, bit-bang the SPI on whatever pins you have available.