# PMW3901

PMW3901 is an [optical flow]() ASIC that computes the flow internally and provides a difference in pixels between each frame. It uses a tracking sensor that is similar to what you would find in a computer mouse, but adapted to work between 80 mm and infinity. The PMW3901 is used in several products, including some from Bitcraze, Tindie, Hex, Thone, and Alientek

![Bitcraze Flow Deck](https://4155462212-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LArEa7z2SPawfl3HpCD%2Fuploads%2Fgit-blob-0ba333817a2ed1b315ece9db5963c5086903fe38%2Fbitcraze-flow.jpg?alt=media)

This topic provides links to sensors that have been tested, along with information about mounting and PX4 configuration (this is common to all sensors of this type).

## Boards using PMW3901

The following table shows some of the boards that use this sensor, listing the number of interfaces, the number of sensors, the input voltage, and the size. The board name links to board-specific sections that include wiring and purchase information.

| Manufacture | Board                                                                             | Interface | Flow | Range Finder | Gyro | Voltage (V) | Size (mm) | Max Height (m) |
| ----------- | --------------------------------------------------------------------------------- | --------- | ---- | ------------ | ---- | ----------- | --------- | -------------- |
| Bitcraze    | [Flow breakout](#bitcraze-flow-breakout)                                          | SPI       | Y    | Y            | -    | 3 - 5       | 21x20     | 1              |
| Tindie      | [PMW3901 Optical Flow Sensor](#tindie-pmw3901-optical-flow-sensor)                | SPI       | Y    | -            | -    | 3 - 5       | AxB       | -              |
| Hex         | [HereFlow PMW3901 Optical Flow Sensor](#hex-hereflow-pmw3901-optical-flow-sensor) | CAN       | Y    | Y            | Y    | 3 - 5       | AxB       | 4              |
| Holybro     | [Holybro PMW3901 Optical Flow Sensor](#holybro-pmw3901-optical-flow-sensor)       | UART      | Y    | -            | -    | 3 - 5       | AxB       | -              |
| Thone       | [ThoneFlow-3901U](#thone-thoneflow-3901u)                                         | UART      | Y    | -            | -    | 3 - 5       | AxB       | -              |
| Alientek    | [ATK-PMW3901](#alientek-atk-pmw3901)                                              | SPI       | Y    | -            | -    | 3.3 - 4.2   | 27.5x16.5 | 1              |

## External Rangefinders

An external rangefinder/distance sensor is _required_ for the sensors that don't have a rangefinder (e.g. _Tindie_ or _Thone_) and _recommended_ for the other boards (as their range is quite limited).

The range needed is dependent on the application:

* Indoor flight: ≈4 metres
* Outdoor flight: ≥10 metres (e.g. to support the position control in environments where GPS might have issues)

Any [rangefinder/distance sensor](../rangefinders) supported by PX4 may be used. The sensor can be mounted anywhere but must point down, and should be connected/configured as usual.

:::tip The PX4 team mainly tested using the [Lidar Lite V3](../rangefinders/lidar_lite) on larger vehicles and the [Lanbao CM8JL65](../rangefinders/cm8jl65_ir_distance_sensor) on smaller vehicles. :::

## Mounting/Orientation

Flow modules are typically mounted near the centre of the vehicle. If mounted off-centre you will need to set offsets: [Optical Flow > EKF2](..#ekf2).

The flow modules may be mounted with any yaw orientation relative to the vehicle body frame, but you must set the value used in [SENS\_FLOW\_ROT](../../../../advanced_config/parameter_reference#SENS_FLOW_ROT).

The "zero" rotation is when the sensor board and [vehicle](../../../../getting_started/px4_basic_concepts#heading-and-directions) X-axes are aligned (i.e. the "front" of the vehicle and the board are in the same direction), with rotations increasing in a clockwise direction.

PMW3901 modules have a small notch indicating the direction of the **back** of the board. The diagram shows the relative board and vehicle orientations that correspond to `SENS_FLOW_ROT=0` (note the notch at the back).

![PMW3901 PH4 Rotation](https://4155462212-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LArEa7z2SPawfl3HpCD%2Fuploads%2Fgit-blob-5c76aed62b760ba6b8cbb0eb814d906be0b8f464%2Fph4-pmw3901-rotation.png?alt=media)

The diagram above shows the Bitcraze board. You can use the notch to find the orientation of the other boards in the same way:

|                                                                                                                                                                                                                                                                           |                                                                                                                                                                                                                                                                                                                        |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p>Tindie<br><img src="https://4155462212-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LArEa7z2SPawfl3HpCD%2Fuploads%2Fgit-blob-c19947a3f201d6e142e318aae83b3a5e87f1bf8e%2Ftindie_notch.jpg?alt=media" alt="PMW3901 Tindie Notch"></p>            | <p>Hex Hereflow<br><img src="https://4155462212-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LArEa7z2SPawfl3HpCD%2Fuploads%2Fgit-blob-5978d49000ddab1c6c5d467da617c07725023049%2Fhex_hereflow_notch.jpg?alt=media" alt="PMW3901 Hereflow Notch"></p>                                           |
| <p>Thone<br><img src="https://4155462212-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LArEa7z2SPawfl3HpCD%2Fuploads%2Fgit-blob-06cd021dc90f574632c81d2f2e188f33bb50da97%2Fthoneflow_3901u_notch.jpg?alt=media" alt="PMW3901 Thoneflow Notch"></p> | <p>Alientek (also has an arrow indicating the front!)<br><img src="https://4155462212-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LArEa7z2SPawfl3HpCD%2Fuploads%2Fgit-blob-7cc419430f062e764d577e55d09cf28de76d5866%2Falientek_pmw3901_notch.jpg?alt=media" alt="PMW3901 Alientek Notch"></p> |

## PX4 Configuration

The PX4 configuration that is common to all PMW3901-based boards:

* [Optical Flow > EKF2](..#ekf2) explains how to fuse optical flow data in the EKF2 estimator and set position offsets for the mounting position of the flow sensor.
* [SENS\_FLOW\_ROT](../../../../advanced_config/parameter_reference#SENS_FLOW_ROT) sets the orientation of the flow sensor relative to vehicle heading.

In addition for:

* SPI-connected sensors you must set [SENS\_EN\_PMW3901](../../../../advanced_config/parameter_reference#SENS_EN_PMW3901) to `1` in order to enable the sensor driver.
* UART-connected sensors (e.g. ThoneFlow-3901UY) you must [configure the associated serial port](../../../advanced_config/serial_configuration) by setting the parameter [SENS\_TFLOW\_CFG](../../../../advanced_config/parameter_reference#SENS_TFLOW_CFG) to the value of the connected UART port (for example, if you connected this sensor to `TELEM 2`, you need to set `SENS_TFLOW_CFG` to `102`).
* DroneCAN sensors you must set `UAVCAN_ENABLE` appropriately. For more information see [DroneCAN Peripherals](../dronecan) (and the [HereFlow PMW3901 docs below](#dronecan_wiring)).

Individual flow sensors are further setup/configured as described in the sections below.

## Bitcraze Flow Breakout

The [Bitcraze Flow breakout](https://www.bitcraze.io/products/flow-breakout/) directly exposes the [SPI interface](#spi-wiring) from the PMW3901 module.

The board also incorporates a distance sensor [wired to the Pixhawk I2C port](#i2c-wiring). This distance sensor is the VL53L0x ToF sensor from STMicroelectronics. The sensor range is minimal (2 metres) and will be reduced when flying in the sunlight. We therefore highly recommend that you use an [external distance sensor](#external-rangefinders).

![Bitcraze Flow Deck](https://4155462212-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LArEa7z2SPawfl3HpCD%2Fuploads%2Fgit-blob-0ba333817a2ed1b315ece9db5963c5086903fe38%2Fbitcraze-flow.jpg?alt=media)

[PX4 configuration](#px4-configuration) and [mounting/orientation](#mounting-orientation) instructions are provided above.

### SPI Wiring

The PMW3901, if connected to the SPI port on a Pixhawk 4, will automatically detect the Bitcraze flow module. This device's driver was explicitly written to be plugged into the SPI port using the chip select 1. No parameters will have to be configured other than the [orientation and position of the sensor](#mounting-orientation).

The pinout mapping for the Pixhawk SPI port to Bitcraze Flow Board is shown below (the port mapping is the same for all Pixhawk FMU versions).

| Pixhawk SPI Port (from left to right) | Bitcraze flow board |
| ------------------------------------- | ------------------- |
| 1 (VCC)                               | VCC                 |
| 2 (SCK)                               | CLK                 |
| 3 (MISO)                              | MISO                |
| 4 (MOSI)                              | MOSI                |
| 5 (CS1)                               | Do not connect      |
| 6 (CS2)                               | CS                  |
| 7 (GND)                               | GND                 |

To connect the bitcraze flow board to the Pixhawk, you will need to solder the wires of the Pixhawk SPI cable to the flow board. An SPI cable has 7 wires, from which you need to connect 6 to the flow board.

The following diagram shows how to wire the sensor to a Pixhawk 4.

![Bitcraze PH4 Pinout](https://4155462212-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LArEa7z2SPawfl3HpCD%2Fuploads%2Fgit-blob-d1ffa063b0b812c39907a67a360b1e0fc47b7860%2Fph4-bitcraze-flow-pinout.png?alt=media)

### I2C Wiring

The I2C wiring is the same for any other distance sensor. Simply connect the SLA, SLC, GND, and VCC to the corresponding (same) pins on the Pixhawk and the sensor.

## Tindie PMW3901 Optical Flow Sensor

The Tindie [PMW3901 Optical Flow Sensor](https://www.tindie.com/products/onehorse/pmw3901-optical-flow-sensor/) exposes the SPI interface from the PMW3901 module exactly as on the Bitcraze module (see [SPI Wiring](#spi-wiring)).

![Tindie PH4 Pinout](https://4155462212-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LArEa7z2SPawfl3HpCD%2Fuploads%2Fgit-blob-f8aa732429b19358b68d29fd2e501c3c83aec61a%2Fph4-tindie-flow-pinout.png?alt=media)

The sensor doesn't have a distance sensor onboard, so you will need to use an [external distance sensor](#external-rangefinders).

[PX4 configuration](#px4-configuration) and [mounting/orientation](#mounting-orientation) instructions are provided above.

## AlienTek ATK-PMW3901

The AlienTek [ATK-PMW3901](https://www.aliexpress.com/i/32979605707.html) exposes the SPI interface from the PMW3901 module in the same way as the Bitcraze module (see [SPI Wiring](#spi-wiring)).

![Alientek Pixhawk4 Connections](https://4155462212-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LArEa7z2SPawfl3HpCD%2Fuploads%2Fgit-blob-45631cf342c7fce0c9126698369bf79595f4a4c3%2Fph4-alientek-flow-pinout.png?alt=media)

The board also incorporates a distance sensor (we recommend that you use an [external distance sensor](#external-rangefinders)). You can wire the internal sensor to the Pixhawk I2C port [in the same way as any other I2C peripheral.](#i2c-wiring) A screenshot showing the I2C pins (SLA, SLC, GND, and VCC) is provided below.

![Alientek Pinout](https://4155462212-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LArEa7z2SPawfl3HpCD%2Fuploads%2Fgit-blob-8a149eaeaf06d7361168ac2eab16fc45db65c22b%2Falientek.png?alt=media)

[PX4 configuration](#px4-configuration) and [mounting/orientation](#mounting-orientation) instructions are provided above.

## Hex HereFlow PMW3901 Optical Flow Sensor

The Hex [HereFlow PMW3901 Optical Flow Sensor](http://www.proficnc.com/all-products/185-pixhawk2-suite.html) is a tiny board containing the PMW3901 flow module, VL53L1X distance sensor, and an IMU (used to synchronize the flow data with the gyro data).

An onboard microcontroller samples the three sensors and publishes two DroneCAN messages containing all the information needed for the flow and distance sensor calculations.

The board can be connected to any CAN port on any Pixhawk board (see [DroneCAN wiring](#dronecan_wiring)).

As for the other optical flow boards, we recommend that you use an [external distance sensor](#external-rangefinders).

[PX4 configuration](#px4-configuration) and [mounting/orientation](#mounting-orientation) instructions are provided above.

### DroneCAN Wiring/Setup

The diagram below shows how to connect the sensor to the Pixhawk 4 CAN bus.

![Hex PH4 Pinout](https://4155462212-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LArEa7z2SPawfl3HpCD%2Fuploads%2Fgit-blob-14166cf7677012515b25e6c86e8338962fadfd51%2Fph4-hex-optical-flow.png?alt=media)

In addition to any other configuration, you will need to set the parameter [UAVCAN\_ENABLE](../../../../advanced_config/parameter_reference#UAVCAN_ENABLE) to either 2 or 3, depending on your system:

* `UAVCAN_ENABLE=2`: DroneCAN sensors but no motor controllers.
* `UAVCAN_ENABLE=3`: DroneCAN sensors and motor controllers.

For general information about DroneCAN wiring and configuration see: [DroneCAN Peripherals](../dronecan).

## Holybro PMW3901 Optical Flow Sensor

The [Holybro PMW3901 Optical Flow Sensor](https://holybro.com/products/pmw3901-optical-flow-sensor) exposes a PMW3901 optical flow module via a UART interface.

The board doesn't include a distance sensor onboard, so you will need to use an [external distance sensor](#external-rangefinders).

![](https://4155462212-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LArEa7z2SPawfl3HpCD%2Fuploads%2Fgit-blob-1be9ff48f713f485f17016e56ebdfc13e8515370%2Fholybro-pmw3901-1.jpg?alt=media) ![](https://4155462212-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LArEa7z2SPawfl3HpCD%2Fuploads%2Fgit-blob-47c2699d1e00b1325cd08c635f9e407d7ee87ba8%2Fholybro-pmw3901-2.jpg?alt=media)

It comes with a 3D printed case and has a pre-soldered TX, Voltage, and GND 4 pin connector that can be plugged into the telemetry port of your flight controller, as shown below (for the Pixhawk 6C).

![HB-pmw3901-3](https://4155462212-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LArEa7z2SPawfl3HpCD%2Fuploads%2Fgit-blob-b3cd481f1faebf5130c1b9a3d65daded2fb1464e%2Fholybro-pmw3901-3.png?alt=media)

## Thone ThoneFlow-3901U

The Thone [ThoneFlow-3901U](https://www.seeedstudio.com/ThoneFlow-3901U-UART-Serial-Version-PMW3901-Optical-Flow-Sensor-p-4040.html) exposes a PMW3901 optical flow module via a UART interface.

The board doesn't include a distance sensor onboard, so you will need to use an [external distance sensor](#external-rangefinders).

![PMW3901 Thoneflow Hero](https://4155462212-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LArEa7z2SPawfl3HpCD%2Fuploads%2Fgit-blob-65bb5abb7699b77dfe1a5a18dd9dcf4210aff838%2Fthoneflow_3901u_hero.jpg?alt=media)

[PX4 configuration](#px4-configuration) and [mounting/orientation](#mounting-orientation) instructions are provided above.

In addition, you must also set the parameter [SENS\_TFLOW\_CFG](../../../../advanced_config/parameter_reference#SENS_TFLOW_CFG) to the value of the UART port you connected (e.g. if the sensor is connected to `TELEM 2` then set `SENS_TFLOW_CFG=102`. For more information see [Serial Port Configuration](../../../advanced_config/serial_configuration).
