Git Product home page Git Product logo

mcp4251's Introduction


Logo

MCP4251

Arduino library for MCP4251 Digital Potentiometer
Explore the docs »



Table of Contents

About

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.

Features

  • All available controls as per MCP4251 datasheet.
  • Additional functions like DigitalPotResistanceToPosition and DigitalPotPositionToResistance.
  • Simple to use.
  • Multiple MCP4251 ICs can be interfaced and controlled, subjected to the availability of I/O pins on Arduino board.

Installation

First method

library-manager

  1. In the Arduino IDE, navigate to Sketch > Include Library > Manage Libraries
  2. Then the Library Manager will open and you will find a list of libraries that are already installed or ready for installation.
  3. Then search for MCP4251 using the search bar.
  4. Click on the text area and then select the specific version and install it.

Second method

  1. Navigate to the Releases page.
  2. Download the latest release.
  3. Extract the zip file
  4. In the Arduino IDE, navigate to Sketch > Include Library > Add .ZIP Library

Functions

  • Set wiper position
- DigitalPotWiperIncrement
- DigitalPotWiperDecrement
- DigitalPotSetWiperPosition
- DigitalPotSetWiperMin
- DigitalPotSetWiperMax
- DigitalPotSetWiperMid
- DigitalPotReadWiperPosition
  • Set control registers
- DigitalPotReadTconRegister
- DigitalPotReadStatusRegister
- DigitalPotWriteTconRegister
  • Enable/disable connections
- DigitalPotStartup
- DigitalPotShutdown
- DigitalPotTerminalBConnect
- DigitalPotTerminalBDisconnect
- DigitalPotTerminalAConnect
- DigitalPotTerminalADisconnect
- DigitalPotWiperConnect
- DigitalPotWiperDisconnect
- DigitalPotInitTcon
  • Additional
- DigitalPotResistanceToPosition
- DigitalPotPositionToResistance

Usage

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.

connection-diagram

#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)
    {
    }
}

Documentation

The documentation is available at https://kulbhushanchand.github.io/MCP4251/

Contributing

Any contributions you make are greatly appreciated. You can contribute to this project in the following ways :

  • Add new functionality
  • Review code
  • Raise issues about bugs/features/doubts
  • Proof-read the documentation
  • Cite if used in a publication
  • Star on GitHub
  • Share with others

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.

License

This project is distributed under the GPLv3 License. See LICENSE for more information.

Acknowledgment

The open-source tools used in development of this project.

Contact

Kulbhushan Chand

mcp4251's People

Contributors

kulbhushanchand avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

spyroscpt

mcp4251's Issues

compile error with IDE 1.8.19 for MKRZERO warning: 'B00000000' is deprecated: use 0b00000000 instead

I would like to use the <MCP4251.h> library for a project using Arduino: 1.8.19 (Windows 10) and an "Arduino MKRZERO" for simulating NTC temperature sensors, using the 100kOhm version. However, when I try and compile the basic example provided, I get a large number of errors, such as:
..\Arduino\libraries\MCP4251\src\MCP4251.cpp:49:20: warning: 'B00000000' is deprecated: use 0b00000000 instead [-Wdeprecated-declarations]

 byte cmdByte = B00000000;

see attachment for complete list.
MCP4251_compile_errors.txt

error: prototype for '...' does not match any in class '...'

After making the changes defined in #1 and trying to recompile i get the following error:

Arduino\libraries\MCP4251\src\MCP4251.cpp:64:6: error: prototype for 'void MCP4251::DigitalPotSetWiperPosition(bool, unsigned int)' does not match any in class 'MCP4251'
 void MCP4251::DigitalPotSetWiperPosition(bool potNum, unsigned int value)
      ^~~~~~~
In file included from Arduino\libraries\MCP4251\src\MCP4251.cpp:1:0:
Arduino\libraries\MCP4251\src\MCP4251.h:43:8: error: candidate is: void MCP4251::DigitalPotSetWiperPosition(bool, uint16_t)
   void DigitalPotSetWiperPosition(bool potNum, uint16_t value); // Need confirmation if it is working
        ^~~~~~~~~~~~~~~~~~~~~~~~~~
exit status 1
Error compiling for board Arduino NANO 33 IoT.

To fix it i modified line 43 in MCP4251.h from:

void DigitalPotSetWiperPosition(bool potNum, uint16_t value); // Need confirmation if it is working

to

void DigitalPotSetWiperPosition(bool potNum, unsigned int value); // Need confirmation if it is working

With that change it now compiles. I'm unable to test if it actually works just yet but figured i would report this.

This is using Arduino IDE version: 1.8.16 and targeting an Arduino Nano 33 IOT.

I will report back about it physically working or not once ive got everything hooked up.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.