Matek 3901-L0X Setup Help - No Data and Bad OptFlow Health Message

Hello, this is my first post on this forum so hopefully, I am doing this correctly. I am struggling to set up my Matek optical flow sensor on my drone. I am receiving a “Bad OptFlow Health” message and not receiving any data on opt_m_x or y.

I have the Optical Flow sensor hooked up to my UART port and have the following settings configured:
SERIAL2_PROTOCOL = 32 (I have 1-4 configured like this)
Baud = 115

These settings are per

I am not sure how I can further troubleshoot this issue, I have been sifting through forums and it doesn’t seem like I am missing anything except this Matek Optiflow &Lidar Sensor 3901 LOX - #5 by rickyg32

Sifting through the forums, it IS possible to hook this up with ArduPilot. I am using Mission Planner.

I uploaded some images to show you my configuration. I have TX of the sensor hooked up to RX of UART (BLUE) and RX of sensor hooked up to TX of UART (WHITE):

Let me know if you need anything additional to help me through this, thanks again!

If anyone has any ideas please let me know! :grimacing:

I have such a sensor and it does not show me any such problems. In your case, It might be a calibration issue or an issue with parameters.

(Everything below is kind of a blind guess, and probably you have done most of it already. If possible, please share your dataflash log, so that the advice can be better.)

(This is for the rangefinder part of the sensor, but just in case…)
Please make sure you have something like this:
in your parameters, as well as something valid for RNGFND1_GNDCLEAR. This sensor does not provide valid data for distances greater than 2 meters. It also shall have a clearance of at least 2 cm to the ground when initializing.

I also think that you need to leave only the actually used serial with protocol 32. So far I have no idea what AP thinks if there is protocol 32 set for a serial and there is nothing connected.

It also may be that you set everything to depend on optical flow without calibrating it first. There are FLOW_FXSCALER and FLOW_FYSCALER variables which need to be set up. Without them, I believe, the optical data is quite inconsistent - although I do can see the raw optical data in the logs.

P.S.: By the way, what is your firmware version? I guess versions 4.0.x could not work with the MSP protocol which is necessary for this sensor.

Thanks for responding!! This was very useful advice. I added the range find settings, the values I had in there were not representative of the limitations of the device.

I downloaded the data logs and there is no “OF” dropdown for me to inspect called out here: Optical Flow Sensor Testing and Setup — Copter documentation

I have not calibrated the device though. I would figure I would be able to see some kind of data flowing in before I go and calibrate:

I have version 4.0.3. I am working on getting a new firmware version on my Navio 2 FC. Once I get it updated tonight I will circle back! Here are my logs though.
78 2-26-2022 12-35-49 PM.bin (108 KB)

I believe 4.0.3 is the crucial thing. As far as I remember, this version does not support MSP, so it cannot talk to the sensor at all. Please update it to 4.1.x first.

Update, I was able to compile and install a new image of ardupilot on my Navio FC via:

The “Bad OptFlow” message went away however I am still not receiving data. It looks the same as in my image above :frowning: I also attached my parameter config file. Maybe I am missing something??
config_params.param (17.7 KB)

I also looked to enable OpticalFlow in Mission Planner and the check box is grayed out??

Thank you!!

Okay, so I am very close to finding a solution to it! But I am not happy with my solution at all.
I wanted to check if I was getting any data back from the sensor so I made a python script that I ran to read data coming out of the port. I use pyserial to open the port and read it. After running this suddenly I start to get data flowing in on Mission Planner.

I am wondering if the port is never getting opened on startup or something. I have to run this python script that opens the port and reads info coming from the AMA0 port.

According to I set “SERIAL1” to the settings described above and it should work. Something is preventing the port from opening up. I am not sure why!!!

Well, in this case I am afraid my knowledge is insufficient - I don’t have this kind of hardware, and I have no idea what might be happening specific to this hardware.

Okay, I have a solution. This is a problem with the Navio 2 FC. It seems that the port does not open on boot for the flight controller (very annoying). A workaround is to run a python script that opens the port on boot.

Go to /etc/rc.local and ensure the file looks something like this (ignore the script):

Here is the python code for “” (I can only upload a txt file):
init_uart_port .txt (240 Bytes)

Once this file is in place run the command as you may need to pip install serial.

Finally, reboot the FC, and BOOM you get OPT data flowing into Mission Planner!!!

Thanks, @MaxBuzz for all the help!

1 Like

Just FYI, if the I2C pins are wired on this board the rangefinder stops working, past that just use the manufacturer specified configs:

  • SERIALn_PROTOCOL = 32, “n” is serial number of UART in ArduPilot hwdef, not the FC UART number. On some flight controllers, serial1 is not equal to UART1, Pls checkout FC manual to get corresponding serial number for each UART.
  • SERIAL_BAUD = 115
  • RNGFND_TYPE = 32
  • FLOW_TYPE = 7