Labs / Electronic modules

GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)

Author: Li Zisheng · Source: FreakStudio open documentation, v1.3 · License: CC BY 4.0 · Driver code (signal_generation/ds3502_driver): MIT License

Contents
GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)
GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)

I. Module Introduction

DS3502-based digital potentiometer module supports I2C communication (SDA, SCL interfaces), is equipped with address setting DIP switches (A0, A1), and enables digital potentiometer adjustment via the I2C protocol; it integrates step-down voltage regulation, power filtering and indicator lights, is suitable for scenarios such as maker development and circuit debugging, requires the input signal frequency to be less than 400KHz, and provides a programmable resistance adjustment solution for the system.

II. Introduction to Major Chips

2.1 Chip Overview

The DS3502 is a 7-digit digital potentiometer, which can be communicated with via the I2C interface using a microcontroller to adjust its resistance value. The DS3502 provides 128 resistance adjustment steps, and this device supports a wide range of supply voltages, typically operating between 2.7V and 5.5V.

GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)

DS3502 can operate at speeds up to 400kHz, with a maximum resistance value of 10kΩ. By adjusting the two address setting pins, it supports up to four DS3502 digital potentiometers on the same bus, and it also has EEPROM function, which can save the set 7-bit resistance value after power failure.

2.2 Pin Definition

GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)

DS3502 The pins and their functions are as follows:

Pin Name

Pin Number

Pin Functions

SDA

1

I2C Serial Data: Used for the input and output of I2C data.

The voltage of SDA ranges from -0.5V to (VCC + 0.5V), and shall not exceed + 6.0V.

SCL

10

I2C Serial Clock: The input pin of the I2C clock, which is responsible for synchronizing data transmission.

The voltage of SCL ranges from -0.5V to (VCC + 0.5V), and shall not exceed + 6.0V.

VCC

3

Power supply voltage terminal: Connect to an external power source to provide the operating voltage required for the device, which is typically in the range of 2.5V to 5.5V.

GND

2

Ground terminal: the grounding terminal of a device, which serves as the reference point for the circuit.

A1, A0

4, 5

Address selection input: Used to specify the I2C slave device address.

RH

6

High-end terminal: the high end of a potentiometer, connected to the positive power supply in the application.

The voltage range is from -0.5V to V+.

RW

7

Slider terminal: The sliding end of a potentiometer, which outputs an adjustable voltage and is usually connected to a load or a subsequent circuit.

The voltage range is from -0.5V to V+.

RL

8

Low-end terminal: the low end of a potentiometer, connected to ground or a negative power supply.

The voltage range is from -0.5V to V+.

V+

9

Slide bias voltage: It provides a bias voltage for the sliding terminal, with a voltage range from -0.5V to + 17V, which affects the output voltage range.

2.3 Functional Block Diagram

DS3502 The internal structure of the chip is shown below, and its core units include I2C communication interface, control register, tap register and resistor network:

GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)

The sliding position of the DS3502 is controlled by the value in the Wiper Register (WR). Upon power-up, the initial value of the sliding position is programmed via the Initial Value Register (IVR); after power-up, the data in the IVR register is loaded into the WR register, thereby setting the initial position of the potentiometer's wiper terminal (RW).

GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)

The Control Register (Control Register, CR) is located at address 02h and contains the WR / IVR address mode bit (MODE bit); the MODE bit determines how to write to the I2C WR and IVR data registers:

EEPROM and SRAM retain their data when the MODE bit is switched; upon power-up, the default value of the CR control register is 00h.

DS3502 potentiometer consists of 127 series-connected resistors connected between the RH and RL pins. By changing the value (a decimal value ranging from 0 to 127) in the wiper register (Wiper Register, WR), DS3502 's internal decoder controls specific MOS transistors to turn on or off. The MOS transistors act as switches in the resistor network to select which resistor node the wiper terminal (RW) is connected to:

GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)

