Giter VIP home page Giter VIP logo

mcp4151's Introduction

Arduino API for MCP4151 digital potentiometer


How to use

Create an instance of it, like MCP4151 pot(CS, MOSI, MISO, SCK).
Where CS is chip select pin, MOSI is the output on the Arduino, MISO is the input, and SCK is the clock.
On the MCP4151, the MISO and MOSI are on the same pin. Use a 1 kOhm resistor to pull down the MISO pin
on the chip to GND, with the MOSI line (on the MOSI pin of the Arduino) in series with the resistor. There's another constructor that accepts more parameters if one needs more customization.

Import it into your project with #include <MCP4151.h>.


Available functions

pot.writeValue() and pot.getCurValue() where 'pot' is the name of the object initialized.
Function pot.getCurValue() retrieves the stored wiper value from the chip. If this isn't needed,
then connecting the resistor and MISO line are not needed and the Arduino can just have its MOSI line
connected to the chip's pin 3.

Will this work with other MCP41x1 chips? Yes probably. Only tested with MCP4151.

mcp4151's People

Contributors

nwb99 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

ua6em

mcp4151's Issues

is SPI.begin() missing?

Hi there,

thanks for the lib!

Was there a reason not to use SPI.begin() (https://www.arduino.cc/reference/en/language/functions/communication/spi/begin/) in the constructors instead of:

MCP4151/src/MCP4151.cpp

Lines 25 to 30 in 63f302b

pinMode(CSpin, OUTPUT);
pinMode(MOSIpin, OUTPUT);
pinMode(MISOpin, INPUT_PULLUP);
pinMode(SCKpin, OUTPUT);
digitalWrite(MOSIpin, LOW);
digitalWrite(SCKpin, LOW);

MCP4151/src/MCP4151.cpp

Lines 42 to 46 in 63f302b

pinMode(CSpin, OUTPUT);
pinMode(MOSIpin, OUTPUT);
pinMode(MISOpin, INPUT_PULLUP);
pinMode(SCKpin, OUTPUT);
digitalWrite(MOSIpin, LOW);

BR

Software pull-up and hard-ware pull down?

Hello, I love the simplicity of your include. Looking at your README.MD and your code, I find the following a bit confusing with regard to the MISO pin.

On the one hand, you advise: 'On the MCP4151, the MISO and MOSI are on the same pin. Use a 1 kOhm resistor to pull down the MISO pin on the chip to GND, with the MOSI line (on the MOSI pin of the Arduino) in series with the resistor."

On the other hand, in your code you tell the Arduino to pull-up that same pin via pinMode(MISOpin, INPUT_PULLUP)

So at the same time, we seem to pull-up AND pull-down the MISO pin. I can imagine you use a software INPUT_PULLDOWN on some pins.

I am still a layman, but maybe you can provide some clarification?

Best regards, Lucien

Support for Nano Every?

I've used this library for an Arduino Uno, but on my Leonardo with its weird mapping of SPI pins it didn't work. The project this is for is going into a vehicle, where I normally use the Nano Every due to its robust power management, so given the issues with the Leonardo I'm a little gun shy.

Can you tell me if this library will have issues on the Nano Every due to use of Atmega328 specific registers or other issues?

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.