Simple test

Ensure your device works with this simple test.

examples/pmw3360_simpletest.py
 1# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
 2# SPDX-FileCopyrightText: Copyright (c) 2023 Jerico Tenmatay
 3#
 4# SPDX-License-Identifier: Unlicense
 5
 6import board
 7import PMW3360
 8from digitalio import DigitalInOut, Direction
 9
10# board.SCK may be board.CLK depending on the board
11# board.D10 is the cs pin
12sensor = PMW3360.PMW3360(board.SCK, board.MOSI, board.MISO, board.D10)
13
14# Any pin. Goes LOW if motion is detected. More reliable.
15mt_pin = DigitalInOut(board.A0)
16mt_pin.direction = Direction.INPUT
17
18# Initalizes the sensor
19if sensor.begin():
20    print("sensor ready")
21else:
22    print("firmware upload failed")
23
24# Setting and getting CPI values. Default is 800.
25sensor.set_CPI(1200)
26print(sensor.get_CPI())
27
28while True:
29    # Captures a snapshot
30    data = sensor.read_burst()
31
32    # uncomment if mt_pin isn't used
33    # if data["is_on_surface"] == True and data["is_motion"] == True:
34    if mt_pin.value == 0:
35        print(data)

Mouse test

HID mouse sample