Skip to content
Snippets Groups Projects
Commit 644c16bd authored by Ricco Müller's avatar Ricco Müller
Browse files

Upload New File

parent 6049dd7a
No related branches found
No related tags found
No related merge requests found
#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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment