I wanted an optical sensor which will give me X,Y positions for indoor moving cart. the cart is at the same level so the position from the floor will always be the same. I have Arduino Uno, with it I bought this sensor cjmcu 3901 (based on pmw3901 sensor) from AliExpress
the sensor came with small lens. i remove the tape on the optical eye and attached the lens to it.
I connect it according to te SPI and seems that the connections are fine but the output data is not correct. the sensor output delta x & y from the last read, and when i move the cart slowly , i always get delta x & y = 0.
i tried diffferent surfaces but still no change. i got changes in the delta x & y when i put some colorful surface(like magazine cover) and move it quickly. maybe this sensor is not quite good? i know that it's range limitations is from 8cm to infinity. what am i doing wrong?
i used the simple code below to get the data:
#include "PMW3901.h"
// Using digital pin 10 for chip select
PMW3901 flow(10);
void setup() {
Serial.begin(9600);
if (!flow.begin()) {
Serial.println("Initialization of the flow sensor failed");
while(1) { }
}
}
int16_t deltaX,deltaY;
void loop() {
// Get motion count since last call
flow.readMotionCount(&deltaX, &deltaY);
Serial.print("X: ");
Serial.print(deltaX);
Serial.print(", Y: ");
Serial.print(deltaY);
Serial.print("\n");
delay(100);
}