Can't write to MCP4261 potentiometer


hello, i'm trying control digital potentiometer mcp4261 (datasheet). tried 3 approaches below, none of working. wiring @ end.
since can't measure resistance multimeter when it's powered, i'm instead measuring current through multimeter: wiper (pin 6) 150ohm resistor multimeter (current) ground. since i'm feeding +5v, expecting vary 1 ma 34 ma, can't budge 2ma (which matches default wiper-to-ground resistance of 2.6 kohm) of these codes.

(1) using mcp4261 library https://playground.arduino.cc/code/mcp4261 , example code.
i can run code fine, pot resistance doesn't change.
i added serial debugging lines, , i'm finding code stops executing or hangs tries write wiper resistance, i.e., in setup function have:
code: [select]

  serial.println("setup\n");
  mcp4261.wiper0_pos(0);
  serial.println("write wiper0");
  mcp4261.wiper1_pos(0);
  serial.println("write wiper1");


and serial reads:
quote
setup
if comment mcp4261.wiperx_pos(x) lines, serial prints expected until next write-to-wiper command:
quote
setup

write wiper0
write wiper1

scale 100%


(2) tried modifying digitalpotcontrol example comes spi library. ad5206, think maybe didn't switch addressing? i'm learning go here i'm not sure.
code: [select]

/*
  digital pot control

  this example controls analog devices ad5206 digital potentiometer.
  the ad5206 has 6 potentiometer channels. each channel's pins labeled
  a - connect voltage
  w - pot's wiper, changes when set it
  b - connect ground.

 the ad5206 spi-compatible,and command it, send 2 bytes,
 one channel number (0 - 5) , 1 resistance value the
 channel (0 - 255).

 the circuit:
  * pins  of ad5206 connected +5v
  * b pins of ad5206 connected ground
  * led , 220-ohm resisor in series connected each w pin ground
  * cs - digital pin 10  (ss pin)
  * sdi - digital pin 11 (mosi pin)
  * clk - digital pin 13 (sck pin)

 created 10 aug 2010
 by tom igoe

 thanks heather dewey-hagborg original tutorial, 2005

*/


// inslude spi library:
#include <spi.h>


// set pin 10 slave select digital pot:
const int slaveselectpin = 10;

void setup() {
  // set slaveselectpin output:
  pinmode(slaveselectpin, output);
  // initialize spi:
  spi.begin();
}

void loop() {
  // go through 6 channels of digital pot:
  for (int channel = 0; channel < 6; channel++) {
    // change resistance on channel min max:
    for (int level = 0; level < 255; level++) {
      digitalpotwrite(channel, level);
      delay(10);
    }
    // wait second @ top:
    delay(100);
    // change resistance on channel max min:
    for (int level = 0; level < 255; level++) {
      digitalpotwrite(channel, 255 - level);
      delay(10);
    }
  }

}

void digitalpotwrite(int address, int value) {
  // take ss pin low select chip:
  digitalwrite(slaveselectpin, low);
  //  send in address , value via spi:
  spi.transfer(address);
  spi.transfer(value);
  // take ss pin high de-select chip:
  digitalwrite(slaveselectpin, high);
}





(3) tried writing simple spi control i'd read in documentation , few other examples including this 1 mcp4251, , ended code below.  

in table 7-2 in documenation says spi string "write data volatile wiper 1"
'0001 00nn nnnn nnnn'
but got error when tried write 16-bit command:
'b0001010000000000' not declared in scope
so tried splitting 2 bytes i'd seen in other examples:
 spi.transfer(b00010100); //the command byte
 spi.transfer(b00000000); // data byte
which compiled fine didn't seem change wiper value.

code: [select]

#include <spi.h>  // include spi library
const int slaveselectpin = 10;
 
void setup() {
  pinmode (slaveselectpin, output); // slaveselectpin output  
  spi.begin();    // initialize spi:
}
 
void loop() {
  // take ss pin low select chip:
  digitalwrite(slaveselectpin,low);
  spi.transfer(b00010100); //the command byte
  spi.transfer(b00000000); // data byte
  digitalwrite(slaveselectpin,high);
  delay(10);

}
 




wiring setup of mcp4261 pins:
  • 1 cs arduino 10
  • 2 sck arduino 13
  • 3 sdi arduion 11
  • 4 vss ground
  • 5 p1b ground
  • 6 p1w 150ohm resistor multimeter (current) ground
  • 7 p1a +5v
  • 8 p0a +5v
  • 9 p0w unconnected
  • 10 p0b ground
  • 11 wp +5v
  • 12 shdn +5v (or in method 2, digital pin 7 , 4.7k pull down resistor)
  • 13 sdo arduino 12
  • 14 vdd +5v




thanks getting working. i'm feeling stuck on this.



Arduino Forum > Using Arduino > Programming Questions > Can't write to MCP4261 potentiometer


arduino

Comments

Popular posts from this blog

Flip address is out of range arduino uno r3

Arduino Uno not uploading

Indesign and MathType fonts