Go Down

Topic: mcp42010 digipot SPI connection (Read 5351 times) previous topic - next topic


Aug 21, 2012, 11:22 am Last Edit: Aug 21, 2012, 11:25 am by tommyrosa Reason: 1
Hi everyone...
i'm trying to make a mcp42010 digipot (http://www.datasheet4u.net/download.php?id=440013) work using a SPI protocol, but nothing works.
i'm using an arduino nano, i have tried using a very slightly modified version of the example digipot sketch, and i have checked the pins and the connections many times, but the digipot doesn't seem to receive any information, and just lights the led very dimly.
i have tried swapping the IC but nothing changes.

the program i'm using

// 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() {
   // change the resistance on this channel from min to max:
   for (int level = 0; level < 255; level++) {
     digitalPotWrite(1, level);
   // wait a second at the top:
   // change the resistance on this channel from max to min:
   for (int level = 0; level < 255; level++) {
     digitalPotWrite(1, 255 - level);


int 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:


i also tried messing around with the SPI.begin(); settings but i have achieved nothing.

i'm obviously missing something... any suggestions on what?

also, an image with the digipot connections to the nano


See the Single/Dual digital Potentiometer Library for MCP41xxx, MCP42xxx


AH_MCP41xxx.h functions
Code: [Select]
 void init_MCP41xxx (int CS);
 void init_MCP42xxx (int CS, int SHDN, int RS);

 void setValue(byte value); //value = 0..255
 void setValue(byte value, int potentiometer); //Pot0=0 or Pot1=1
 void shutdown(boolean data); //TRUE or FALSE
 void reset();


Based on the command byte format from the datasheet, reference:
FIGURE 5-2: Command Byte Format.

Your code:
digitalPotWrite(1, level);

should be:
digitalPotWrite(0x11, level);


I had the same problem, following jeremy Blum's arduino tutorial#8.  The AD5204 is no longer available so I got 2 MCP42010s.

The library referenced here, with accompanying examples, got me going. See http://www.jeremyblum.com/2011/02/20/arduino-tutorial-8-spi-interfaces/comment-page-1/#comment-656326.


After looking at the library referenced in  my last post, I determined that most of what was in the examples was unnecessary.

The problem is the command byte.  So, to raise and lower brightness on 2 LEDs consecutively,  I did a nested for/next loop, with the outer level looping through the pots:
for(byte i=17; <=18; i++) {
{ inner loop incrementing "value"  50-255}
{ second inner loop decrementing "value"  255-50}

byte 17 is B00010001 and byte 18 is B00010010, which is what we want for MCP42010 PA0 and PA1.

As it turns out, that was the only change I needed to make from code designed for the AD5204 was to send the right values for the POTs.

Fulll code and explanation on Jeremy Blum's blog at the link in my last post in this thread.

Go Up