pmw3901: add driver for the PixArt PMW3901 optical flow sensor (#918) · tinygo-org/drivers@41df15a · GitHub
Skip to content

Commit 41df15a

Browse files
authored
pmw3901: add driver for the PixArt PMW3901 optical flow sensor (#918)
* pmw3901: add driver for the PixArt PMW3901 optical flow sensor Adds the driver with motion and frame capture, unit tests, examples, and smoketest entries. Tested on an M5Stamp Fly. * pmw3901: address review feedback Use encoding/binary for multi-byte fields, use the Bitcraze SPI timings, and document the wait needed after Configure before SetLED.
1 parent 2b83a45 commit 41df15a

9 files changed

Lines changed: 918 additions & 0 deletions

File tree

‎examples/pmw3901/frame/main.go‎

Lines changed: 70 additions & 0 deletions

‎examples/pmw3901/motion/main.go‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// This example uses the pins of the M5Stack StampFly with a Stamp-S3A.
2+
package main
3+
4+
import (
5+
"machine"
6+
"time"
7+
8+
"tinygo.org/x/drivers/pmw3901"
9+
)
10+
11+
const (
12+
sck = machine.GPIO44
13+
sdo = machine.GPIO14
14+
sdi = machine.GPIO43
15+
csPin = machine.GPIO12
16+
17+
// The BMI270 IMU shares the SPI bus.
18+
imuCS = machine.GPIO46
19+
)
20+
21+
var dev pmw3901.Device
22+
23+
func main() {
24+
imuCS.Configure(machine.PinConfig{Mode: machine.PinOutput})
25+
imuCS.High()
26+
27+
csPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
28+
csPin.High()
29+
machine.SPI0.Configure(machine.SPIConfig{
30+
Frequency: 2_000_000,
31+
SCK: sck,
32+
SDO: sdo,
33+
SDI: sdi,
34+
Mode: 3,
35+
})
36+
37+
dev = pmw3901.New(machine.SPI0, csPin)
38+
if err := dev.Configure(); err != nil {
39+
for {
40+
println("Error configuring device:", err.Error())
41+
time.Sleep(time.Second)
42+
}
43+
}
44+
45+
for {
46+
m, err := dev.ReadMotionBurst()
47+
if err != nil {
48+
println("Error reading motion:", err.Error())
49+
} else {
50+
println("dx:", m.DeltaX, "dy:", m.DeltaY, "squal:", m.Squal, "shutter:", m.Shutter, "valid:", m.Valid())
51+
}
52+
time.Sleep(100 * time.Millisecond)
53+
}
54+
}

‎pmw3901/LICENSE-bitcraze‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 Bitcraze
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

‎pmw3901/LICENSE-pimoroni‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 Pimoroni Ltd.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

‎pmw3901/README.md‎

Lines changed: 25 additions & 0 deletions

0 commit comments

Comments
 (0)