Daisy Chaining the MCP42100 Dual 100kOhm Potentiometer

In my quest to keep learning, I purchased a few MCP42100 digital potentiometers (Datasheet here) and have been playing around with them.

I have managed to find enough information online to get one doing what I wanted it to do. A simple script utilizing the SPI library that I modified to change the brightness of 2 LEDs. As I said, just for learning at this stage. And it works just like I wanted.

After reading some more about these chips, I learned that they can be daisy chained together and controlled by just 3 pins on the Arduino. So, this is the next step I want to figure out.

I found this interesting document, Communicating with Daisy Chained MCP42XXX Digital Potentiometers. However, it's not something I am really understanding.

Does anyone have a good reference on Shift Registers that's written in layman's terms, so to speak. Like Shift Registers for Dummies! :slight_smile:

The following code is what I was using in conjunction with an analog potentiometer to adjust the brightness of an LED. But how one would send commands to chips on down the chain is above my head at the moment.

/* include SPI library */
#include <SPI.h>

const int slaveSelectPin = 10;

int CommandByte0 = 17;
int CommandByte1 = 18;
int value0 = 254;
int value1 = 204;

int staticPot = 0;
int a = 0;
int sensorValue = 0;

void setup() {
  SPI.setClockDivider(SPI_CLOCK_DIV4);
  pinMode (slaveSelectPin, OUTPUT);
  SPI.begin();
  digitalWrite(slaveSelectPin,LOW);
  SPI.transfer(19);
  SPI.transfer(0);
  digitalWrite(slaveSelectPin,HIGH);
  Serial.begin(9600);
  delay(10);
}

void loop(){
  sensorValue = analogRead(A1);  

  if(sensorValue > staticPot+2 || sensorValue < staticPot-2)
  {
    staticPot = sensorValue;
    a++;
    Serial.print("a-");
    Serial.print(a);
    Serial.print("=");
    Serial.println(sensorValue);

    value0 = sensorValue/4;
    changeDigiPot();
  }
}

void changeDigiPot(){
    digitalWrite(slaveSelectPin,LOW);
    SPI.transfer(CommandByte0);
    SPI.transfer(value0);
    digitalWrite(slaveSelectPin,HIGH);
    
    delay(10);
  
    digitalWrite(slaveSelectPin,LOW);
    SPI.transfer(CommandByte1);
    SPI.transfer(value1);
    digitalWrite(slaveSelectPin,HIGH);
}

Any advice, links, vids, etc to help a noob out is much appreciated.

I guess one thing about the above code that I'm not getting is what 17, 18 & 19 are in regards to "SPI.transfer". I get that 17 effects channel one, 18 effects channel two and 19 effects both channels. But where do those numbers come from?

You posted a link to the datasheet. Pages 17 and 18 describe the command byte. Figure 5-2 provides details of the bits, which explains to me how to create these decimal values. It might make more sense if binary or hexadecimal had been used, but a simple conversion can get you from the binary of figure 5-2 to the decimal values used in the program.

I don't know how to help you with shift registers. Sorry.