Reading from the registers of a PMW3901 sensor

Hello all,
I am planning to create a digital twin of the PMW3901 sensor in Arduino so that I can get some information like the present state of the sensor, which would help me to debug the sensor if there are any errors during usage. I am trying to read from the registers of the PMW3901 sensor from Bitcraze. It uses SPI to communicate with the arduino. I am new to this field of reading from the registers and I have tried reading a lot of posts on this forum but did not find any useful information till now on how I can read from the registers. Attached you will find the link to the sensor from bitcraze and the data sheet with the information about the registers.
Any help is appreciated. Thanks.

Datasheet

Sensor

[Code] In the following code I am trying to read the surface quality register (squal) but the output is just zeroes.

/* 
This is the code from the following Arduino forum: https://forum.arduino.cc/t/reading-register-values-from-spi/270224 
*/
#include <SPI.h>
#include "Bitcraze_PMW3901.h"

int SS1 = 10;


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
 
  pinMode(SS, OUTPUT);
  digitalWrite(SS, HIGH);
  Serial.begin(9600);
  Serial.println("Beginning Transmission...");
  delay(2000);
  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE0);  //Output at 0,0 clock edge for CAM204 (also Arduino Default mode)
  SPI.setClockDivider(SPI_CLOCK_DIV16);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(SS, LOW);
  SPI.transfer(0x07);   
     
  byte ByteA = SPI.transfer(0x07); 

  Serial.println(ByteA);

  digitalWrite(SS, HIGH);
}

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