I’m trying to use the following PMW3389 mouse sensor library with xiao seeed nrf52840, but initialization fails.
It doesn’t seem to recognize SS pin 7, what’s the problem?
#include <PMW3389.h>
#define SS 7 // Slave Select pin. Connect this to SS on the module.
PMW3389 sensor;
void setup() {
Serial.begin(9600);
while(!Serial);
//sensor.begin(10, 1600); // to set CPI (Count per Inch), pass it as the second parameter
if(sensor.begin(SS)) // 10 is the pin connected to SS of the module.
Serial.println("Sensor initialization successed");
else
Serial.println("Sensor initialization failed");
//sensor.setCPI(1600); // or, you can set CPI later by calling setCPI();
}
void loop() {
PMW3389_DATA data = sensor.readBurst();
if(data.isOnSurface && data.isMotion)
{
Serial.print(data.dx);
Serial.print("\t");
Serial.print(data.dy);
Serial.println();
}
delay(10);
}
Verify that the SS pin is working as expected. Write a simple test script to toggle pin 7 and check the output with an LED or multimeter:
void setup() {
pinMode(7, OUTPUT);
while (1) {
digitalWrite(7, HIGH);
delay(500);
digitalWrite(7, LOW);
delay(500);
}
}
void loop() {}
If the pin does not toggle, it indicates an issue with the pin setup.
1 Like
HI there,
If I may, I would ask which BSP are you using ?
I don’t see in your code the PIN_MODE ? for pin 7 which by default is the RX pin for the Serial1 interface, unless set otherwise AFAIK
may need to use the Port number name instead. Try that also.
Why just “7” not “D7” ? some BSP’s & LIB’s use the “D” in a macro to discern A or D fyi
also as @liaifat85 suggest I often just print out what the system thinks it is for “SS”
first , usually it’s not.
HTH
GL PJ
2 Likes
It looks like you are supplying 5V to the PMW3389 board, but from the picture it does not appear to have a level shifter on board. Can you provide a link to the board you are using?
1 Like
This is the board I’m using.
thank you for your reply!
The BSP used is Seeed nRF52 Boards.
Even when I specified D7, there was no change…
xiao seeed Does the nrf52840 have a default SS pin?
The 5V supply seems to work fine, but I have a few additional questions.
- is it correct that the link is PMW3360 and not PMW3389?
- The MOTION pin is connected to GND, what is its function?
- The overall soldering is not clean, have you checked the connections?
- Does <PMW3389.h> support nRF52840?
- Where did you get <PMW3389.h>?
- Have you tried “pinMode(D7, OUTPUT);”?