SunjunKim / PMW3360

PixArt PMW3360 Motion Sensor Library for Arduino
43 stars 20 forks source link

Sensor Initialization Failed - Compatible with ESP32 ? #2

Open ImNeos opened 3 years ago

ImNeos commented 3 years ago

Hello, I am trying to use this library on a ESP32. I changed in the library the file "PWM3360.cpp" and remplaced SPI.begin() by SPI.begin(18, 19, 23, ss_pin) ; because MISO, MOSI and SCK pins aren't the same.

I tried to use the "basic_interrupt" example but I keep getting the issue "Sensor Initialization Failed". I am sure of the hardware part. I am wondering if the library is compatible with ESP32 ?

Thank you

SunjunKim commented 3 years ago

Hello, I am trying to use this library on a ESP32. I changed in the library the file "PWM3360.cpp" and remplaced SPI.begin() by SPI.begin(18, 19, 23, ss_pin) ; because MISO, MOSI and SCK pins aren't the same.

I have only tried this on ATMega32U4-based 8-bit boards. However, it's just SPI communications, so it must be compatible... in theory.

Even though I absolutely have no experience with ESP32, I may suspect some culprits, from the most suspicious to the least suspicious.

1) It seems like ESP32 needs some more code snippet to work with SPI. For example, try check the answers to the following: https://stackoverflow.com/questions/66722386/how-to-use-spi-with-esp32-and-arduino https://forum.arduino.cc/t/esp32-spi-comunication-on-sd-module/598345

2) If you're using the PMW3360 module from here, and if your module is the latest one v1.4, probably there're small jumper pads (SJ1 in here which pull-up the MISO pin. Try with the jumper connected.

3) Have you tried any different SPI speeds? #define SPI_BEGIN SPI.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE3))

A-Schmid commented 3 years ago

We use the PMW3360 with an M5Stack (which is ESP32 based) in this project and it works like a charm.

The SPI settings we use are SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE3)) (have not tested it with 8000000 yet).

mbalestrini commented 1 year ago

@SunjunKim the PMW3360 datasheet recommends a maximum Serial Port Clock Frequency of 2MHz. Is there a reason you choose 8 MHz?