Introduction

Discord Build Status Code Style: Black

CircuitPython library for the PMW3360 motion sensor. Port of Arduino PMW3360 Module Library by SunjunKim.

Tested working on KB2040 (RP2040), Adafruit Feather M4 Express (SAMD51) and Adafruit ESP32-S3 Feather with 4MB Flash 2MB PSRAM (ESP32-S3).

Dependencies

This driver depends on:

Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle or individual libraries can be installed using circup.

Installing to a Connected CircuitPython Device with Circup

Make sure that you have circup installed in your Python environment. Install it with the following command if necessary:

pip3 install circup

With circup installed and your CircuitPython device connected use the following command to install:

circup install pmw3360

Or the following command to update an existing version:

circup update

Usage Example

import PMW3360
import board
from digitalio import DigitalInOut, Direction

# board.SCK may be board.CLK depending on the board
# board.D10 is the cs pin
sensor = PMW3360.PMW3360(board.SCK, board.MOSI, board.MISO, board.D10)

# Any pin. Goes LOW if motion is detected. More reliable.
mt_pin = DigitalInOut(board.A0)
mt_pin.direction = Direction.INPUT

# Initalizes the sensor
if sensor.begin():
    print("sensor ready")
else:
    print("firmware upload failed")

# Setting and getting CPI values. Default is 800.
sensor.set_CPI(1200)
print(sensor.get_CPI())

while True:
    # Captures a snapshot
    data = sensor.read_burst()

    # uncomment if mt_pin isn't used
    # if data["is_on_surface"] == True and data["is_motion"] == True:
    if mt_pin.value == 0:
        print(data)

Documentation

API documentation for this library can be found on Read the Docs.

For information on building library documentation, please check out this guide.

Contributing

Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.

Table of Contents

Indices and tables