[UP] Problem finding a suitable library for Arduino YUN and MCP4152

Hi, I linked Arduino YUN to MCP4152(two digital potenziometer ) in the follow way:

  • pin 10 YUN to pin 1 MCP4152
  • pin 11 YUN to pin 3 MCP4152
  • pin 12 YUN to pin 12 MCP4152
  • pin 13 YUN to pin 2 MCP4152

MCP and YUN connected at USB of the PC so +5V.
Now I'm not able to find a library with a code than can make to work whole.
Don't tell me to reinvent the weel and work directly with the bit with the SPI.h functions.
Please help me: I tryed a lot of code for make that but doesn't work.
The multimeter doesn't sign nothing about the variations in Kohms.
My code:

typ#include <SPI.h>
#include <mcp4xxx.h>

using namespace icecave::arduino;

MCP4XXX* pot;

void setup()
{
    // Construct an instance of the MCP4XXX to manage the digipot.
    // The first parameter is the pin number to use for 'chip select' (CS), if you are
    // using the default SPI CS pin for your Arduino you can simply omit this parameter.
    pot = new MCP4XXX(10);
}

void loop()
{
    // Move the wiper to the lowest value
    pot->set(0);

    // Move the wiper to the highest value
    pot->set(pot->max_value());

    // Increment the wiper position by one
    pot->increment();

    // Decrement the wiper position by one
    pot->decrement();
}

entry deleted
Is this the library the Yun needs?

How does your DMM manage to measure the values of the digital potentiometers so quickly? In the program loop, you successively set different values, but because you don't have a delay, the microcontroller executes it very quickly. I doubt you could see it without an oscilloscope. Why don't you try adding a few seconds delay after each change? It may turn out that everything works.

I put delay(500); and nothing change: the value in the multimeter is 5Kohms.
Why?
My code:

#include <SPI.h>
#include <mcp4xxx.h>

using namespace icecave::arduino;

MCP4XXX* pot;

void setup()
{
    // Construct an instance of the MCP4XXX to manage the digipot.
    // The first parameter is the pin number to use for 'chip select' (CS), if you are
    // using the default SPI CS pin for your Arduino you can simply omit this parameter.
    pot = new MCP4XXX(10);
}

void loop()
{
    // Move the wiper to the lowest value
    pot->set(0);

    // Move the wiper to the highest value
    pot->set(pot->max_value());
    delay(500);
    // Increment the wiper position by one
    pot->increment();
    delay(500);
    // Decrement the wiper position by one
    pot->decrement();
    delay(500);
}

I used now the follow code but doesn't work:

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

// set pin 10 as the slave select for the digital pot:

const int slaveSelectPin = 10;


void digitalPotWrite(int address, int value) {

  // take the SS pin low to select the chip:

  digitalWrite(slaveSelectPin, LOW);

  delay(100);

  //  send in the address and value via SPI:

  SPI.transfer(address);

  SPI.transfer(value);

  delay(100);

  // take the SS pin high to de-select the chip:

  digitalWrite(slaveSelectPin, HIGH);
}

void setup() {

  // set the slaveSelectPin as an output:

  pinMode(slaveSelectPin, OUTPUT);

  // initialize SPI:

  SPI.begin();
}

void loop() {

  // go through the six channels of the digital pot:

 
    // change the resistance on this channel from min to max:

    for (int level = 0; level < 255; level++) {

      digitalPotWrite(0, level);

      delay(10);

    }

    // wait a second at the top:

    delay(100);

    // change the resistance on this channel from max to min:

    for (int level = 0; level < 255; level++) {

      digitalPotWrite(0, 255 - level);

      delay(10);

    }
}

Why please? The slaveSelectPin is 10
I use an MCP4251 with 100Kohms (two potentiometer).
The impedence of the potentiometer is at 9Mohms but haven't a variation.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.