Connecting Matek Optical Flow to UART MSP

I am trying to connect this sensor via navio 2’s UART port (which to my understanding uses GPIO pins 14 and 15 on the pi). I can successfully read the sensor’s data from a python script using pyserial by opening /dev/ttyAMA0, but it does not work in ardupilot (serial 5).

For the navio config, I have:

# Default settings for ArduPilot for Linux.
# The file is sourced by systemd from arducopter.service

TELEM1="-A udp:192.168.1.108:5555"
TELEM5="-F /dev/ttyAMA0"

# Options to pass to ArduPilot
ARDUPILOT_OPTS="$TELEM1 $TELEM5"

I’ve tried other UART ports but they don’t work either

Hi @joego2124,

Most likely, you need to reconsider the parameters in the Mission Planner configuration. Here is the post with Marc’s settings that should help you out:

Hi, thank you for responding @liudmila.slepova . I have tested the Mission Planner parameters and they work with a different flight controller, but not with the Navio 2. I’ve also talked with the ardupilot devs and they said that the issue is likely that navio is not detecting the UART device. Could you please describe the process of adding a UART device to Navio 2 after connecting Rx and Tx?

I was able to get the sensor data to be read by ardupilot, but only after restarting arducopter by using:

sudo systemctl restart arducopter

and then running a test python script that opened up /dev/ttyAMA0:

import time
import serial
from struct import pack, unpack

import sys
from msp.multiwii import MultiWii

class Sensor:

  def __init__(self, ser_port):
    self.ser = serial.Serial()
    self.ser.port = ser_port
    self.ser.baudrate = 115200
    self.ser.bytesize = serial.EIGHTBITS
    self.ser.parity = serial.PARITY_NONE
    self.ser.stopbits = serial.STOPBITS_ONE
    self.ser.timeout = None
    self.ser.xonxoff = False
    self.ser.rtscts = False
    self.ser.dsrdtr = False

    wakeup = 2
    try:
      self.ser.open()
      print("Waking u/p board on " + self.ser.port + "...")
      
      junk = self.ser.read(64)
      
      print([junk[i:i+1] for i in range(len(junk))])
      
      # for i in range(1, wakeup):
      #   print(wakeup - i)
      #   time.sleep(1)
    except Exception as error:
      print("\n\nError opening " + self.ser.port + " port.\n" + str(error) + "\n\n")

    print("Serial Communication Initialized")

opflow = Sensor("/dev/ttyAMA0")

My theory is that somewhere along the arducopter start up process, navio is not opening the serial port, can someone please explain what’s going on?

Hi @joego2124,

For connecting the device to Navio2, you need to configure the necessary parameter in /etc/default/ardu* file and then reload the configuration with sudo systemctl daemon-reload. If the autopilot was running while you were changing the settings, the restart is required for the changes to take the effect.