Pages: [1]   Go Down
Author Topic: Wii camera demo + digitalpot's problem continues.  (Read 1229 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It works ! kinda !!
OK, after some real head banging and coding issues I finally am getting some where, or so I thought...
Using wiimote ir camera hack and the AD5206 Digital pot to control my xbox wired controller I have hit another problem ! After being helped by a great guy with the code I find that I only get the X axis to work (ie Left /right)
the Y axis still refuses to work (up and down), I see in the serial monitor that it is functioning fine, but get nothing,
no voltage output from the digi-pot (channel 2), I have check the wiring etc , and even reolaced the digi-pot,
I have even re-wired it so that the X axis wiper wire controls  the Y axis on the xbox controller ,  it works! I have tried a different channel too, still nothing!  So I'm thinking maybe it's still a coding issue, so again here is the code I have, Am I just missing something ??? Can some one have a look  PLEASE, before I go mad !!

Code:
                                                                     
                                                                     
                                                                     
                                             

#include <Wire.h>
#include <PVision.h>
#include <SPI.h>
//Select one of the following to be 0, and the other 1
//'0': ON, '1': OFF
#define serial_display 1
#define processing_display 0

#define channelx 1
#define channely 2
PVision ircam;
byte result;


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

//MUX testing
int S0 = 5;
int S1 = 6;
void setup()
{
  Serial.begin(115200);
  ircam.init();
   // while (Serial.available() <= 0) {
     //Serial.print("AE v1.0");   // send a capital A
    // delay(300);
    //}
//SPI stuff here
   pinMode (slaveSelectPin, OUTPUT);
   SPI.begin();
}

void loop()
{
   
  result = ircam.read();
 
  if(serial_display == 1){
    if (result & BLOB1)
    {
      digpot_x = ircam.Blob1.X >> 2;
      digpot_y = ircam.Blob1.Y >> 2;
      Serial.print("BLOB1 detected. X:");
      Serial.print(digpot_x);
      Serial.print(" Y:");
      Serial.print(digpot_y);
      Serial.print(" Size:");
      Serial.println(ircam.Blob1.Size);
    }
   
    if (result & BLOB2)
    {
      Serial.print("BLOB2 detected. X:");
      Serial.print(ircam.Blob2.X >> 2);
      Serial.print(" Y:");
      Serial.print(ircam.Blob2.Y >> 2);
      Serial.print(" Size:");
      Serial.println(ircam.Blob2.Size);
    }
    if (result & BLOB3)
    {
      Serial.print("BLOB3 detected. X:");
      Serial.print(ircam.Blob3.X >> 2);
      Serial.print(" Y:");
      Serial.print(ircam.Blob3.Y >> 2);
      Serial.print(" Size:");
      Serial.println(ircam.Blob3.Size);
    }
    if (result & BLOB4)
    {
      Serial.print("BLOB4 detected. X:");
      Serial.print(ircam.Blob4.X >> 2);
      Serial.print(" Y:");
      Serial.print(ircam.Blob4.Y >> 2);
      Serial.print(" Size:");
      Serial.println(ircam.Blob4.Size);
    }
   
     digitalPotWrite (channelx,(int)digpot_x);
     digitalPotWrite (channely,(int)digpot_y);
  }//endif serial_display
 
  else if(processing_display == 1){
    if( Serial.available() > 0){
   //   print header
     uint8_t XL1 = ircam.Blob1.X & 0xFF;
     uint8_t XH1 = (ircam.Blob1.X >> 8) & 0x03;
     uint8_t YL1 = ircam.Blob1.Y & 0xFF;
     uint8_t YH1 = (ircam.Blob1.Y >> 8) & 0x03;
     uint8_t XL2 = ircam.Blob2.X & 0xFF;
     uint8_t XH2 = (ircam.Blob2.X >> 8) & 0x03;
     uint8_t YL2 = ircam.Blob2.Y & 0xFF;
     uint8_t YH2 = (ircam.Blob2.Y >> 8) & 0x03;

     
     
      Serial.write(XL1);
      Serial.write(XH1);
      Serial.write(YL1);
      Serial.write(YH1);
      Serial.write(XL2);
      Serial.write(XH2);
      Serial.write(YL2);
      Serial.write(YH2);
    }//end ifSerial.available
  }//endif processing_display
 
}//End loop()

void digitalPotWrite(int address, int value) {
   // take the SS pin low to select the chip:
   digitalWrite(slaveSelectPin,LOW);
   //  send in the address and value via SPI:
   SPI.transfer(address);
   SPI.transfer(value);
   // take the SS pin high to de-select the chip:
   digitalWrite(slaveSelectPin,HIGH);
}

 smiley-roll Thanks !!
Logged

Pages: [1]   Go Up
Jump to: