Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Schwimmwinkelsensor MA
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ricco Müller
Schwimmwinkelsensor MA
Commits
644c16bd
Commit
644c16bd
authored
11 months ago
by
Ricco Müller
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
6049dd7a
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Arduino Code/PMW3360_Test/PMW3360_Test.ino
+86
-0
86 additions, 0 deletions
Arduino Code/PMW3360_Test/PMW3360_Test.ino
with
86 additions
and
0 deletions
Arduino Code/PMW3360_Test/PMW3360_Test.ino
0 → 100644
+
86
−
0
View file @
644c16bd
#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
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment