Example Arduino Sketch for MCP4261 Potentiometer Shield?



  • Just received my pot shield and was wondering if there is an example Arduino sketch available to get me up and running quickly?

    Thanks!



  • @swbooking

    We have an Arduino library for the MCP4261 Potentiometer Shield available in the iorodeo_arduino_libs repository on bitbucket https://bitbucket.org/iorodeo/iorodeo_arduino_libs/src See the mcp4261 sub-directory. Examples can be found in mcp4261/Examples.

    Here is a short example showing how to set the wiper positions of the potentiometers using the mcp4261 library.

    #include <SPI.h>
    #include "mcp4261.h"
    
    // Simple example demonstrating how to use the MCP4261 library with 
    // the MCP4261 Arduino Uno shield
    
    const int POT_0_CS = 5;
    const int POT_1_CS = 6;
    const int LOOP_DELAY = 200;
    MCP4261 pot0 = MCP4261(POT_0_CS);
    MCP4261 pot1 = MCP4261(POT_1_CS);
    
    void setup() {
    
        // Setup SPI communications
        SPI.setDataMode(SPI_MODE0);
        SPI.setBitOrder(MSBFIRST);
        SPI.setClockDivider(SPI_CLOCK_DIV8);
        SPI.begin();
    
        // Initialize potentiometers
        pot0.initialize();
        pot1.initialize();
    }
    
    void loop() {
        static int cnt=0;
    
        pot0.setWiper0(cnt);
        pot0.setWiper1(256-cnt);
    
        pot1.setWiper0(cnt);
        pot1.setWiper1(256-cnt);
    
        cnt += 1;
        if (cnt > 256) {
            cnt = 0;
        }
        delay(LOOP_DELAY);
    }
    

    The KiCad Design files for the Arduino Uno shield can be found here https://bitbucket.org/iorodeo/mcp4261_shield/src

    An image of the schematic is given below
    alt text



  • Awesome, thanks Will! got me up and running super quickly! :thumbsup:


Log in to reply