GY-63_MS5611/libraries/MCP_POT
2024-01-19 16:00:25 +01:00
..
.github 0.1.0 MCP_POT 2023-12-22 16:45:25 +01:00
examples/MCP_POT_demo 0.2.0 MCP_POT 2024-01-19 16:00:25 +01:00
test 0.1.0 MCP_POT 2023-12-22 16:45:25 +01:00
.arduino-ci.yml 0.1.0 MCP_POT 2023-12-22 16:45:25 +01:00
CHANGELOG.md 0.2.0 MCP_POT 2024-01-19 16:00:25 +01:00
keywords.txt 0.1.0 MCP_POT 2023-12-22 16:45:25 +01:00
library.json 0.2.0 MCP_POT 2024-01-19 16:00:25 +01:00
library.properties 0.2.0 MCP_POT 2024-01-19 16:00:25 +01:00
LICENSE 0.2.0 MCP_POT 2024-01-19 16:00:25 +01:00
MCP_POT.cpp 0.2.0 MCP_POT 2024-01-19 16:00:25 +01:00
MCP_POT.h 0.2.0 MCP_POT 2024-01-19 16:00:25 +01:00
README.md 0.2.0 MCP_POT 2024-01-19 16:00:25 +01:00

Arduino CI Arduino-lint JSON check GitHub issues

License: MIT GitHub release PlatformIO Registry

MCP_POT

Arduino library for MCP41xxx and MCP42xxx SPI based digital potentiometers.

Description

Experimental to be tested on hardware.

The MCP_POT library implements digital potentiometers. The chips have 1 or 2 potentiometers, 10 KΩ, 50 KΩ and 100 KΩ and communicates over SPI. The library supports both hardware SPI and software SPI.

type potentiometers notes
MCP41010 10 1 not tested yet.
MCP41050 50 1
MCP41100 100 1
MCP42010 10 2 daisy chain allowed
MCP42050 50 2
MCP42100 100 2

Current version allows manual override of the hardware SPI clock.

Alt-234 = Ω

0.2.0 Breaking change

Version 0.2.0 introduced a breaking change to improve handling the SPI dependency. The user has to call SPI.begin() or equivalent before calling AD.begin(). Optionally the user can provide parameters to the SPI.begin(...)

Mainly other digital potentiometers.

Interface

#include "MCP_POT.h"

Constructors

Base class.

  • MCP_POT(uint8_t select, uint8_t reset, uint8_t shutdown, SPIClassRP2040 * mySPI = &SPI) hardware constructor RP2040
  • MCP_POT(uint8_t select, uint8_t reset, uint8_t shutdown, SPIClass * mySPI = &SPI) hardware constructor other
  • MCP_POT(uint8_t select, uint8_t reset, uint8_t shutdown, uint8_t dataOut, uint8_t clock)

The derived classes have same constructors with same parameters as the base class.

  • MCP41010(...) constructor 1 potentiometer, 10 KΩ
  • MCP41050(...) constructor 1 potentiometer, 50 KΩ
  • MCP41100(...) constructor 1 potentiometer, 100 KΩ
  • MCP42010(...) constructor 2 potentiometer, 10 KΩ
  • MCP42050(...) constructor 2 potentiometer, 50 KΩ
  • MCP42100(...) constructor 2 potentiometer, 100 KΩ
  • void begin(uint8_t value = MCP_POT_MIDDLE_VALUE)
  • void reset(uint8_t value = MCP_POT_MIDDLE_VALUE)
  • bool setValue(uint8_t value) set both potmeters.
  • bool setValue(uint8_t pm, uint8_t value)
  • uint8_t getValue(uint8_t pm = 0)

SPI

  • void setSPIspeed(uint32_t speed) sets SPI clock in Hz.
  • uint32_t getSPIspeed() gets current speed in Hz.

Miscellaneous

  • uint8_t pmCount() returns the number of potmeters.
  • void powerOn() set SHUTDOWN pin HIGH (device enabled).
  • void powerOff() set SHUTDOWN pin LOW (device disabled).
  • bool isPowerOn() idem.

Debug

  • bool usesHWSPI() returns true if hardware SPI is used.

About SPI Speed

SPI code is based upon MCP_ADC.

The default SPI speed is reduced to 1 MHz. This is the value recommended in the datasheet for 2.7 Volt.

Board Voltage safe max
ESP32 2.7V 1 MHz 4 MHz
UNO 5.0V 2 MHz 4 MHz

For hardware SPI the ESP32 uses the VSPI pins. (see ESP examples).

Daisy Chaining

Not supported yet. (need hardware)

The MCP42xxx series have a dataout pin which allows to daisy chain the devices. The devices must share a CS signal, or at least all of them should have been selected to forward bytes. WHen the CS signal goes HIGH again, all devices will simultaneously change to their new values. However per device at most one potmeter can be set in a daisy chain, or both have the same value.

Future

Must

  • improve documentation
  • buy hardware and test

Should

  • investigate and implement daisy chaining of MCP42xxx

Could

  • improve SWSPI for AVR (code is under test for MCP23S17)

Wont

Support

If you appreciate my libraries, you can support the development and maintenance. Improve the quality of the libraries by providing issues and Pull Requests, or donate through PayPal or GitHub sponsors.

Thank you,