PyPX4Flow: A cross-platform Python package for reading from the PX4Flow optical-flow sensor

I needed an easy way to access data from the PX4Flow sensor using Python, so I wrote this little package, which you can download from github. It runs on Windows, Linux, and OS X in Python 2 and 3. As with the other Python packages I’ve written, the API is very simple. For example, this program prints the computed X and Y flow velocities from the sensor:

from px4flow import PX4Flow

class ShowFlow(PX4Flow):

    def update(self):


if __name__ == '__main__':

    sensor = ShowFlow('/dev/ttyACM0')

    while True:


As this example shows, PX4Flow is an abstract class that you subclass with a class implementing the update method. To see the other methods available, look at the documentation.

I’ve also included a program that will display the sensor data in a useful way (depicted above) and log the data to a .CSV file for Excel.


You will need:

  1. PX4Flow kit. I recommend following the Image Quality and Output instructions to make sure the sensor is working properly.
  2. The ability to program in Python
  3. The PySerial package installed on your computer. Like many people, I found it easiest to install from source.
  4. Administrator (root) privileges on your computer
  5. The PyPX4Flow repository.

Once you’ve downloaded the repositry, use a terminal (Linux or OS X) or command shell (Windows) to change to the directory where you put it, and issue the command

  python install

On Linux or OS X, you may need to issue this command as root:

  sudo python install

Then you should be able to run the program in the display folder.

Known issues

  1. Some users have reported a bug in which the display program crashes immediately with a stack trace ending in the following output:
     File "/usr/local/lib/python2.7/dist-packages/px4flow/", line 99, in unpack
        return struct.unpack(fmt, self.msg[lo:hi])[0:n]
    error: unpack requires a string argument of length 4

    So far this bug seem to occur only with versions of Python below 2.7.5, so I’ve added a branch to the repository that should work with such earlier versions. If you are running 2.7.5 or above and still experience this problem, please let me know.

  2. At startup, the display program occasionally computes and displays bogus large values for the distance traveled. This may have to do with the fact that I am not using the checksum to validate each message.

Copyright and licensing

Copyright and licensing information (Gnu LGPL) can be found in the header of each source file.


This work was supported in part by a Commonwealth Research Commercialization Fund grant from the Center for Innovative Technology (CRCF #MF14F-011-MS) and a Lenfest summer research grant from Washington and Lee University.