Bluetooth Control of MCP4261 Pot

I am trying to use a bluetooth interface from my Iphone to output voltages from a MCP4261 dual pot to interface with a controller to control forward/reverse and left/right motion. I'm using an Arduino Uno with a Bluetooth breakout board.

I'm trying to take this a step at a time. The first being a sketch to talk to the MCP4261 and read the outputs of the wipers using 2 voltmeters as it loops from high to low resistance, etc. Once that's working, I want to work on the Bluetooth interface to provide X,Y coordinates via a joystick type app to drive the pots.

This is all very new to me and I think this is a substantial project.

I have spent lots of time surfing and reading the net looking for potential solutions but either they don't seem to work or conflict with each other.

I would appreciate any help with the first part of my project - talking to the MCP4261.


It should be a straightforward use of SPI...

I did some work with controlling these from the Espruino board a little while ago. IIRC, if you do anything wrong, they'll get unhappy and stop responding until you power cycle it. Also, don't forget the decoupling capacitor, 0.1uf between gnd and vcc as close to the chip as possible.

Thanks for your response.

I found the following sketch which is talking to the 4261. I hooked up a volt meter to each wiper. The issue I'm having is the voltage readings on one of wipers goes from .3 to 4.5 volts but the other wiper goes from 3.2 to 3.7

here's the sketch. Any suggestions. Do I have a bad 4261

  Digital Pot Control
  Based on the original sketch for AD5206....
  This example controls a Microchip digital potentiometer.
  The MCP42 has 2 potentiometer channels. Each channel's pins are labeled
  PAx - connect this to voltage
  PWx - this is the pot's wiper, which changes when you set it
  PBx - connect this to ground.

 The MCP42 is SPI-compatible,and to command it, you send two bytes: 

 The first byte is the Command Byte which has this format when
 the next byte is to be data: XX01XXpp
 note these bits ...............^^....  the 01 means the next byte is data
 (where pp = potentiometer selection, X= don't care)
 pp= 00 = dummy code, no pot selected
 pp= 01 = pot0
 pp= 10 = pot1
 pp= 11 = both pots

 Simplest case is to have X= 0 so the Command Byte will be:
 pp= 00: 00010000 = 16 
 pp= 01: 00010001 = 17
 pp= 10: 00010010 = 18
 pp= 11: 00010011 = 19

 The second byte is the resistance value for the channel (0 - 255).  

 The circuit:
  * All PA pins of MCP42 connected to +5V
  * All PB pins of MCP42 connected to ground
  * An LED and a 220-ohm resisor in series connected from each PW pin to ground
  * CS - to digital pin 10  (SS pin)
  * SI - to digital pin 11 (MOSI pin)
  * SCK - to digital pin 13 (SCK pin)

 created 10 Aug 2010 
 by Tom Igoe

 Thanks to Heather Dewey-Hagborg for the original tutorial, 2005

 Version for MCP42xx April 2013, Jim Brown


// include the SPI library:
#include <SPI.h>

// set pin 10 as the slave select for the digital pot:
const int slaveSelectPin = 10;

void setup() {
  // set the slaveSelectPin as an output:
  pinMode (slaveSelectPin, OUTPUT);
  // initialize SPI:

void loop() {
  // go through pp=01, 10, 11  for pot0, pot1 and both together of the digital pot:
  for (int CommandByte = 17; CommandByte < 20; CommandByte++) {    // 17, 18 and 19
    // change the resistance on this pot from min to max:
    for (int level = 0; level < 255; level++) {
      digitalPotWrite(CommandByte, level);
    // wait at the top:
    // change the resistance on this channel from max to min:
    for (int level = 0; level < 255; level++) {
      digitalPotWrite(CommandByte, 255 - level);


int digitalPotWrite(int CommandByte, int value) {
  // take the SS pin low to select the chip:
  //  send in the address and value via SPI:
  // take the SS pin high to de-select the chip:

The 2 addresses that I use are 0 and 18 ...your code steps thru 17, 18 and it appears that your only writing to one valid address ...18.

void digitalPotWrite(int address, int value){// addresses = 0 & 18 for the MCP4261-502E/P Digital Potentiometer ...they may need to change for other chips. 
  // take the SS pin low to select the chip:  
  // send in the address and value via SPI:
  // take the SS pin high to de-select the chip:

As usual, you came through. Made the change and it works!

Thank you