Based on this principle, we can adjust DS3502 the resistance of the potentiometer's wiper terminal to achieve different voltage outputs. If RH, RL and RW are connected in a voltage divider configuration, the voltage across RW can be calculated using the following formula:

VRW=VRL+(VRH−VRL)×WR127V_{RW} = V_{RL} + \frac{(V_{RH} - V_{RL}) \times WR}{127}

Wherein,WRWRis the wiper position, expressed in decimal (0-127),VRLV_{RL}is the voltage at the RL terminal,VRHV_{RH}and is the voltage at the RH terminal.

Here, in the electrical characteristics section of the DS3502 chip datasheet, we can see that after the wiper is adjusted to a new resistance value, it takes 1μs (i. e., the Wiper response time tWRS) to stabilize:

GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)

Therefore, theoretically, when the DS3502 acts as a variable voltage divider to adjust the output voltage, its maximum operating frequency is 1 MHz (1/tWRS).

2.4 Performance Parameters

GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)
GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)
GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)
GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)
GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)

2.5 Reference Circuit

GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)

2.6 Chip Configuration

DS3502 chip's I2C communication address is determined by the two pins A1 and A0:

GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)

When writing single-byte data to the DS3502 chip using a microcontroller, it is necessary to write the device address (pins A0 and AI in the figure below are both connected to GND), the register address and the write data, as shown below:

GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)

For example, when writing to the WR register, the communication process is as follows:

GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)

When the CR register MODE bit is set to 0, since writing to the EEPROM register requires a certain period of time, the master device can repeatedly address the DS3502 to check whether it responds, so as to determine whether the DS3502 has completed writing to the EEPROM register; alternatively, the master can directly wait for the maximum EEPROM write time (tW), which can be found in the electrical characteristics section of the DS3502 datasheet and is specified as 20ms:

GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)

When using a microcontroller to read single-byte data from the DS3502 chip, take reading the value of the CR control register as an example:

GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)

  1. First, send the slave address byte and set the R/W bit to 0 to perform a dummy write operation, then the slave will send an ACK response signal;
  2. Write the memory address to be read 02h, and the slave sends an ACK response signal;
  3. Generate duplicate START conditions to maintain communication;
  4. Write the slave address again and set the R/W bit to 1, indicating that data is to be read;
  5. The slave device sends a single-byte data of the corresponding register, the master device reads the data byte, uses the NACK signal to indicate the end of transmission, and generates a STOP condition.

When using the DS3502 chip, note that decoupling capacitors of 0.01µF and 0.1µF should be used for the power supply pin (VCC) and the sliding voltage pin (V+), and 4.7kΩ pull-up resistors should be applied to the SDA and SCL pins;additionally, if the voltage of RH is higher than that of VCC, V+ must be kept at the same or a higher voltage level as RH, which means V+ should be connected to RH.

Meanwhile, it should be noted that the voltage range of the sliding voltage pin (V+) is + 4.5V to 15.5V:

GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)

2.8 PCB Routing Precautions

None.

III. Instructions for Circuit Engineering and Module Usage

3.1 Circuit Source Engineering

To obtain the source project of the circuit, please follow the official account [Freak Embedded]

3.2 Module Usage Instructions

The schematic diagram of this module is shown below:

SCH_Digital Potentiometer Module Based on DS3502_v1.0_2025-11-23.pdf 1.8 MB

GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)
GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)

This module provides an I2C interface for communication: it supports a maximum I2C clock frequency of 400kHz, is compatible with I2C standard mode and fast mode, and can realize programmable adjustment of the digital potentiometer through this interface. Meanwhile, with the help of the I2C communication mechanism, it can also realize non-volatile storage of potentiometer settings, ensuring that parameters are permanently retained after power-off, which is suitable for scenarios requiring dynamic and stable resistance adjustment such as circuit debugging and signal conditioning.

When using this module, you need to short the three sets of pads of the address selection pins A0 and A1 on the back of the module to GND or VCC to configure the device address; in addition, turn on the SW1 DIP switch's RL to short it to GND, turn on its V+ to short it to RH, and connect a power supply (e. g. + 5V) to the U3 terminal's RL and V+ pins:

GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)
GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)

Note that if the voltage at RH is higher than VCC, V+ must be maintained at the same or a higher voltage level as RH; that is, V+ shall be connected to RH.

Meanwhile, it should be noted that the voltage range of the sliding voltage pin (V+) is + 4.5V to 15.5V:

GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)

3.3 Application Experiment

Here, we use the Fengya No. 1 board for testing. First, you need to plug the Fengya No. 1 Board - Grove Interface Expansion Board into the Fengya No. 1 Board - Universal Compatible Expansion Board, and meanwhile use a 4P cable to connect the I2C1 port on the Fengya No. 1 Board - Grove Interface Expansion Board with the I2C port on the GraftSense - DS3502-based Digital Potentiometer Module:

GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)

Then insert the Fengya No.1 Board-Universal Compatible Expansion Board into the Fengya No.1 Board-Data Conversion Board , and open the SCL , SDA and RDY options of the Fengya No.1 Board-Data Conversion Board on the SWITCH1 DIP switch, and open the ADC1 switch option of the SWITCH2 DIP switch:

GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)
GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)

Before conducting application experiments, you need to on the back side of the DS3502-based digital potentiometer module configure the device address by shorting the three pads of the address selection terminals A0 and A1 to GND or VCC; in addition, turn on the RL of the DIP switch SW1 to short it with GND, turn on the V+ to short it with RH, and connect a + 5V power supply to the RL and V+ on the U3 terminal (it is recommended to use the GraftSense - LM2596S-based adjustable power supply module):

GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)
GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)

The physical image after insertion is as follows:

GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)
GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)
GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)

Here, the signal output interface on the DS3502-based digital potentiometer module is the terminal U3 's RW. We also need to use an SMA to DuPont wire adapter to connect the RW signal output interface of terminal U3 on the GraftSense - DS3502-based digital potentiometer module to the ADC0 internal analog-to-digital conversion SMA interface on the Fengya No. 1 Board - Data Conversion Board , as shown in the following figure:

In addition, we first need to connect the MiniUSB data cable to the serial port on the Fengya No. 1 Board - Universal Compatible Expansion Board; here, GP0 and GP1 are the default pins of the Raspberry Pi Pico's hardware serial port UART0:

GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)

Here, the digital potentiometer module based on DS3502 on the signal output interface is the RW of terminal U3 , we also need to use SMA to DuPont cable adapter to digital potentiometer module based on DS3502 on the terminal U3 of the RW signal output interface and Fengya No.1 board - data conversion board on the ADC0 internal analog-to-digital conversion SMA interface are connected to each other, as shown in the following figure:

GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)

The overall connection diagram is shown as follows:

The wiring conditions of the components are shown in the following table:

Module / DevicePin / Interface / Configuration itemConnection targetTarget pin / Interface
Raspberry Pi Pico (core of the Fengya No. 1 board)GP10 (I2C1_SDA)Grove interface expansion board I2C1SDA pin
Raspberry Pi Pico (core of the Fengya No. 1 board)GP11 (I2C1_SCL)Grove interface expansion board I2C1SCL pin
Grove interface expansion boardI2C1_SDADS3502 module I2CSDA interface
Grove interface expansion boardI2C1_SCLDS3502 module I2CSCL interface
DS3502 moduleAddress select pin A0GND/VCCPad shorted
DS3502 moduleAddress select pin A1GND/VCCPad shorted
DS3502 moduleSW1 DIP switch RLModule internal GNDDIP switch shorted
DS3502 moduleSW1 DIP switch V+Module internal RHDIP switch shorted
3.3V power supplyOutput terminalDS3502 module U3 terminalRL interface
3.3V power supplyOutput terminalDS3502 module U3 terminalV+ interface
Raspberry Pi Pico (core of the Fengya No. 1 board)GP0 (UART0_TX)Universal compatible expansion board serial portTX pin
Raspberry Pi Pico (core of the Fengya No. 1 board)GP1 (UART0_RX)Universal compatible expansion board serial portRX pin
Universal compatible expansion boardSerial port interfaceMiniUSB cableUSB male end
DS3502 moduleU3 terminal RW (signal output)Data conversion board ADC0SMA interface
Data conversion boardADC0 interfaceRaspberry Pi Pico (core of the Fengya No. 1 board)GP26 (ADC0)

