Pages: [1]   Go Down
Author Topic: ADNS5050  (Read 607 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello!  I have some  problems with ADNS5050 on Arduino atmega328 board,I  appreciate anyone who can help me out.I get some code on the internet but it  doesnot work well.Can you post your code ? I will learn it very hard .Thank you  very much!

Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24322
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I have some  problems
, but I'm not going to tell you what they are.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is my code ,Can you help me find the problem with it ?Thank you !
Code:

#include "arduino.h"
#include "Adns.h"

/******************************************************************************
 * Definitions
 ******************************************************************************/

#define SCLK                6
#define SDIO                5
#define NCS                 4

#define PRODUCT_ID          0x00
#define DELTA_Y_REG         0x03
#define DELTA_X_REG         0x04
#define SQUAL_REG           0x05
#define MAXIMUM_PIXEL_REG   0x08
#define MINIMUM_PIXEL_REG   0x0a
#define PIXEL_SUM_REG       0x09
#define PIXEL_DATA_REG      0x0b
#define SHUTTER_UPPER_REG   0x06
#define SHUTTER_LOWER_REG   0x07
#define RESET          0x3a
#define MOUSE_CONTROL2      0x19
#define RES_CPI            0x1B
#define NUM_PIXELS          361

byte pix[361];
char  dx;
char  dy;


void setup()
{
  Serial.begin(9600);
  pinMode(SDIO, OUTPUT);
  pinMode(SCLK, OUTPUT);
  pinMode(NCS, OUTPUT);
  sync();
  byte productId = ADNS_read_old(PRODUCT_ID);
 Serial.print("Found productId ");
  Serial.print(productId);

 
}


void loop()
{
 
 // Freezes DX and DY until they are read or MOTION is read again.


 
     dx = ADNS_read_old(DELTA_X_REG);
     dy = ADNS_read_old(DELTA_Y_REG);


   
   Serial.print("DELTA:");
    Serial.print( dx, DEC);
   Serial.print("    ");
    Serial.print( dy, DEC);
     Serial.print("    ");
    Serial.print('\r');
     Serial.print('\n');
  //   pixelGrab();
//    Serial.print("FRAME:");
//    for(int i = 0; i < NUM_PIXELS; i++)
//    {
//      byte p = pix;
//      if( p < 0x10 )
//        Serial.print("0");
//        Serial.print(p, HEX);
//    }
//    Serial.println();
}

//byte surfaceQuality()
//{
//  return ADNS_read_old(SQUAL_REG);
//}

void sync()
{
  pinMode(NCS, OUTPUT);
  digitalWrite(NCS, LOW);
  delayMicroseconds(2);
  digitalWrite(NCS, HIGH);
   ADNS_write_old(RESET, 0x5a);
  delay(100); // From NRESET pull high to valid motion, assuming VDD and motion is present.
   if(ADNS_read_old(PRODUCT_ID) ==  0x12)   
  {               
        ADNS_write_old(MOUSE_CONTROL2, 0x1B);

  }


}

void pixelGrab()
{
    //ADNS_write(PIXEL_DATA_REG, 0); // start reading
    //delayMicroseconds(20);
 
  int grabCount = 0;
  while( grabCount < NUM_PIXELS )
  {
    byte data = ADNS_read_old(PIXEL_DATA_REG);
    if( (data & 0x80) != 0 ) { // Data is valid
      pix[grabCount++] = data&0x7f;
    }
  }
}


void ADNS_write_old(unsigned char addr, unsigned char data) {
  char temp;
  int n;

  digitalWrite(NCS, LOW);//nADNSCS = 0; // select the chip

  temp = addr ;
  digitalWrite(SCLK, LOW);//SCK = 0;                // start clock low
  pinMode(SDIO, OUTPUT);//DATA_OUT; // set data line for output
  for (n=0; n<8; n++) {
    digitalWrite(SCLK, LOW);//SCK = 0;
    pinMode(SDIO, OUTPUT);
    delayMicroseconds(1);
    if (temp & 0x80)
      digitalWrite(SDIO, HIGH);//SDOUT = 1;
    else
      digitalWrite(SDIO, LOW);//SDOUT = 0;
    temp = (temp << 1);
    digitalWrite(SCLK, HIGH);//SCK = 1;
    delayMicroseconds(1);//delayMicroseconds(1);          // short clock pulse
  }
  temp = data;
  for (n=0; n<8; n++) {
    digitalWrite(SCLK, LOW);//SCK = 0;
    delayMicroseconds(1);
    if (temp & 0x80)
      digitalWrite(SDIO, HIGH);//SDOUT = 1;
    else
      digitalWrite(SDIO, LOW);//SDOUT = 0;
    temp = (temp << 1);
    digitalWrite(SCLK, HIGH);//SCK = 1;
    delayMicroseconds(1);          // short clock pulse
  }
  delayMicroseconds(20);
  digitalWrite(NCS, HIGH);//nADNSCS = 1; // de-select the chip
}

byte ADNS_read_old(unsigned char addr) {
  byte temp;
  int n;

  digitalWrite(NCS, LOW);//nADNSCS = 0;             // select the chip
  temp = addr;
  digitalWrite(SCLK, OUTPUT); //SCK = 0;                // start clock low
  pinMode(SDIO, OUTPUT); //DATA_OUT;                // set data line for output
  for (n=0; n<8; n++) {

    digitalWrite(SCLK, LOW);//SCK = 0;
    pinMode(SDIO, OUTPUT); //DATA_OUT;
    if (temp & 0x80) {
      digitalWrite(SDIO, HIGH);//SDOUT = 1;
    }
    else {
      digitalWrite(SDIO, LOW);//SDOUT = 0;
    }
    temp = (temp << 1);
    delayMicroseconds(1);
    digitalWrite(SCLK, HIGH); //SCK = 1;
    delayMicroseconds(1);          // short clock pulse
  }
 
  temp = 0; // This is a read, switch to input
  pinMode(SDIO, INPUT); //DATA_IN;
  for (n=0; n<8; n++) {       // read back the data
    digitalWrite(SCLK, LOW);
    if(digitalRead(SDIO)) {// got a '1'
      temp |= 0x1;
    }
    if( n != 7) temp = (temp << 1); // shift left
    digitalWrite(SCLK, HIGH);
  }
 
  digitalWrite(NCS, HIGH);// de-select the chip
  return temp;
}




Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24322
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You still haven't told us what you perceive "the problem" to be.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
You still haven't told us what you perceive "the problem" to be.
Thank you for your responses.I am not sure the application of Motion ,Squal ,Pixel_Sum,Pixel_Grab.I use ADNS5050 to location on robot.I want to get X_displacement and Y_displacement.
Code:
dx = ADNS_read_old(DELTA_X_REG); dy = ADNS_read_old(DELTA_Y_REG);
in my code ,Now but  the changes are not very noticeable.please experts to analyze why.Thanks!
Logged

Pages: [1]   Go Up
Jump to: