Need help with Pimoroni PMW3901 Optical Flow Sensor


I am using “Pimoroni PMW3901 Optical Flow Sensor” with Arduino Uno, and I am trying to find an Arduino library that can help me get the readings from this sensor. The only library I found so far is a Python library for the usage of this sensor with Raspberry PI. I have also found “Bitcraze PMW3901” arduino library but “Bitcraze PMW3901” sensor has a different pinout compared to “Pimoroni PMW3901” so I am not sure if it will be alright to use this library with my sensor.



The Bitcraze PMW3901 board has a VL53LOX chip which the Pimoroni PMW3901 does not. This chip has a I2C (SDA/SCL) interface. Hence the extra pins. As far as I can tell the Arduino library for the Bitcraze only accesses the PMW3901 chip via the SPI interface. There are many other libraries for the VL53LOX chip.

MOTION pin on the Bitcraze is the same as the INT on the Pimoroni.
You can ignore INT as it would only be used if you wanted an interrupt driven setup.

The flow example in the library uses Arduino pin 10 for CS and does not use INT.
The SCK, MOSI, MISO would connect to the normal SPI interface of the Arduino.
3-5V GND to the appropriate Ardunio power pins etc.

I think the Arduino library should work from my investigation. But without actually testing the device I cannot say for sure.



EDIT: Primoroni make good products but their documentation and technical support is sometimes lacking. They did send me a replacement for a low cost item that did not work correctly without returning the broken item and at no cost to me.


Thank you for your reply. I was wondering also about the camera focal length. I observed that the sensor measures change in the X/Y when a surface at a distance around 8 cm moves beneath it; however, as the distance of the moving surface from the sensor increases, the sensor becomes less sensitive to the surface motion. I want to use the sensor on a drone to help me control the drone’s position indoor at height of about 1.5-2.5m. At these distances the sensor does not give me displacement readings. Any clue, how to correct the focal length as the height changes?



From my investigation of drones, various systems and sensors are used to determine position and height. One I looked at used a video camera to take a picture of what was below and then adjusted height and position to keep it the same. A kind of hover mode. But that would take a bit of processing power. The drone was not cheap.

The PMW3901 is designed to detect fluid flow from a few cms away; the camera on it is very low res and cheap. Raspberry Pi Cameras use a system where you can rotate the lens to adjust the focus, It is quite difficult to operate and get right. This would be an option but add weight and power usage and require some sophisticated processing.

To detect movement of the drone you could use an accelerometer, but it would not guarantee to keep it at the same position most likely the drone would drift. Drones that can keep their position and height pretty accurately would have a complex sensor system to do this and they are not cheap.

The PMW3901 is not the right sensor for what you want to do, IMHO.

The accelerometer method might be a start, they are cheap enough.
PiicoDev Motion Sensor MPU-6050 $7.90.

Other than that a reasonable resolution camera (wide angle maybe). Depending on drone capabilities and processing power.



Hi All
Just having a quick read.
What about a radio or laser system. I think they are called Time Of Flight measurements and usually measure distance horizontally but I don’t see any reason they can’t look straight down. Similar operation to an aircraft radio altimeter which gives the pilot the distance above ground as against an aneroid device which is distance above sea level. I don’t know anything about the devices for Arduino or RPi but there was some activity on this forum on this subject some time ago. You might find it with some search filtering.
Cheers Bob


Add on to above.
Search “TOF” on Core web site. 25 Items and probably lots of info and tutorials built in. I haven’t looked in detail.
Cheers Bob


Thank you for your reply. I have tried before using the accelerometer readings to get the position. This method requires double integration to the accleration values. I found that, according to my knowledge, this method is not reliable at all and you will find a big drift in the position values after a short period of time especially if you are operating at high sample rate (50~100Hz). What drew my attention to the PMW3901 sensor is its discription written on the core electronics website which says and I quote “A great use for it is detecting and correcting for drift of a drone by looking for x/y motion of the ground below.” I am trying to know how?!


Reading further, the datasheet specifies 80mm to infinity and mentions use in drones. So I am wrong in thinking it is not designed for that function, apologies. The datasheet also states no focus required during lens mounting.

The lens has small notches around the edge and small glue slots, as mentioned on the datasheet. Unsure if this is intended as a focus adjustment. Pimoroni may have set this when they made the board, because they specifically say flow sensor. But they also say it can be used for drones.
You could try rotating the lens, but that may damage the device and may not be what is intended.

I bought a wide angle Pi lens that was out of focus and had used way too much glue. In trying to adjust the lens I felt like I would break it. Removing some of the glue eventually I got it to focus.

The datasheet is poor in describing how to use the data from the device, good in physical design though. Annoying when manufactures don’t provide adequate specs.

Sorry I cannot offer more.
This device I might put on my next order, just to play with, it would be useful for a small drone I have that has no stability sensors.



Pixart Imaging Inc manufacture the chip. The only technical support on their web site is to email them.

Comments in the Python script indicate they have propriety information to program the registers in the chip and do not provide details as to what the registers do. If this information was provided (like most chip makers do) then maybe it could be altered to suit your purpose.

This kind of attitude by a suppliers means their products will be used less. It is beyond me why they do this. Anyway suggest emailing and seeing what you get back if anything. Probably they ignore hobbyist users.

From the Python Library Class.

class PAA5100(PMW3901):
    def _secret_sauce(self):
        """Write the secret sauce registers for the PAA5100.
        Don't ask what these do, we'd have to make you walk the plank.
        These are some proprietary calibration magic.
        I hate this as much as you do, dear reader.



@Mohamed158863 The thought occurred to me to compare the proprietary registers and values between the examples I found on GitHub. I looked at pimoroni/ pmw3901-python, simondlevy/ PMW3901, bitcraze/ Bitcraze_PMW3901 and braincore/ pmw3901-rs.

The registers are all the same but the Primoroni Python code has 4 different values against 4 registers in the sequence. The other 3 all have the same values. Without knowing what the registers do and what each sequence does it is hard to say if it means anything.

You could try the different values and see it it makes any difference.
As Pimoroni is the manufacturer of the board you would hope their Python code has the correct values.

Anyway, all the best.