Here, we need to search for the relevant driver packages on uPyPI: https://upypi.net/zh/

GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)

Enter ds3502_driver for search, and the following will be displayed:

GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)

Click to copy the local installation command:

GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)

Here, we can use the mip tool to import module driver library code. Below are the usage commands for the mpremote tool:

mpremote mip install github:FreakStudioCN/GraftSense-Drivers-MicroPython/signal_generation/ds3502_driver

After importing the digital potentiometer module based on DS3502 - MicroPython driver code, copy the following main.py code into our project:

# Python env   : MicroPython v1.23.0
# -*- coding: utf-8 -*-        
# @Time    : 2025/3/21 3:04 PM
# @Author  : Li Qingshui
# @File    : main.py       
# @Description : Output arbitrary waveforms using the DS3502 digital potentiometer

# ======================================== Import Modules ========================================

# Import the hardware module
from machine import ADC, Timer, Pin, I2C, UART
# Import time-related modules
import time
# Import the module for accessing and controlling MicroPython internals
import micropython
# Import the ds3502 module used to control the digital potentiometer chip
from ds3502 import DS3502
# Import the waveform generation module
from dac_waveformgenerator import WaveformGenerator

# ======================================== Global Variables ============================================

# DS3502 chip address
DAC_ADDRESS = 0x00
# Voltage conversion factor
adc_conversion_factor = 3.3 / (65535)

# ======================================== Functions ============================================

def timer_callback(timer: Timer) -> None:
    """
    Timer callback function, used to read ADC data periodically and call the user-defined callback function.

    Args:
        timer (machine.Timer): Timer instance.

    Returns:
        None: This function has no return value.

    Raises:
        None: This function does not raise exceptions.
    """

    # Declare global variables
    global adc, adc_conversion_factor

    # Read ADC data
    value = adc.read_u16() * adc_conversion_factor
    # Call the user-defined callback function
    micropython.schedule(user_callback, (value))

def user_callback(value: float) -> None:
    """
    User-defined callback function, used to process the voltage value sampled by the ADC and send it over the serial port.

    Args:
        value (float): Voltage value sampled by the ADC.

    Returns:
        None: This function has no return value.

    Raises:
        None: This function does not raise exceptions.
    """
    # Declare global variables
    global uart

    # Get the floating-point number and round it to two decimal places
    formatted_value = "{:.2f}".format(value)
    # Send the sampled voltage data over the serial port
    uart.write(str(formatted_value) + '\r\n')

# ======================================== Custom Classes ============================================

# ======================================== Initialization ==========================================

# Delay 3 s to wait for the device to finish powering up
time.sleep(3)
# Print debug information
print("FreakStudio : Using Digital Potentiometer chip DS3502 to generate differential waveform")

# Create a hardware I2C instance using the I2C1 peripheral, with a clock frequency of 400KHz, SDA pin 2, and SCL pin 3
i2c = I2C(id=1, sda=Pin(2), scl=Pin(3), freq=400000)

# Start scanning for devices on the I2C bus and return a list of slave addresses
devices_list = i2c.scan()
print('START I2C SCANNER')

# If devices_list is empty, no device is connected to the I2C bus
if len(devices_list) == 0:
    print("No i2c device !")
# If not empty, print the slave device addresses
else:
    print('i2c devices found:', len(devices_list))
    # Iterate over the slave device address list
    for device in devices_list:
        # If the device address is between 0x28 and 0x2B, it is a DS3502 chip
        if 0x28 <= device <= 0x2B:
            print("I2C hexadecimal address: ", hex(device))
            DAC_ADDRESS = device

