How to read data from an SPI device

Google wasn't much help -- often someone has already written a library for common SPI devices. The data sheet does describe each of the registers that can be read or written with SPI, but not what the exact values are in the registers, nor the order of register access that might be required. maybe someone at pixart can provide you more details.

if you've never written a sketch to utilize a SPI device you might bring up the Arduino/Teensy IDE and look at Examples > SPI > BarometricPressureSensor. That sketch shows how to read and write the registers on that sensor. And you need to wire up 3.3v and grnd, plus the 4 SPI pins (MOSI,MISO,CLK,CS). sparkfun.com and adafruit.com have tutorials for various SPI devices, showing how to wire-up and program those devices.

good luck
 
Yes, i was trying use someother example to kinda find my way to the data on the chip but i couldn't. Is there a way to call up all the registers like a "*.*" ?
I did email them at pixart to see if i can get some sample code.
 
Alright so after a lot of work i was able to get the device to give me a 0-255 reading through serial print. Where do you suggest going from there?
 
Hi,

ben10teensy can you please share code with me ? I' trying to make PAJ7025R3 (newer version of PAJ7025) but still not successful.
 
That depends on the sensor.

But with many SPI chips, this is normal to see them power up in active mode. Many only go into a very low power mode if specifically told to do so. Some use a command over the SPI, but also very common is a dedicated pin to put the chip into a deep power-down mode.
 
Hey guys
So ive just bought a new teensy 3.2
I was looking over the spi.transfer
And I need to read from a register
As i look over the documentation on spi
It says it writes and also reads at the same time.
But if i send a dummy number to initiate
How do i know its going to the right registry
And its reading from the right reg?
 
Its not a device that has a written library
So im trying to get the basic transaction
To send it settings and also know how to recieve
Data
 
Reading data is based upon how better your sensors are working. And with the help of sample coded you can read the data. Following syntax and description make you to do this.
 
I didn't really understand your answer. let me clarify my question:
I would like to know if anyone have managed to work with the sensor PAJ7025R2. and if so can he share a sample code
thanks
 
I didn't really understand your answer. let me clarify my question:
I would like to know if anyone have managed to work with the sensor PAJ7025R2. and if so can he share a sample code
thanks

if you have a device, maybe you can post the register descriptions of the sensor, and communication protocol, so we can help.
The Pixart.com provided documentation is completely useless.
 
I have uploaded a data sheet i found with the register data. im New to using SPI communication so i dont really know how to use it
rigister bank.PNGrigister bank2.PNG

I hope this provide some information
 
In the data sheet, there should, besides of the register reference, be a description how and which reading commands would have to be sent to the chip over SPI to get the register content back. But...

...as far as I could find out with the help of Mrs Google, these technical details seem to be closed source by Pixar Inc and nowhere published on the www. Thus, you'll probably have to look for a different sensor model.

Edit: Here is something which could be helpful for you: http://www.stephenhobley.com/blog/2...rary-for-arduino/comment-page-1/#comment-4173
 
Last edited:
Necroing a thread here, I wrote a driver for this fantastic little chip but it's in no shape to be released and needs a TON of cleanup and optimization work done on it. Above posters were correct in saying that the datasheets are NDA locked, it's a bit of a pain to get them to even talk to you and sign the NDA but look deep enough on the net and you'll find prior generations (under a different part number) datasheets out there. I did get permission from PXI to release an open source driver for it but I'm gonna hold on that until I can get it into a standard arduino compatible library format.
 
Driver for PAJ7025R3

Necroing a thread here, I wrote a driver for this fantastic little chip but it's in no shape to be released and needs a TON of cleanup and optimization work done on it. Above posters were correct in saying that the datasheets are NDA locked, it's a bit of a pain to get them to even talk to you and sign the NDA but look deep enough on the net and you'll find prior generations (under a different part number) datasheets out there. I did get permission from PXI to release an open source driver for it but I'm gonna hold on that until I can get it into a standard arduino compatible library format.

