# Digital Potentiometers (Digipots)

## What is a digital potentiometer?

{% embed url="<https://www.digikey.com/en/articles/the-fundamentals-of-digital-potentiometers>" %}

Digital potentiometers function using a "ladder" of resistors with floating wires at each junction.  By setting the wiper register, the user can select which junction is connected to the wiper, and thus how many resistors in the ladder comprise the connection from A-to-W or from W-to-B.&#x20;

<figure><img src="/files/pY9hKM96YaCxuY11Dpln" alt=""><figcaption><p>Block diagram of a digipot's resistor network from the <a href="https://www.digikey.com/en/products/detail/microchip-technology/MCP4531T-502E-MS/2061327">MCP4531T</a> manual</p></figcaption></figure>

The total number of resistors in a digipot is referred to as its number of **taps** or **steps**. In the above example from the manual of the MCP453X/455X/463X/465X family of digipots, the digipots can have 129 taps (i.e., 128 resistor ladder with 129 possible wiper positions) or 257 taps (i.e., 256 resistor ladder with 257 possible wiper positions). The resistance change at each step is then calculated as:

<figure><img src="/files/iYqD5JWrEp96rBsdyaoy" alt=""><figcaption><p>Step resistance equations from the <a href="https://www.digikey.com/en/products/detail/microchip-technology/MCP4531T-502E-MS/2061327">MCP4531T</a> manual</p></figcaption></figure>

## Digipot Hardware Limitations

#### Digipots are very low current devices.&#x20;

The max allowable current across a digipot wiper is around 1-2.5 ***mA*****.**&#x20;

#### The wiper itself has resistance.&#x20;

This resistance affects the functional range of the digipot, and can be quite high. For example, the [DS3502 digipot](https://learn.adafruit.com/ds3502-i2c-potentiometer) has a resistance of 10kΩ between A and B, but has a ***5k*****Ω** wiper resistanc&#x65;*.* That means the functional range of resistance of the DS3502 between AW or WB is actually 0kΩ-15kΩ.

As a further example, here is the equation for calculating the WB resistance of the MCP453X/455X/463X/465X family of digipots:

<figure><img src="/files/KDke1FnQzBXSU1TIEoAh" alt=""><figcaption><p>How to calculate the WB resistance from the <a href="https://www.digikey.com/en/products/detail/microchip-technology/MCP4531T-502E-MS/2061327">MCP4531T</a> manual</p></figcaption></figure>

## Controlling a digipot with Arduino

Most digipots are controlled across the I2C bus. For more information on I2C, go here:

{% content-ref url="/pages/XSArXjCrtByVSbTUMXux" %}
[I2C Communication with Arduino](/neuromint-resources/technical-guides/i2c-communication-with-arduino.md)
{% endcontent-ref %}

Here is example code for getting a MCP4531T digipot to increment its wiper value over time, and print the voltage at the wiper over Serial. The wiring diagram necessary for this code is also included below.

```arduino
#include <Wire.h>
byte val = 0;
int errorPot;
byte a;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  // Wait until serial port is opened
  while (!Serial) { delay(1); }
  Wire.begin();
  Wire.beginTransmission(46);
  Wire.write(byte(0x00));
  Wire.write(byte(10));
  errorPot = Wire.endTransmission();
}

void loop() {
  // put your main code here, to run repeatedly:

  Serial.print("Wiper set to ");
  Serial.println(val);
  Wire.beginTransmission(46);
  Wire.write(byte(0x00));
  Wire.write(val);
  errorPot = Wire.endTransmission();

  float wiper_value = analogRead(A0);
  wiper_value *= 5.0;
  wiper_value /= 1024;

  Serial.print("Error message: ");
  Serial.print(errorPot);
  Serial.print("\t");
  Serial.print("Wiper Voltage: ");
  Serial.println(wiper_value);
  delay(1000);

  val++;                       // Increment value

  // if reached 128th position (max)
  if(val == 128) {
      val = 0;                   // Start over from lowest value
    }  
}
```

<figure><img src="/files/ymlJyMPnDPoFMJztMftS" alt=""><figcaption><p>The necessary wiring of the MCP4531 digipot for the above code. </p></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wvu-neuromint.gitbook.io/neuromint-resources/technical-guides/circuit-board-components/digital-potentiometers-digipots.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
