I have been going through Jeremy Blum's Arduino Tuturial Series. Tutoral #8 is on SPI devices. His example used an AD4204 quad digital potentiometer. I could not find a breadboard-friendly version of that one, so I bought two MBP42010s. With some alterations, I was able to get one to work. Since it's a dual, I could not fully replicate the tutorial, since it consisted of alternately raising and lowering the intensity on 3 LEDs.
I am trying to accomplish the replication by daisy-chaining the two MCP42010s, but it is not working. As I understand it, here's what I need to do:
Breadboard
- Connect the MISO pin of the first MCP42010 (#1) to the MOSI pin of the second (#2).
- Connect the CS and SCK pins on #2 to Arduino pins 10 and 13 via the corresponding pins on #1 via the breadboard (i.e, pin one on #2 is on breadboard row 15 and pin 1 on #1 is on row 26--I used a jumper wire between those rows--same for SCK).
- Connect the remaining pins on #2 to VCC, GND, the LED, etc. the same as #1.
Arduino
In the two-LED version, I had nested for/next loops: the outeer loop varied the pot, one inner loop varied the level up followed by another loop to vary it back down. That works.
Since daisy-chaining requires sending two sets of command/data bytes whole CS is LOW, then sending all 32 bits when CS is set HIGH (or at least that's how I understand the datasheet), I removed the outer loop and intended to add code in the routine that sets the LED levels to determine which pot to activate.
BUT FIRST, I wanted to see if I could get this to work, so I just wrote code to manipulate pot A0 on #2 and both pots on #1. As I understand it, you do one pair of SPI.transfers (command/data) for #2 which loads it into #1,followed by a pair for #1, then when CS is set HIGH the first 2 bytes are shifted to #2 and the third and fourth are loaded into #1.
Here's the code to loop through levels:
for(int j=50; j<=255; j++)
{
byte i=0; //
setLed(i,j); //this used to use both pot and level, we're leaving pot as a vestige
delay(20);
}
//hold, then same thing in reverse
delay(500);
for(int j=255; j>=50; j--)
{
byte i=0;
setLed(i,j);
delay(20); }
And the code to set LEDs and do the daisy-chain
void setLed (byte reg, int level) //reg is vestigial--not used
{
digitalWrite(Slave, LOW);
SPI.transfer(17); // device 2 pot 0--gets shifted after next spi.transfers (B00010001 says use POT0)
SPI.transfer(level);
SPI.transfer(19); // pots 0&1 device 1 (B00010011 says use both)
SPI.transfer(level);
digitalWrite(Slave, HIGH);
}
This code is successful for #1, but #2 does nothing. I can do either pot, both, or neither on #1, but I cannot get #2 to respond.
Obviously, I am missing something. It could be the code, or the way I have it wired, or both, Any suggestions?







