Digital Potentiometer not fading LED
After studying the datasheet differences between MCP41100 (digital pot used in the tutorial) and MCP4131 (the one you get), I found two major differences between both:


Difference in resolution:


MCP41100 has 257 steps resolution (8 bits + 1): you can see that at the beginning of its datasheet
MCP4131 has only 129 steps resolution (7 bits + 1): you can get this information on page 2 of its datasheet

Difference in commands formats sent through SPI; both use one "command byte" followed by a "data byte", but have a diffrent format for their command byte:


MCP41100 command byte is X X C1 C0 X X P1 P0 where X is unused, C1 C0 is one of 4 possible commands,  only 2 being valid commands actually: 01 (Write data), 10 (Shutdown), finally P1 P0 should be always 01 for an MCP41100
MCP4131 command byte is AD3 AD2 AD1 AD0 C1 C0 D9 D8, where AD3-AD0 is the address of the "register" on which to perfom a command. For the MCP4131, the most important address is 00 which means "volatile wiper 0" (this is what allows you to change the resistance value of the pot), C1 C0 is one of 4 possible commands (read data, write data, increment, decrement), in your example the command should be 00 (write data); finally D9 D8 are the high order bits of the value to write to the register, but D9 is unused and should always be 0. For 257-steps pots, D8is used to have the full resistance scale, otherwise it should be 0



Now that we know aht your MCP4131 expects as commands passed through SPI, we can take a look at what the tutorial program passes:

00010001 value


The first byte can be broken down as such:


0001 address of the pot wiper register 1 (not 0): this wiper does not exist on MCP4131 hecne writing to it will have no impact...
00 command bits meaning "Write to register specified in previous address"
01 high order bits (D9-D8) of the value to write to the wiper register.


Although I don't have an MCP4131 at hand, I think you should adapt the program as follows:

byte address = 0x00;


And that should be fine! Indeed, now your program passes:

00000000 value


Which means "write value (between 0 and 128 which matches exactly the 129 steps resolution) to the wiper register 0 of the port".

Note that the MCP4131 has more features than the MCP41100 in terms of commands, for instance you could use the special commands "increment" and "decrement", with the advantage they need only one byte (the command byte), e.g.

void loop()
{
    for (i = 0; i &lt;= 128; i++)
    {
      digitalPotIncrement();
      delay(10);
    }
    delay(500);
    for (i = 128; i &gt;= 0; i--)
    {
      digitalPotDecrement();
      delay(10);
    }
}

void digitalPotIncrement()
{
  digitalWrite(CS, LOW);
  SPI.transfer(0x04);
  digitalWrite(CS, HIGH);
}

void digitalPotDecrement()
{
  digitalWrite(CS, LOW);
  SPI.transfer(0x08);
  digitalWrite(CS, HIGH);
}