I have a working Driver for the PAJ7025R3 (Pixart). If anyone can write a library for this little IR camera, it would be appreciated. I have beeb working on tracking two colliding objects.

Code:
 /* WORKS !!!!!!!
   PixArt_7025R3_IR_Sensor Modified driver from PixArt into Arduino sketch. 
  */
  #include <SPI.h>
   #include <i2c_t3.h>
  const int slaveSelectPin = 10;
  
  #define FEATURE_BANK      0x0a
  #define FEATURE_SIZE_PER_OBJ  9
  #define TRACKING_OBJ_NUM    1 //16
  #define TOTAL_FEATURE_SIZE    FEATURE_SIZE_PER_OBJ * TRACKING_OBJ_NUM
  
  struct MOT_Data 
  {
    uint16_t   size2 ;
    uint16_t  center_x;
    uint16_t  center_y;
    uint8_t   avg_brightness;
    uint8_t   max_brightness;
    uint8_t   radius;
    uint8_t   range;
  
  };
  
  struct MOT_Data mot_data[TRACKING_OBJ_NUM];
  
  void spi_read_reg(uint8_t start_addr, uint8_t *data_buf, uint8_t length2);
  void spi_write_reg(uint8_t start_addr, uint8_t *data_buf, uint8_t length2);
  
  void chk_mot_pid(void);
  void init_mot(void);
  void get_mot_feature(void);
  
  void chk_mot_pid(void)
  {   
    uint8_t  tmp_data[2];
    uint8_t  bank = 0;
   
    spi_write_reg(0xef, &bank, 1); // switch to bank0
    // Serial.println(" INSIDE spi_write_reg ");
    spi_read_reg(0x02, tmp_data, 2);  // read pid
  
    if(((tmp_data[1] << 8) + tmp_data[0]) != 0x7025)
      // dbg_printf("Check MOT PID.....Fail\r\n");
      Serial.print("Check MOT PID.....Fail\r\n");
    else
      Serial.print("Check MOT PID.....PASS\r\n");
  }
  
  void init_mot(void)  
  {
    //Serial.println(" INSIDE init_mot(void)  ");
    uint8_t  bank;
    uint8_t  tmp_data;
    
    bank = 0x00;
    spi_write_reg(0xef, &bank, 1);     //Switching RegBank to Bank0
  
    tmp_data = 0x00;
    spi_write_reg(0xdc, &tmp_data, 1); //internal_system_control_disable
  
    tmp_data = 0x04;
    spi_write_reg(0xfb, &tmp_data, 1); //[2]LEDDAC disable
  
    tmp_data = 0x05;
    spi_write_reg(0x2f, &tmp_data, 1); //sensor_on 
    
    tmp_data = 0x00;
    spi_write_reg(0x30, &tmp_data, 1); //Manual_PowerControl_Update_Req
  
    tmp_data = 0x01;
    spi_write_reg(0x30, &tmp_data, 1); //Manual_PowerControl_Update_Req
    
    tmp_data = 0x00;
    spi_write_reg(0x1f, &tmp_data, 1); //freerun_irtx_disable
  
    bank = 0x01;
    spi_write_reg(0xef, &bank, 1);     //Switching RegBank to Bank1
  
    tmp_data = 0x00;
    spi_write_reg(0x2d, &tmp_data, 1); //V flip
  
    bank = 0x0c;
    spi_write_reg(0xef, &bank, 1);     //Switching RegBank to Bank12
  
    tmp_data = 0x00;
    spi_write_reg(0x64, &tmp_data, 1); //G0 mode setting
    tmp_data = 0x00;
    spi_write_reg(0x65, &tmp_data, 1); //G1 mode setting
    tmp_data = 0x00;
    spi_write_reg(0x66, &tmp_data, 1); //G2 mode setting
    tmp_data = 0x00;
    spi_write_reg(0x67, &tmp_data, 1); //G3 mode setting
    tmp_data = 0x00;
    spi_write_reg(0x68, &tmp_data, 1); //G4 mode setting
    tmp_data = 0x00;
    spi_write_reg(0x69, &tmp_data, 1); //G5 mode setting
    tmp_data = 0x00;
    spi_write_reg(0x6a, &tmp_data, 1); //G6 mode setting
    tmp_data = 0x00;
    spi_write_reg(0x6b, &tmp_data, 1); //G7 mode setting
    tmp_data = 0x00;
    spi_write_reg(0x6c, &tmp_data, 1); //G8 mode setting
    tmp_data = 0x00;
    spi_write_reg(0x71, &tmp_data, 1); //G13 mode setting
    tmp_data = 0x00;
    spi_write_reg(0x72, &tmp_data, 1); //G14 mode setting
    tmp_data = 0x00;
    spi_write_reg(0x12, &tmp_data, 1); //keyscan disable
    tmp_data = 0x00;
    spi_write_reg(0x13, &tmp_data, 1); //keyscan disable
    bank = 0x00;
    spi_write_reg(0xef, &bank, 1);     //Switching RegBank to Bank0
    tmp_data = 0x01;
    spi_write_reg(0x01, &tmp_data, 1); //update flag enable
   /*
     // ******* DEFAULT RESOLUTION 2940 X 2940 ********************  
    bank = 0x0c;
    spi_write_reg(0xef, &bank, 1);     //Switching RegBank to Bank12
    tmp_data = 0x10;
    spi_write_reg(0x0b, &tmp_data, 1); //golbal = 16
    tmp_data = 0x00;
    spi_write_reg(0x0c, &tmp_data, 1); //ggh=0 total gain=2x
    tmp_data = 0x00;
    spi_write_reg(0x0f, &tmp_data, 1);//Texp=8192
    tmp_data = 0x20;
    spi_write_reg(0x10, &tmp_data, 1);//Texp=8192
    tmp_data = 0x00;
    spi_write_reg(0x46, &tmp_data, 1);//oalb
    tmp_data = 0x6e;
    spi_write_reg(0x47, &tmp_data, 1);//Yth = 110
   */
  //----- Modified Code Below to change "Resolution " parameters  
   // *********** resolution 4095 X 4095 **************************
    tmp_data = 0x00;
    spi_write_reg(0xef, &tmp_data, 1); //change Bank 0
   
    tmp_data = 0x0c;
    spi_write_reg(0xef, &tmp_data, 1);// Change to Bank 1
    
    tmp_data = 0xFF;
    spi_write_reg(0x60, &tmp_data, 1); // Set 0x60 to first x value
    
    tmp_data = 0x0F;
    spi_write_reg(0x61, &tmp_data, 1);// Set 0x61 to 2nd x value
    
    tmp_data = 0x0F;
    spi_write_reg(0x62, &tmp_data, 1); // Set 0x62 to 2nd y value
    
    tmp_data = 0xFF;
    spi_write_reg(0x63, &tmp_data, 1);  // Set 0x63 to 2nd y value
  // --------------------------------
  //--------- Must keep following at end:--------  
    bank = 0x01;
    spi_write_reg(0xef, &bank, 1);     //Switching RegBank to Bank1
   
    tmp_data = 0x01;
    spi_write_reg(0x01, &tmp_data, 1); //update flag enable
  }
  
  void get_mot_feature(void)
  {
    // Serial.println("  INSIDE  get_mot_feature(void) ");
    uint8_t index = 0;
    uint8_t bank = FEATURE_BANK ;
    uint8_t feature_data[TOTAL_FEATURE_SIZE] = {0};
  
    spi_write_reg(0xef, &bank, 1); // switch to bank10 // feature bank
    spi_read_reg(0x00, feature_data, TOTAL_FEATURE_SIZE);   //í@
  
    for(int i = 0; i < TRACKING_OBJ_NUM; i++)
      {
        index = i * FEATURE_SIZE_PER_OBJ ; 
        mot_data[i].size2 = feature_data[index] + (feature_data[index + 1] << 8);
        mot_data[i].center_x = feature_data[index + 2] + ((feature_data[index + 3] & 0x0F) << 8);
        mot_data[i].center_y = feature_data[index + 4] + ((feature_data[index + 5] & 0x0F) << 8);
        mot_data[i].avg_brightness = feature_data[index + 6];
        mot_data[i].max_brightness = feature_data[index + 7];
        mot_data[i].radius = (feature_data[index + 8] & 0x0F);
        mot_data[i].range = (feature_data[index + 8] >> 4);   
      
        Serial.print(mot_data[i].center_x);
        Serial.print(" " );
        Serial.println(  mot_data[i].center_y);
       // Serial.print("   " );
        
        
      // Serial.print( map (mot_data[i].avg_brightness,0,255,0,4096));
      // Serial.print("    " );
       // Serial.print( mot_data[i].avg_brightness);
       // Serial.print("    " );
       // Serial.print( mot_data[i].max_brightness);
       // Serial.print("   " ); 
         
        //delay(5);
      }
      //Serial.println();
  }
  void setup()
  {
    Serial.begin(115200);
    pinMode(slaveSelectPin, OUTPUT);  // Chip select
    digitalWrite(slaveSelectPin, HIGH);  // send data to slave
   //Serial.println("  INSIDE SETUP ");
    SPI.begin(); //  initialize the SPI hardware.
    chk_mot_pid() ;
    init_mot();  
  }
  
  void loop()
  { 
    get_mot_feature();        
   delay(2); // sleep 5 msec
    // Serial.println("  ITS WORKING ");     
  }
  
  void SpiCSHigh()
  {
    //DrvGPIOOutput(1,1,1) ;  // 7025_CS
    digitalWrite(slaveSelectPin, HIGH);
    // Serial.println(" Inside slaveSelectPin HIGH   ");
  }
  void SpiCSLow()
  {   
    // DrvGPIOOutput(1,1,0) ;  // 7025_CS  
    digitalWrite(slaveSelectPin, LOW); 
    //Serial.println(" Inside slaveSelectPin LOW   ");
  }
  
  void spi_read_reg(uint8_t u8Addr, uint8_t *u8Data , uint8_t u8Len)
  {
    //Serial.println("INSIDE  spi_read_reg");
    uint8_t  cmd = 0x80 ;  // read 
    uint8_t  i = 0 ;
    if(u8Len > 1)
      cmd |= 0x01 ;   // multi
  
    SPI.beginTransaction(SPISettings(4000000, LSBFIRST, SPI_MODE3));
    SpiCSLow();
  
    SPI.transfer(cmd);
    SPI.transfer(u8Addr);
    SPI.transfer(u8Data, u8Len);
  
    SpiCSHigh();
    SPI.endTransaction();
  }
  
  void spi_write_reg(uint8_t u8Addr, uint8_t *u8Data , uint8_t u8Len)
  {
    //Serial.println(" InSide SPI_WRITE   ");
    //Serial.println(u8Len);
    uint8_t  cmd = 0x00 ;  // write 
    uint8_t    i = 0 ;
    if(u8Len > 1)
      cmd |= 0x01;
  
    SPI.beginTransaction(SPISettings(4000000, LSBFIRST, SPI_MODE3));
    SpiCSLow();
  
    SPI.transfer(cmd);      
    SPI.transfer(u8Addr);   
  
    for(i = 0 ; i < u8Len ; i++) {
      SPI.transfer(u8Data[i]);  
    }
  
    SpiCSHigh();
    SPI.endTransaction();
  }
 
Last edited by a moderator:
Necroing a thread here, I wrote a driver for this fantastic little chip but it's in no shape to be released and needs a TON of cleanup and optimization work done on it. Above posters were correct in saying that the datasheets are NDA locked, it's a bit of a pain to get them to even talk to you and sign the NDA but look deep enough on the net and you'll find prior generations (under a different part number) datasheets out there. I did get permission from PXI to release an open source driver for it but I'm gonna hold on that until I can get it into a standard arduino compatible library format.

Any luck getting this driver spruced up for open source release?
 
Back
Top