inav icon indicating copy to clipboard operation
inav copied to clipboard

How to configure and use an SPI optical flow sensor in INAV firmware?

Open surongfengSRF opened this issue 1 month ago • 4 comments

Due to an oversight at work, I purchased a batch of PMW3901 optical flow sensors with SPI interface first. However, when attempting to use them, I found that INAV only supports optical flow sensors with UART/serial interface. Could I still continue using these SPI PMW3901 sensors in this case? If yes, how should I proceed? My INAV compilation environment is on Ubuntu 20.04, and the INAV version is 7.1.2.

surongfengSRF avatar Nov 25 '25 16:11 surongfengSRF

You mentioned "compilation environment". Which sounds like you're familiar with compiling INAV, which suggests you've edited the code before.

You can see how the optic flow sensor is read over the uart. In comparing the airspeed sensor, you can see how a given type of sensor can be used with either uart or I2C.

So you have an example of how to read a sensor over I2C. And an example of how to read the optic flow sensor.

In your shoes, I would take a look at the airspeed sensor or another I2C sensor, then let us know where you get stuck.

sensei-hacker avatar Nov 26 '25 13:11 sensei-hacker

Thanks so much for your advice—it’s really helpful. Yes, I’ve used PX4 before, and now I’m trying to build an INAV flight controller. But I made a pretty big mistake: my optical flow sensor doesn’t have the I2C interface exposed. When I bought it, I only focused on SPI’s faster transmission speed. Thanks again for your advice—I’ll dive deeper into INAV before moving on to the next step.

surongfengSRF avatar Nov 26 '25 15:11 surongfengSRF

You had written SPI and I read I2C. Does your flight controller hardware expose the SPI in a way you can get to it?

sensei-hacker avatar Nov 26 '25 16:11 sensei-hacker

If you have access to the SPI on your FC, here's a very rough idea of what might be needed to get it working:

https://github.com/iNavFlight/inav/compare/master...sensei-hacker:inav_unofficial_targets:add-pmw3901-opflow-sensor

I do not have the hardware to test and I haven't even read the datasheet - that's raw from my AI that understands INAV somewhat.

sensei-hacker avatar Nov 26 '25 16:11 sensei-hacker