digital pot's ( AD5206 ) not working together!

hi! iv’e been working with a.square for some time trying to solve my problem, and i still have not found a solution, hopefully somebody here can help…

so i’m trying to make the rgb button pads from sparkfun work using 2 AD5206 digital pot’s working either simultaniously, or turn one off and the next on really fast to assume the allusion of constant on…

so i tried the tutorial on the AD5206 from the tutorial page, and it’s very nice, but when i try to change slave select, to lets say pin 8, or 18, or 4, or any random pin, it doesent seem to work, and that’s why i believe the second digital pot won’t work, becuase it seems only pin 10 works for the digital pots, and i have 2, so i need seprate slave selects…

when i try the code a.square gave me, it just flips out and doesent do anything impressive…

so here are some resources that will help you help me:

AD5206 tutorial:
http://www.arduino.cc/en/Tutorial/SPIDigitalPot
my code:

#define DATAOUT 11//MOSI
#define DATAIN 12//MISO - not used, but part of builtin SPI
#define SPICLOCK  13//sck
#define SLAVESELECT 10 // right here is the problem, only pin 10 on the arduino works, no other pin!
byte potpin = 0;
byte r1=0;
byte g2=1;
byte g1=2;
byte b2=3;
byte b1=4;
byte r2=5;
byte res1=255;
byte res2=255;
byte res3=255;
byte res4=255;
byte res5=255;
byte res6=255;
char spi_transfer(volatile char data)
{
  SPDR = data;                    // Start the transmission
  while (!(SPSR & (1<<SPIF)))     // Wait the end of the transmission
  {
  };
  return SPDR;                    // return the received byte
}

void setup()
{
  byte i;
  byte clr;
  pinMode(DATAOUT, OUTPUT);
  pinMode(DATAIN, INPUT);
  pinMode(SPICLOCK,OUTPUT);
  pinMode(SLAVESELECT,OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(4, OUTPUT);
  digitalWrite(SLAVESELECT,HIGH); //disable device
  // SPCR = 01010000
  //interrupt disabled,spi enabled,msb 1st,master,clk low when idle,
  //sample on leading edge of clk,system clock/4 (fastest)
  SPCR = (1<<SPE)|(1<<MSTR);
  clr=SPSR;
  clr=SPDR;
  delay(10);
  for (i=0;i<6;i++)
  {
    write_pot(i,255);
  }
}

byte write_pot(int address, int value)
{
  digitalWrite(SLAVESELECT,LOW);
  //2 byte opcode
  spi_transfer(address);
  spi_transfer(value);
  digitalWrite(SLAVESELECT,HIGH); //release chip, signal end transfer
}

void loop()
{
 digitalWrite(7, LOW);
write_pot(r2, 0);
 write_pot(g1, 0);
 delay(1);
 digitalWrite(7, HIGH);
 digitalWrite(6, LOW);
 write_pot(g1, 255);
 write_pot(r1, 0);
 write_pot(r2, 255);
 write_pot(b2, 0);
 delay(1);
 digitalWrite(5, LOW);
 digitalWrite(6, HIGH);
  write_pot(r1, 255);
  write_pot(b2, 255);
  write_pot(g1, 0);
  write_pot(b2, 0);
  write_pot(r2, 0);
 delay(1);
 digitalWrite(4, LOW);
 digitalWrite(5, HIGH);
 write_pot(b1, 0);
 write_pot(g2, 0);
 write_pot(g1, 0);
 write_pot(b2, 255);
 write_pot(r2, 255);
 delay(1);
 digitalWrite(4, HIGH);
write_pot(g2, 255);
write_pot(b1, 255);
write_pot(g1, 255); 
 }

a.square’s code:

// Each button randomly cycles through colors. 
// When a button is pressed, all of the buttons change to that color and pause
// The pressed button(s) is/are lit up white while pressed

#define DATAOUT 11//MOSI (pin 7 of AD5206)
#define DATAIN 12//MISO - not used, but part of builtin SPI
#define SPICLOCK  13//sck (pin 8 of AD5206)
#define ROWS 4
#define COLS 4
#define H 254
#define L 64

#define slavesel(x) ((x<6) ? 0 : 1)
const byte rowpin[ROWS] = {
  14,15,16,17};
const byte slaveselect[2] = {
  10, 18};

// The pot register numbers for each of the red, green, and blue channels
const byte red[4] = {
  5, 2, 7, 8};
const byte green[4] = {
  3, 0, 6, 11};
const byte blue[4] = {
  1, 4, 9, 10};
byte rGrid[ROWS][COLS] = {
  0};
byte gGrid[ROWS][COLS] = {
  0};
byte bGrid[ROWS][COLS] = {
  0};

const byte buttonWrite[4] = {
  2, 5, 3, 4}; //Pins for the Vin of the buttons
const byte buttonRead[4] = {
  6, 7, 9, 8}; //Pins for reading the state of the buttons
boolean pressed[ROWS][COLS] = {
  0};

byte trajectory[ROWS][COLS] = {
  0};
unsigned long time;
#define PAUSE 1000

// END DEFINITIONS, BEGIN PROGRAM

char spi_transfer(volatile char data)
{
  SPDR = data;                    // Start the transmission
  while (!(SPSR & (1<<SPIF)))     // Wait the end of the transmission
  {
  };
  return SPDR;                    // return the received byte
}

byte write_pot(byte address, byte value)
{
  digitalWrite(slaveselect[slavesel(address)], LOW);
  //2 byte opcode
  spi_transfer(address % 6);
  spi_transfer(constrain(255-value,0,255));
  digitalWrite(slaveselect[slavesel(address)], HIGH); //release chip, signal end transfer
}

void setup(){
  randomSeed(1);

  byte i;
  byte clr;
  pinMode(DATAOUT, OUTPUT);
  pinMode(DATAIN, INPUT);
  pinMode(SPICLOCK,OUTPUT);
  pinMode(slaveselect[0],OUTPUT);
  pinMode(slaveselect[1],OUTPUT);

  for(byte r = 0; r < ROWS; ++r){
    pinMode(rowpin[r], OUTPUT); // Initialize rows
    digitalWrite(rowpin[r], LOW); // Turn all rows off
  }

  digitalWrite(slaveselect[0],HIGH); //disable device
  digitalWrite(slaveselect[1],HIGH);
  // SPCR = 01010000
  //interrupt disabled,spi enabled,msb 1st,master,clk low when idle,
  //sample on leading edge of clk,system clock/4 (fastest)
  SPCR = (1<<SPE)|(1<<MSTR);
  clr=SPSR;
  clr=SPDR;
  delay(10);
  // clear all of the pot registers
  for (i=0;i<12;i++)
  {
    write_pot(i,0);
  }
  //setup the button inputs and outputs
  for(int i = 0; i < ROWS; ++i){ // ???? Is ROWS

and also, this is the original thread, where i have pics up of my setup, so that could help too:

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1200846962/15

thanks in advance for any help!

thanks alot guys..... i'm just gonna use relays to switch the 2 wires from connecting... problem solved

Hi, I am having a similar problem. Is it possible for you to explain your "relay" procedure a bit more? I do not have an electrical background so I feel totally handicapped.

Thanks for your help.