Arduino driver for PMW3901 optical flow sensor
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples/flow Add driver code Jul 6, 2017
src Add driver code Jul 6, 2017
CONTRIBUTING.md Create CONTRIBUTING.md Oct 25, 2017
LICENSE Initial commit Jul 6, 2017
keywords.txt Add driver code Jul 6, 2017
library.properties Add driver code Jul 6, 2017
readme.md Add output interpretation section to Readme.md Aug 1, 2018

readme.md

Arduino driver for PMW3901 optical flow sensor

Arduino driver for the Pixart PMW3901 optical flow sensor. The driver is developed to support the Bitcraze Flow Breakout board. It communicates with the sensor using SPI.

Electrical connection

The library is using the standard SPI library, the sensor MOSI, MISO and SCK should be connected to the arduino according to the SPI library documentation. The CS (chip select) pin can be any digital pin (which allows to connect more than one SPI sensor to your Arduino).

Usage

Look at the flow example for basic usage.

You can create a sensor by passing the chip select pin number:

// Using digital pin 10 for chip select
Bitcraze_PMW3901 flow(10);

Initializing the sensor is done by calling begin, it returns true if the sensor is detected and initialized, false otherwise:

  if (!flow.begin()) {
    Serial.println("Initialization of the flow sensor failed");
    while(1) { }
  }

As soon as it is initialized, the sensor will start accumulating motion count. Calling the readMotionCount function allows to get the value of the motion counters and resets the counters. So each time the function is called you get the motion count since the last call:

  // Get motion count since last call
  flow.readMotionCount(&deltaX, &deltaY);

Output interpretation

The sensor outputs unitless ticks that corresponds to the amount of movement that has been observed in front of the sensor. These ticks can be converted to a distance if we know the distance to the tracked surface and we assume the tracked surface is flat.

Parameters of the PMW3901 sensor have been devised experimentally in order to implement it in the Crazyflie firmware. The measurement equation are described in Marcus Greiff's Master thesis section 6.5. The implementation is part or the Crazyflie kalman filter.