From 644c16bd2e548812abf4960734fe9ec6855e07dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricco=20M=C3=BCller?= <ricco.mueller@tu-braunschweig.de> Date: Thu, 11 Apr 2024 08:54:43 +0000 Subject: [PATCH] Upload New File --- Arduino Code/PMW3360_Test/PMW3360_Test.ino | 86 ++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 Arduino Code/PMW3360_Test/PMW3360_Test.ino diff --git a/Arduino Code/PMW3360_Test/PMW3360_Test.ino b/Arduino Code/PMW3360_Test/PMW3360_Test.ino new file mode 100644 index 0000000..ab00408 --- /dev/null +++ b/Arduino Code/PMW3360_Test/PMW3360_Test.ino @@ -0,0 +1,86 @@ +#include <PMW3360.h> + +/* + +# PIN CONNECTION + * MI = MISO + * MO = MOSI + * SS = Slave Select / Chip Select + * SC = SPI Clock + * MT = Motion (active low interrupt line) + * RS = Reset + * GD = Ground + * VI = Voltage in up to +5.5V + +Module Arduino + RS --- (NONE) + GD --- GND + MT --- (NONE) + SS --- Pin_10 (use this pin to initialize a PMW3360 instance) + SC --- SCK + MO --- MOSI + MI --- MISO + VI --- 5V + +# PMW3360_DATA struct format and description + - PMW3360_DATA.isMotion : bool, True if a motion is detected. + - PMW3360_DATA.isOnSurface : bool, True when a chip is on a surface + - PMW3360_DATA.dx, data.dy : integer, displacement on x/y directions. + - PMW3360_DATA.SQUAL : byte, Surface Quality register, max 0x80 + * Number of features on the surface = SQUAL * 8 + - PMW3360_DATA.rawDataSum : byte, It reports the upper byte of an 18â€bit counter + which sums all 1296 raw data in the current frame; + * Avg value = Raw_Data_Sum * 1024 / 1296 + - PMW3360_DATA.maxRawData : byte, Max/Min raw data value in current frame, max=127 + PMW3360_DATA.minRawData + - PMW3360_DATA.shutter : unsigned int, shutter is adjusted to keep the average + raw data values within normal operating ranges. + */ + +#define SS 5 // Slave Select pin. Connect this to SS on the module. + +PMW3360 sensor; + +int dx_with_negative = 0; +int dy_with_negative = 0; + +void setup() { + Serial.begin(115200); + 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() { + PMW3360_DATA data = sensor.readBurst(); + + dx_with_negative = convertTwoComplementToInt(data.dx); + dy_with_negative = convertTwoComplementToInt(data.dy); + + if(data.isOnSurface && data.isMotion) + { + Serial.print(dx_with_negative); + Serial.print("\t"); + Serial.print(dy_with_negative); + Serial.println(); + } + + delay(10); +} + +int convertTwoComplementToInt(unsigned int value) { + // Ãœberprüfen, ob das höchste Bit gesetzt ist (negative Zahl im Zweierkomplement) + if (value & 0x8000) { + // Konvertieren in int und die negativen Bits setzen + return -((~value + 1) & 0xFFFF); + } else { + // Wert ist positiv, direkte Konvertierung + return value; + } +} -- GitLab