# Adafruit DS3502 I2C Digital Potentiometer

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/078/986/medium800/adafruit_products_4286-00.jpg?1564789883)

If you're a person like me that gets exhausted turning knobs all day, the DS3502 is just the ticket to calm all your knob-turning related troubles. Instead of having to&nbsp;_turn knobs&nbsp;_with your _HANDS_ like an _ANIMAL,&nbsp;_the DS3502 I2C Digital Potentiometer allows you to let your microcontroller adjust the resistance for you!

Now you can free your hands to spin your fidget spinner or or eat a slice of pizza while you're on the phone. Talking over an I2C bus, your Arduino, CircuitPython board, or Python powered computer can talk to the DS3502 and tell it to vary its resistance at your beck and call.

![](https://cdn-learn.adafruit.com/assets/assets/000/078/987/medium800/adafruit_products_4286-04.jpg?1564789899)

Working with the DS3502 is easy as an I2C controllable pie. We've&nbsp; put it on a breakout PCB with the required support circuitry and [SparkFun qwiic](https://www.sparkfun.com/qwiic) compatible [**STEMMA QT**](https://learn.adafruit.com/introducing-adafruit-stemma-qt) connectors to allow you to use it with other similarly equipped boards **without needing to solder.** &nbsp;This handy little helper can work with 3.3V or 5V micros, so it's ready to get to work with a range of development boards.

The DS3502 is a simple chip that does one thing well and so it's very easy to work with. Wire it up and set the value for the wiper, that's it. To make things _even easier,_ we've gone and written Arduino and CircuitPython/Python 3 drivers to simplify interfacing with your new knob-replacing friend.

![](https://cdn-learn.adafruit.com/assets/assets/000/078/988/medium800/adafruit_products_4286-02.jpg?1564789915)

"OK, this thing sounds great. Give me some details" you say. OK then, here you go: The wiper value is a 7-bit number meaning there are **128** possible levels of resistance to choose, from **0-10K ohms**. You can even set a default value that will be set on power up. The analog voltage controlled can be from **4.5-15.5V.** &nbsp;

Additionally you can use the address jumpers or pins to set the I2C address to one of four values, allowing you to have four DS3502s on the same I2C bus.

# Adafruit DS3502 I2C Digital Potentiometer

## Pinouts

![](https://cdn-learn.adafruit.com/assets/assets/000/078/991/medium800/adafruit_products_4286-03.jpg?1564790048)

# Power Pins

The sensor on the breakout requires between a 2.7V and 5.5V, and can be easily used with most microcontrollers from an Arduino to a Feather or something else.

- **Vcc** &nbsp;- this is the power pin.&nbsp; To power the board, give it the same power as the logic level of your microcontroller - e.g. for a 5V micro like Arduino, use 5V
- **GND** - common ground for power and logic

# I2C Logic Pins

- **SCL** - I2C clock pin, connect to your microcontrollers I2C clock line. The logic level is the same as **Vcc** and it has a 10K pullup already on it.
- **SDA** - I2C data pin, connect to your microcontrollers I2C data line. The logic level is the same as **Vcc**. and it has a 10K pullup already on it.
- **[STEMMA QT](https://learn.adafruit.com/introducing-adafruit-stemma-qt)&nbsp;-** These connectors allow you to connectors to dev boards with&nbsp; **STEMMA QT** connectors or to other things with&nbsp;[various associated accessories](https://www.adafruit.com/?q=JST%20SH%204)

# Resistor Pins

- **RL&nbsp;** is the Low Terminal of the potentiometer, often connected to ground.
- **RW&nbsp;** is the wiper of the potentiometer. As the wiper value is adjusted via I2C, the resistance between **RW** and **RL/RH** changes&nbsp;
- **RH** is the High Terminal of the potentiometer, often connected to your high voltage source **.**
- **V+** is the wiper bias pin and is used to bias the gates of the MOSFETs that are responsible for changing the resistance between **RW** and&nbsp; **RH&nbsp;** or&nbsp; **RL**. If the voltage at&nbsp; **RH&nbsp;** is higher than&nbsp; **VCC** ,&nbsp; **V+** must be at the same or higher voltage than&nbsp; **RH**. By default this is connected with a jumper to **RH** but you can cut the solder jumper and wire it directly

![](https://cdn-learn.adafruit.com/assets/assets/000/079/050/medium800/adafruit_products_vjump.jpg?1564951696)

# Extra Pins

- **A0 and A1&nbsp;** - These are the address select pins.

Since you can only have one device with a given address on an I2C bus, there must be a way to adjust the address if you want to put more than one DS3502 on a shared I2C bus. The **A0/A1** pins set the bottom two bits of the I2C address. There are pull-down resistors on the board so connect them to VDD, you can solder the back jumpers or wire them on a breadboard, to set the bits to '1'. They are read on power up, so de-power and re-power to reset the address

The default address is **0x28** and the address can be calculated by 'adding' the **A0/A1** &nbsp;to the base of **0x28**

**A0** sets the lowest bit with a value of **1** , and&nbsp; **A1** sets the middle bit with a value of **2**. The final address is **0x28&nbsp;+ A1 + A0**.

- So for example if only **A0** is tied to VDD, the address is **0x28 + 1 = 0x29**  
- If only **A1** is tied to VDD, the address is **0x28 + 2 = 0x2A**
- If **A1** is tied to VDD and **A0** is tied to VDD, the address is **0x28 + 2 + 1 = 0x2B.** &nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/079/051/medium800/adafruit_products_addrjmp.jpg?1564951705)

# Adafruit DS3502 I2C Digital Potentiometer

## Assembly

![](https://cdn-learn.adafruit.com/assets/assets/000/078/992/medium800/adafruit_products_4286-01.jpg?1564790104)

## Prepare the header strip:

Cut the strip to length if necessary. It will be easier to solder if you insert it into a breadboard -&nbsp; **long pins down**

![adafruit_products_DSC_4287.jpg](https://cdn-learn.adafruit.com/assets/assets/000/079/999/medium640/adafruit_products_DSC_4287.jpg?1566864840)

![adafruit_products_DSC_4288.jpg](https://cdn-learn.adafruit.com/assets/assets/000/080/000/medium640/adafruit_products_DSC_4288.jpg?1566864900)

![adafruit_products_DSC_4289.jpg](https://cdn-learn.adafruit.com/assets/assets/000/080/001/medium640/adafruit_products_DSC_4289.jpg?1566865027)

## Add the breakout board:

Place the breakout board over the pins so that the short pins poke through the breakout pads

![adafruit_products_DSC_4290.jpg](https://cdn-learn.adafruit.com/assets/assets/000/080/002/medium640/adafruit_products_DSC_4290.jpg?1566865109)

## And Solder!

Be sure to solder all 10 pins for reliable electrical contact.  
  
_(For tips on soldering, be sure to check out our&nbsp;_[_Guide to Excellent Soldering_](http://learn.adafruit.com/adafruit-guide-excellent-soldering)_)._

![adafruit_products_DSC_4291.jpg](https://cdn-learn.adafruit.com/assets/assets/000/080/005/medium640/adafruit_products_DSC_4291.jpg?1566865172)

![adafruit_products_DSC_4292.jpg](https://cdn-learn.adafruit.com/assets/assets/000/080/006/medium640/adafruit_products_DSC_4292.jpg?1566865176)

![adafruit_products_DSC_4293.jpg](https://cdn-learn.adafruit.com/assets/assets/000/080/007/medium640/adafruit_products_DSC_4293.jpg?1566865333)

![adafruit_products_DSC_4296.jpg](https://cdn-learn.adafruit.com/assets/assets/000/080/008/medium640/adafruit_products_DSC_4296.jpg?1566866070)

![adafruit_products_DSC_4298.jpg](https://cdn-learn.adafruit.com/assets/assets/000/080/009/medium640/adafruit_products_DSC_4298.jpg?1566866090)

![adafruit_products_DSC_4301.jpg](https://cdn-learn.adafruit.com/assets/assets/000/080/012/medium640/adafruit_products_DSC_4301.jpg?1566866105)

You're done! Check your solder joints visually and continue onto the next steps.

![adafruit_products_DSC_4304.jpg](https://cdn-learn.adafruit.com/assets/assets/000/080/013/medium640/adafruit_products_DSC_4304.jpg?1566863470)

# Adafruit DS3502 I2C Digital Potentiometer

## Arduino

# Wiring

Wiring the DS3502 to communicate with your microcontroller is straight forward forward thanks to the I2C interface. For these examples we can use the Metro or Arduino to measure the voltage changes as the DS3502 adjusts its resistance. The instructions below reference a [Metro](https://www.adafruit.com/product/2488), but the same applies to an Arduino

- Connect the **Metro 5V** to **Vcc** on the DS3502
- Connect **GND** on the Metro to **GND** &nbsp;on the DS3502
- Connect the **SCL** pins on the Metro and DS3502
- Connect the **SDA** pins on the Metro and DS3502&nbsp;
- Connect **RL** to **GND**
- Connect **RH** to **Metro 5V**
- Connect **RW** to the **A0** pin on the **Metro** , to allow us to measure the voltage

![adafruit_products_one_one.jpg](https://cdn-learn.adafruit.com/assets/assets/000/128/898/medium640/adafruit_products_one_one.jpg?1711381399)

Using a [STEMMA QT cable](https://www.adafruit.com/product/4399) makes it super easy. Pick a cable length and plug one into a STEMMA QT capable controller and the other end into the DS3502.

![](https://cdn-learn.adafruit.com/assets/assets/000/128/905/medium800/adafruit_products_arduino_stemma_bb.jpg?1711382365)

Featured
### STEMMA QT / Qwiic JST SH 4-Pin Cable - 50mm Long

[STEMMA QT / Qwiic JST SH 4-Pin Cable - 50mm Long](https://www.adafruit.com/product/4399)
This 4-wire cable is&nbsp;50mm / 1.9" long and fitted with JST SH female 4-pin connectors on both ends. Compared with the chunkier JST PH these are 1mm pitch instead of 2mm, but still have a nice latching feel, while being easy to insert and remove.

<a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/4399)
[Related Guides to the Product](https://learn.adafruit.com/products/4399/guides)
![Angled of of JST SH 4-Pin Cable.](https://cdn-shop.adafruit.com/640x480/4399-00.jpg)

# Library Installation

Once wired up, to start using the DS3502, you'll need to install the&nbsp;[Adafruit\_DS3502 library](https://github.com/adafruit/Adafruit_DS3502). The library is available through the Arduino library manager so we recommend taking that approach.

From the Arduino IDE, open up the Library Manager:

![](https://cdn-learn.adafruit.com/assets/assets/000/077/293/medium800/adafruit_products_library_manager_menu.png?1561149147)

Click the&nbsp; **Manage Libraries ...** &nbsp;menu item, search for&nbsp; **Adafruit DS3502** ,&nbsp;and select the&nbsp; **Adafruit DS3502** &nbsp;library and click **Install** :

![](https://cdn-learn.adafruit.com/assets/assets/000/077/294/medium800/adafruit_products_library_manager.png?1561149611)

Follow the same process to install the&nbsp; **Adafruit BusIO** library.

![](https://cdn-learn.adafruit.com/assets/assets/000/077/295/medium800/adafruit_products_sensors_adafrtui_busio_arduino.png?1561149654)

# Load Example

Open up&nbsp; **File -\> Examples -\> Adafruit&nbsp;DS3502&nbsp;**** -\> ds3502\_test**and upload to your Metro wired up to the DS3502 breakout as shown above. Once you upload the code, you will see the wiper settings and measured voltage being printed when you open the Serial Monitor (**Tools-\>Serial Monitor**) at 115200 baud, similar to this:

![](https://cdn-learn.adafruit.com/assets/assets/000/077/329/medium800/adafruit_products_serial_monitor_output.png?1561156979)

# Example Code

The following code is part of the standard library and illustrates the basic function of using the variable resistance of the DS3502 to change the voltage measured at pin A0:

https://github.com/adafruit/Adafruit_DS3502/blob/master/examples/ds3502_test/ds3502_test.ino

# Adafruit DS3502 I2C Digital Potentiometer

## Arduino Docs

# Adafruit DS3502 I2C Digital Potentiometer

## Python & CircuitPython

# CircuitPython Microcontroller Wiring

Wiring the DS3502 to communicate with your microcontroller is straightforward thanks to the I2C interface. For these examples, we can use a Metro or a Feather to measure the voltage changes as the DS3502 adjusts its resistance. The instructions below reference a [Feather](https://www.adafruit.com/product/3857), but the same applies to a Metro.

- Connect the **Feather 3.3V** to **Vcc** on the DS3502
- Connect **GND** on the Feather to **GND** &nbsp;on the DS3502
- Connect the **SCL** pins on the Feather and DS3502
- Connect the **SDA** pins on the Feather and DS3502&nbsp;
- Connect **RL** to **GND**
- Connect **RH** to **Feather 3.3V**
- Connect **RW** to the **A0** pin on the **Feather** , to allow us to measure the voltage

![adafruit_products_cpy_fritz.png](https://cdn-learn.adafruit.com/assets/assets/000/079/057/medium640/adafruit_products_cpy_fritz.png?1565034087)

Using a&nbsp;[STEMMA QT cable](https://www.adafruit.com/product/4399)&nbsp;makes it super easy. Pick a cable length and plug one into a STEMMA QT capable controller and the other end into the DS3502.

![](https://cdn-learn.adafruit.com/assets/assets/000/128/906/medium800/adafruit_products_arduino_stemma_bb.jpg?1711382666)

# Python Computer Wiring

Since there's _dozens_ of Linux computers/boards you can use we will show wiring for [Raspberry Pi](https://www.adafruit.com/product/3055). For other platforms, [please visit the guide for CircuitPython on Linux to see whether your platform is supported](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux).&nbsp;

Here's the Raspberry Pi wired with I2C:

- **Pi 3V3** &nbsp;to&nbsp; **sensor VIN**
- **Pi GND** &nbsp;to&nbsp; **sensor GND**
- **Pi SCL** &nbsp;to&nbsp; **sensor SCL**
- **Pi SDA** &nbsp;to&nbsp; **sensor SDA**
- **Pi GND&nbsp;** to&nbsp; **sensor RL**
- **Pi 3V3** to&nbsp; **sensor RH**
- **Multimeter Positive Lead&nbsp;** to&nbsp; **sensor RW**
- **Multimeter Negative Lead&nbsp;** to **sensor GND**

![adafruit_products_rpi_fritz.png](https://cdn-learn.adafruit.com/assets/assets/000/078/833/medium640/adafruit_products_rpi_fritz.png?1564517656)

Note that because the Raspberry Pi does not include any pins with analog to digital converters (ADCs) to read the voltage that will change on the DS3502's&nbsp; **RW** &nbsp;pin, you will need to use a multimeter to measure the voltage between the **RW** pin and&nbsp; **GND.**

## CircuitPython Installation of DS3502 Library

You'll need to install the&nbsp;[Adafruit CircuitPython DS3502](https://github.com/adafruit/Adafruit_CircuitPython_DS3502) library on your CircuitPython board.

First make sure you are running the&nbsp;[latest version of Adafruit CircuitPython](https://learn.adafruit.com/welcome-to-circuitpython/installing-circuitpython)&nbsp;for your board.

Next you'll need to install the necessary libraries&nbsp;to use the hardware--carefully follow the steps to find and install these libraries from&nbsp;[Adafruit's CircuitPython library bundle](https://github.com/adafruit/Adafruit_CircuitPython_Bundle/releases).&nbsp; Our CircuitPython starter guide has [a great page on how to install the library bundle](https://learn.adafruit.com/welcome-to-circuitpython/circuitpython-libraries).

For non-express boards like the Trinket M0 or Gemma M0, you'll need to manually install the necessary libraries from the bundle:

- **adafruit\_ds3502.mpy**
- **adafruit\_bus\_device**
- **adafruit\_register**

Before continuing make sure your board's lib folder or root filesystem has the&nbsp; **adafruit\_ds3502.mpy,**  **adafruit\_bus\_device** , and&nbsp; **adafruit\_register** files and folders **&nbsp;** copied over.

Next&nbsp;[connect to the board's serial REPL&nbsp;](https://learn.adafruit.com/welcome-to-circuitpython/the-repl)so you are at the CircuitPython&nbsp; **\>\>\>** &nbsp;prompt.

## Python Installation of DS3502 Library

You'll need to install the **Adafruit\_Blinka** library that provides the CircuitPython support in Python. This may also require enabling I2C on your platform and verifying you are running Python 3.&nbsp;[Since each platform is a little different, and Linux changes often, please visit the CircuitPython on Linux guide to get your computer ready](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux)!

Once that's done, from your command line run the following command:

- `sudo pip3 install adafruit-circuitpython-ds3502```

If your default Python is version 3 you may need to run 'pip' instead. Just make sure you aren't trying to use CircuitPython on Python 2.x, it isn't supported!

# CircuitPython Usage
Info: 

To demonstrate the usage of the potentiometer we'll initialize it and set the wiper value to change the voltage on the&nbsp; **WH** pin. We will then use the&nbsp; **A0** pin to take an analog reading of the voltage on the&nbsp; **WH** pin.

Run the following code to import the necessary modules and initialize the I2C connection with the potentiometer:

```auto
from time import sleep
import board
import adafruit_ds3502
from analogio import AnalogIn

i2c = board.I2C()
ds3502 = adafruit_ds3502.DS3502(i2c)
wiper_output = AnalogIn(board.A0)
```

![](https://cdn-learn.adafruit.com/assets/assets/000/077/349/medium800/adafruit_products_cpy_imports.png?1561157666)

With the driver initialized, we can the set the wiper value, take an ADC reading to measure the voltage, and then convert the raw ADC value to a human-readable value

```auto
ds3502.wiper = 127
print("Wiper set to %d"%ds3502.wiper)
voltage = wiper_output.value
voltage *= 3.3
voltage /= 65535
print("Wiper voltage: %.2f V"%voltage)
```

![](https://cdn-learn.adafruit.com/assets/assets/000/077/350/medium800/adafruit_products_wiper_set_1.png?1561157775)

We can then change the wiper value and take another reading to see how the resulting voltage on the&nbsp; **RW** pin has changed

```auto
ds3502.wiper = 63
print("Wiper set to %d"%ds3502.wiper)
voltage = wiper_output.value
voltage *= 3.3
voltage /= 65535
print("Wiper voltage: %.2f V"%voltage)
```

![](https://cdn-learn.adafruit.com/assets/assets/000/077/351/medium800/adafruit_products_wiper_set_2.png?1561157847)

# Full CircuitPython Example Code
https://github.com/adafruit/Adafruit_CircuitPython_DS3502/blob/main/examples/ds3502_simpletest.py

# Python Usage
Because the Raspberry Pi and many other similar devices do not include the hardware for measuring analog voltages, you will have to use a multimeter to measure the voltage on the&nbsp; **RW** pin.  
  
To start, similar to above we will import the needed modules and initialize the driver

```auto
from time import sleep
import board
import adafruit_ds3502

i2c = board.I2C()
ds3502 = adafruit_ds3502.DS3502(i2c)
```

![](https://cdn-learn.adafruit.com/assets/assets/000/077/363/medium800/adafruit_products_rpi_imporrs.png?1561159957)

Once the driver has been initialized, we can use it to set the value of the wiper

```auto
ds3502.wiper = 127
```

![](https://cdn-learn.adafruit.com/assets/assets/000/077/366/medium800/adafruit_products_rpi_set_127.png?1561160138)

You can then use your multimeter or other voltage measuring device to check the voltage across&nbsp; **GND** and&nbsp; **RW.** It should be the same as the voltage on the **RH** pin which will be the voltage level of your device, most likely&nbsp; **3.3V**

Next, change the wiper value again and measure the voltage on the&nbsp; **RW pin**

```auto
ds3502.wiper = 63
```

![](https://cdn-learn.adafruit.com/assets/assets/000/077/365/medium800/adafruit_products_rpi_set_63.png?1561160103)

The voltage on the&nbsp; **RW&nbsp;** pin should be approximately half of the voltage at the&nbsp; **RH** pin, likely around&nbsp; **1.6V**

# Full Python Example Code
https://github.com/adafruit/Adafruit_CircuitPython_DS3502/blob/main/examples/ds3502_blinka_simpletest.py

# Adafruit DS3502 I2C Digital Potentiometer

## Python Docs

# Adafruit DS3502 I2C Digital Potentiometer

## Downloads

# Files

- [DS3502 Datasheet](https://datasheets.maximintegrated.com/en/ds/DS3502.pdf)
- [EagleCAD files on GitHub](https://www.github.com/adafruit/Adafruit-DS3502-PCB)
- [3D CAD files on GitHub](https://github.com/adafruit/Adafruit_CAD_Parts/tree/master/4286%20DS3502%20Digital%20Pot)
- [Fritzing object in Adafruit Fritzing Library](https://github.com/adafruit/Fritzing-Library/blob/master/parts/Adafruit%20DS3502.fzpz)

# Schematic
![](https://cdn-learn.adafruit.com/assets/assets/000/078/834/medium800/adafruit_products_schematic.png?1564517764)

# Fab Print
![](https://cdn-learn.adafruit.com/assets/assets/000/078/835/medium800/adafruit_products_fab_diagram.png?1564517774)


## Primary Products

### Adafruit DS3502 I2C Digital 10K Potentiometer Breakout

[Adafruit DS3502 I2C Digital 10K Potentiometer Breakout](https://www.adafruit.com/product/4286)
If you're a person like me that gets exhausted turning knobs all day, the DS3502 is just the ticket to calm all your knob-turning related troubles. Instead of having to&nbsp;_turn knobs&nbsp;_with your _HANDS_ like an _ANIMAL,&nbsp;_the DS3502 I2C Digital Potentiometer...

In Stock
[Buy Now](https://www.adafruit.com/product/4286)
[Related Guides to the Product](https://learn.adafruit.com/products/4286/guides)

## Guide Products

### STEMMA QT / Qwiic JST SH 4-Pin Cable - 50mm Long

[STEMMA QT / Qwiic JST SH 4-Pin Cable - 50mm Long](https://www.adafruit.com/product/4399)
This 4-wire cable is&nbsp;50mm / 1.9" long and fitted with JST SH female 4-pin connectors on both ends. Compared with the chunkier JST PH these are 1mm pitch instead of 2mm, but still have a nice latching feel, while being easy to insert and remove.

<a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/4399)
[Related Guides to the Product](https://learn.adafruit.com/products/4399/guides)

## Related Guides

- [Neocontroller Color Grading Input Box](https://learn.adafruit.com/neocontroller-color-grading-input-box.md)
- [Wireless ESP32-S2 Touch Screen Controller for Pure Data](https://learn.adafruit.com/wireless-esp32-s2-controller-for-pure-data.md)
- [USB C Power Delivery Monitor](https://learn.adafruit.com/usb-c-benchtop-power-supply.md)
- [Adafruit Sparkle Motion](https://learn.adafruit.com/adafruit-sparkle-motion.md)
- [Tiny Pod - BLE Rotary Encoder for iWatch](https://learn.adafruit.com/ano-pod.md)
- [Pick the Perfect Plant: Battery-Powered Sun Tracking](https://learn.adafruit.com/battery-powered-sun-tracking.md)
- [Adafruit Feather RP2040 with USB Type A Host](https://learn.adafruit.com/adafruit-feather-rp2040-with-usb-type-a-host.md)
- [Air Quality Monitor and Case](https://learn.adafruit.com/aqi-case.md)
- [CYBERDECK Expansion Plate](https://learn.adafruit.com/cyberdeck-plate.md)
- [Pico Bootloader Retro Console](https://learn.adafruit.com/pico-bootloader-retro-console.md)
- [DIY Trinkey No-Soldering USB Air Quality Monitor](https://learn.adafruit.com/diy-trinkey-no-solder-air-quality-monitor.md)
- [Adafruit RP2040 CAN Bus Feather](https://learn.adafruit.com/adafruit-rp2040-can-bus-feather.md)
- [Adafruit Feather RP2040 Adalogger](https://learn.adafruit.com/adafruit-feather-rp2040-adalogger.md)
- [Knobby Sequencer](https://learn.adafruit.com/knobby-sequencer.md)
- [CircuitPython Libraries and Jupyter Notebook on any Computer with MCP2221](https://learn.adafruit.com/jupyter-on-any-computer-with-circuitpython-libraries-and-mcp2221.md)