# Create a DS3502 object using the I2C1 peripheral, with address DAC_ADDRESS
dac = DS3502(i2c, DAC_ADDRESS)
# Set the DS3502 to fast mode (write only to the WR register)
dac.set_mode(1)

# Create the serial port object, set the baud rate to 115200
uart = UART(0, 115200)
# Initialize the uart object with a baud rate of 115200, 8 data bits, no parity bit, and 1 stop bit
# Set the serial port timeout to 100ms
uart.init(baudrate=115200,
          bits=8,
          parity=None,
          stop=1,
          tx=0,
          rx=1,
          timeout=100)

# Create an ADC instance: ADC2-GP28
adc = ADC(2)
# Create a software timer object
timer = Timer(-1)
# Start the timer, triggering the timer_callback function every 1ms; the ADC samples the voltage
timer.init(period=10, mode=Timer.PERIODIC, callback=timer_callback)

# ========================================  Main Program  ===========================================

# Generate the sine wave
print("FreakStudio : Generate Sine Waveform : 10Hz, 1.5V, 1.5V")
# Initialize the waveform generator
wave = WaveformGenerator(dac, frequency=5, amplitude=1.5, offset=1.5, waveform='sine')
# Start waveform generation
wave.start()
# Stop generation after running for a while
time.sleep(6)
wave.stop()

# Generate square wave
print("FreakStudio : Generate Square Waveform : 10Hz, 1.5V, 1.5V")
# Initialize the waveform generator
wave = WaveformGenerator(dac, frequency=5, amplitude=1.5, offset=1.5, waveform='square')
# Start waveform generation
wave.start()
# Stop generation after running for a while
time.sleep(6)
wave.stop()

# Generate triangle wave
print("FreakStudio : Generate Triangle Waveform : 10Hz, 1.5V, 1.5V, 0.8")
# Initialize the waveform generator
wave = WaveformGenerator(dac, frequency=5, amplitude=1.5, offset=1.5, waveform='triangle', rise_ratio=0.8)
# Start waveform generation
wave.start()
# Stop generation after running for a while
time.sleep(6)
wave.stop()

# Stop ADC sampling
timer.deinit()

Next, we launch SerialPlot software, select the corresponding port connected to the USB-to-TTL chip, and click the Open button:

GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)

Select the data format ASCII for encoding, and leave other configurations as default:

GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)

Burn the code, open a terminal, and use the mpremote tool to connect to the main controller; the output is as follows:

GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)

Open SerialPlot software, and you can see that the frequency and amplitude of the displayed DAC output voltage are both normal:

GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)
Sine wave generated by digital potentiometer, displayed
GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)
Square wave generated by digital potentiometer, displayed
GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)
Triangle wave generated by digital potentiometer, displayed
GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)
Single triangle wave generated by digital potentiometer, displayed

In the generated waveform, it can be seen that due to the low resolution (7-bit) of DS3502, the generated waveform has obvious steps, so it is not suitable for scenarios requiring high frequency or high precision.

IV. Drivers

ds3502_driver.zip 15 KB

None.

VI. Revision History

Document Version

Date of Revision

Modifier

Modified Content

v1.0

2025-11-22

Li Zisheng

Initialize the document

The BOM sheet has not been finally checked, the driver has not been re-verified, and the 3.3 application experiment

Not yet specified.

v1.1

2025-12-29

Li Zisheng

Added application experiments and production files

v1.2

2025-12-31

Xin Ruili

Create an open version of the document based on the internal document version v1.1.

v1.3

2026-03-29

Xin Ruili

Modified the application experiment section

VII. Relevant Materials

7.1 Chip Datasheet

DS3502 Digital Potentiometer Datasheet.pdf 157 KB

7.2 Unique Icons for PCB Silkscreen

GraftSense - Digital Potentiometer Module Based on DS3502 (Open Version)