Hello everybody!
I am currently trying to connect four Bitcraze PMW3901 sensors to an Arduino NANO, but I seem to have issues with the SPI. When I connect two sensors using the code below, it works perfectly: I am able to retrieve the X and Y data from the serial port for both sensors.
include "Bitcraze_PMW3901.h"
Bitcraze_PMW3901 flow(10);
Bitcraze_PMW3901 flow2(9);
void setup() {
Serial.begin(9600);
if (!flow.begin()) {
Serial.println("Initialization of the flow sensor 1 failed");
while(1) { }
}
if (!flow2.begin()) {
Serial.println("Initialization of the flow sensor 2 failed");
while(1) { }
}
}
int i =0;
int16_t deltaX,deltaY;
int16_t deltaX2,deltaY2;
void loop() {
if ((i % 2) == 0) {
digitalWrite(10, LOW); // sets the digital pin 10 on
flow.readMotionCount(&deltaX, &deltaY);
digitalWrite(10, HIGH); // sets the digital pin 9 off
}
if ((i % 2) == 1) {
digitalWrite(9, LOW); // sets the digital pin 10 on
flow2.readMotionCount(&deltaX2, &deltaY2);
digitalWrite(9, HIGH); // sets the digital pin 9 off
}
i = i + 1;
Serial.print("X1:");
Serial.print(deltaX);
Serial.print("\t");
Serial.print("Y1:");
Serial.print(deltaY);
Serial.print("\t");
Serial.print("X2: ");
Serial.print(deltaX2);
Serial.print("\t");
Serial.print("Y2:");
Serial.print(deltaY2);
Serial.print("\n");
}
However, when I try to add a third Bitcraze PMW3901 sensor I cannot seem to be able to initilize it. Still, I declare a separete SS as
Bitcraze_PMW3901 flow3(6);
and add the initialization code in the setup() function as follows
if (!flow3.begin()) {
Serial.println("Initialization of the flow sensor 3 failed");
while(1) { }
}
What I get is the sentence "Initialization of the flow sensor 3 failed" or "Initialization of the flow sensor 1 failed" (it depends and I don't really understand why, since the code is always the same) printed on the serial port window.
I have already checked my sensors: they all work separetely and two-by-two. Do you have any suggestions? I hope I have managed to explain the problem clearly, otherwise please let me know if I can add or specify something more. Thank you in advance for your help!