Digital potentiometer, MCP4131
A real 10 k pot (or 5 k, 50 k, 100 k) whose wiper an SPI sketch sets in 129 steps, two bytes with CS low.
- 8 pins
- 1 setting
- In 1 project
The Digital potentiometer, MCP4131 in brief
What it is, and every setting the properties panel gives it.
The MCP4131 is a potentiometer with no knob: a resistor track of 5 k, 10 k, 50 k or 100 k in an eight-pin DIP, with a wiper that a sketch moves over SPI. P0A and P0B are the two ends and P0W is the wiper, which can stop at 129 places, 0 at the P0B end and 128 at the P0A end; it powers up in the middle, at 64. Wire the ends across 5 V and ground and the wiper becomes a voltage the sketch sets; use one end and the wiper and it is a variable resistor. Mokxi puts the track in the circuit as real resistance, the wiper switch’s 75 ohm included, so an LED or meter on the wiper sees what it would on the bench. The chip shares one pin for data in and out, and the model drives it only for a read or a command error, as the datasheet says.
- Family
- Sensors
- Pins
- 8
- value
- 10k (or 5k, 50k, 100k)
8 pins
Named as the editor names them, so a wire lands where you expect it.
MOSI, and out during a read.How to use the MCP4131 digital pot with an Arduino
The SPI lines go to the Uno’s hardware SPI pins: SCK to 13, SDI to 11, and CS to 10, which the sketch drives itself. VDD goes to 5 V and VSS to GND. In the dimmer project the track sits between 5 V on P0A and GND on P0B, so the wiper on P0W is a voltage from 0 to 5 V; it feeds an LED through 220 ohms and is also read on A0.
No library is needed. Pull CS low, send the command byte 0x00 (write, wiper 0) and then the position from 0 to 128, and raise CS again. The project walks the wiper through 0, 32, 64, 96 and 128 and back, every half second, printing the step and the voltage A0 reads. The LED stays dark at the bottom steps because the wiper has not yet reached its forward voltage, around 1.8 V.
Change the part’s value property from 10k to 100k and run it again: the voltage at each step is unchanged, because it is still a fraction of 5 V, but the LED is dimmer, since a larger track can push less current into it.
On an ESP32 the default SPI pins are 18 for SCK and 23 for MOSI; power the chip and the track from 3.3 V so the wiper stays inside what the ADC reads.
#include <SPI.h>
const int CS = 10;
void setWiper(uint8_t value) { // 0 to 128
digitalWrite(CS, LOW);
SPI.transfer(0x00); // write, wiper 0
SPI.transfer(value);
digitalWrite(CS, HIGH);
}Common Digital potentiometer, MCP4131 errors and fixes
Questions and answers
Does the MCP4131 need an Arduino library?
No. The SPI library and two transfers set the wiper. Libraries exist, but the command is so short that most sketches write it by hand, as the dimmer project does.
What resistance does the wiper add?
About 75 ohms at 5 V, the switch that connects the wiper to the track. The model adds it to every position, so even step 0 is not quite a short to P0B.
Can the MCP4131 handle an audio signal that swings below ground?
Not directly. Every terminal has to stay between VSS and VDD, so an audio signal needs a DC offset into the middle of the supply before it reaches the track.
Where does the wiper start at power-up?
At 64, the middle of the track. A sketch that needs a known level at start should write it in setup() before anything depends on it.
What is true about the Digital potentiometer, MCP4131, here
In its help article’s own words: what the simulation gets right, and where it stops.
Modeled
It is a resistor. The ladder and the wiper switch are in the circuit as the
datasheet draws them: P0W to P0B is value x N / 128 + 75 ohm, the 75 ohm being
the wiper switch, and P0A to P0B is the whole track whatever the wiper does. A
load on the wiper, an LED in series, or a meter across two pins sees what it would on
the bench.
The commands. Write, read, increment and decrement of the wiper (address 0), and
write and read of the TCON register (address 4), which disconnects P0A, P0W
or P0B, or puts the pot in its shutdown state (A open, the wiper on B). The
STATUS register (address 5) reads. Increments stop at 128 and decrements at 0, and
a value over 128 is full scale. Several commands can follow one another while CS
is low. SPI modes 0 and 3 both work.
The shared pin. On the MCP4131 SDI and SDO are one pin. The chip drives it
only for the command error bit (CMDERR) and a read's data bits, open drain. An
invalid command, such as a reserved address or an increment of TCON, pulls the pin
low and the chip ignores everything until CS rises. To read the wiper back, wire
MOSI to the pin through a resistor (1k to 10k) and MISO straight to it, then send
0x0F and 0xFF: the low nine bits of the reply are the wiper.
Not modeled
The wiper resistance's change with supply and current (75 ohm is the 5 V figure),
the track's 20 % tolerance and its temperature drift, bandwidth, the high-voltage
commands, and the internal pull-ups on CS and the shared pin while nothing drives
them. Unpowered, the real chip's switches are undefined; here the three terminals are
open.
From MCP4131 digital potentiometer, in full.
See the Digital potentiometer, MCP4131 in a project
One built-in project uses it. It opens in the editor, already wired.
The boards it is shown on
This board has a built-in project with the Digital potentiometer, MCP4131 in it.
The rest of the bench
Every one of these is drawn and simulated the same way.
Wire up the Digital potentiometer, MCP4131
Open the editor and push it into the breadboard. It is free, and it runs on your own machine.