Skip to content

ArsenioDev/Bitcraze_PMW3901

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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);

Alternatively, to use the framebuffer system to use it as a camera of sorts you will need to do a bit more. After the begin function, call the enableFrameBuffer function to switch modes, then in your loop call readFrameBuffer while passing it a 35*35 array to dump pixels into.

  // Get pixels from framebuffer into an array
  flow.readFrameBuffer(int *FBuffer);

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.

About

Arduino driver for PMW3901 optical flow sensor

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 100.0%