esp-idf-mcp41010

Three-Wire Digitally Controlled Potentiometer driver for ESP-IDF

MIT License

Stars
4

esp-idf-mcp41010

Three-Wire Digitally Controlled Potentiometer driver for ESP-IDF.

ESP32 has two 8-bit DAC (digital to analog converter) channels, connected to GPIO25 (Channel 1) and GPIO26 (Channel 2). ESP32S2 has two 8-bit DAC (digital to analog converter) channels, connected to GPIO17 (Channel 1) and GPIO18 (Channel 2). However, the maximum voltage is up to VDD. If you control a voltage up to 5V, you can use this.

And ESP32S3/ESP32Cx core does not have a DAC function.

  • MCP41010 = Single Digital Potentiometer (10 kOhms)
  • MCP41050 = Single Digital Potentiometer (50 kOhms)
  • MCP41100 = Single Digital Potentiometer (100 kOhms)
  • MCP42010 = Dual Digital Potentiometer (10 kOhms)
  • MCP42050 = Dual Digital Potentiometer (50 kOhms)
  • MCP42100 = Dual Digital Potentiometer (100 kOhms)

I ported from here.

Software requirements

ESP-IDF V4.4/V5.x. ESP-IDF V5.0 is required when using ESP32-C2. ESP-IDF V5.1 is required when using ESP32-C6.

Installation

git clone https://github.com/nopnop2002/esp-idf-mcp41010
cd esp-idf-mcp41010
idf.py set-target {esp32/esp32s2/esp32s3/esp32c2/esp32c3/esp32c6}
idf.py menuconfig
idf.py flash

Configuration

SPI BUS selection

The ESP32 series has three SPI BUSs. SPI1_HOST is used for communication with Flash memory. You can use SPI2_HOST and SPI3_HOST freely. When you use SDSPI(SD Card via SPI), SDSPI uses SPI2_HOST BUS. When using this module at the same time as SDSPI or other SPI device using SPI2_HOST, it needs to be changed to SPI3_HOST. When you don't use SDSPI, both SPI2_HOST and SPI3_HOST will work. Previously it was called HSPI_HOST / VSPI_HOST, but now it is called SPI2_HOST / SPI3_HOST.

Wirering

Circuit MCP ESP32 ESP32-S2/S3 ESP32-C2/C3/C6
CS -- GPIO5 GPIO34 GPIO1
SCK -- GPIO18 GPIO36 GPIO3
SI -- GPIO23 GPIO35 GPIO2
Vss -- GND GND GND
High terminals PA0/PA1 --
Wiper terminals PW0/PW1 --
Low terminals PB0/PB1 --
Vdd -- 3.3V 3.3V 3.3V

You can change it to any pin using menuconfig.

If you connect to Low terminals = Gnd and High terminals = 3.3V, 0 to 3.3V is output to Wiper terminals in 255 steps.

Typical circuit

API

See here.

Reference

https://github.com/nopnop2002/esp-idf-x9c103