Arduino library for MCP4251 Digital Potentiometer
Explore the docs »
This library can be used for interfacing and controlling the MCP4251 IC with the Arduino. The MCP4251 IC is a volatile, 8-bit (257 wiper steps) digital potentiometers with an SPI compatible interface. It is available with end-to-end resistor values of 5KΩ, 10KΩ, 50kΩ and 100KΩ. More information on the product page.Other MCP42xx family ICs can also be used, but full functionality of the library may not be guaranteed.
DigitalPotResistanceToPosition
and DigitalPotPositionToResistance
.- DigitalPotWiperIncrement
- DigitalPotWiperDecrement
- DigitalPotSetWiperPosition
- DigitalPotSetWiperMin
- DigitalPotSetWiperMax
- DigitalPotSetWiperMid
- DigitalPotReadWiperPosition
- DigitalPotReadTconRegister
- DigitalPotReadStatusRegister
- DigitalPotWriteTconRegister
- DigitalPotStartup
- DigitalPotShutdown
- DigitalPotTerminalBConnect
- DigitalPotTerminalBDisconnect
- DigitalPotTerminalAConnect
- DigitalPotTerminalADisconnect
- DigitalPotWiperConnect
- DigitalPotWiperDisconnect
- DigitalPotInitTcon
- DigitalPotResistanceToPosition
- DigitalPotPositionToResistance
Two examples are available in library. Following is the simple example of interfacing a single MCP4251 with the Arduino. Only one potentiometer (pot0) is controlled and wiper is set to a position = 256
.
#include <MCP4251.h>
#define chipSelectPin 53
#define pot0ResistanceRmax 98600 // These resistance values may vary
#define pot0ResistanceRmin 113.5
#define pot1ResistanceRmax 98600
#define pot2ResistanceRmin 130
MCP4251 digitalPot(chipSelectPin, pot0ResistanceRmax, pot0ResistanceRmin, pot1ResistanceRmax, pot2ResistanceRmin);
bool potNum = 1;
uint16_t pos;
void setup()
{
Serial.begin(9600);
digitalPot.begin();
}
void loop()
{
pos = 256;
digitalPot.DigitalPotSetWiperPosition(potNum, pos);
while(1)
{
}
}
The documentation is available at https://kulbhushanchand.github.io/MCP4251/
Any contributions you make are greatly appreciated. You can contribute to this project in the following ways :
Please note that this project is released with a Contributor Code of Conduct. By contributing to this project you agree to abide by its terms.
This project is distributed under the GPLv3
License. See LICENSE for more information.
The open-source tools used in development of this project.