Lua Script to read out external UART-sensor

    ACHTUNG: Mit der neuen EU Drohnenverordnung muß sich jeder Drohnen-Betreiber beim Luftfahrtbundesamt registrieren und seine Drohne mit der e-ID kennzeichnen! Ein passendes Kennzeichen bekommst Du hier im Shop. Außerdem benötigst Du eine Drohnen-Versicherung. Hier geht es zu unserem Drohnen-Versicherungsvergleich. Informationen zum neuen EU Drohnenführerschein gibt es hier.

    • Lua Script to read out external UART-sensor

      Hi there,

      I have an external sensor for my drone project. I am trying to use a Lua Script to read out the Serial Port of my Pixhawk 4. To boot the sensor the Pixhawk has to send the command @4D001F via UART to the sensor, after that it should periodically read the data from the sensor and send it to the GCS.

      I have written a script, but it doesen´t work and honestly I don´t really know what i am doing, this is all new to me.
      It would be huge for me, if someone with experience at Lua Scripting could look through my script and give me clues what I have to change.

      Currently my script reads:

      local port = serial:find_serial(0)
      port:begin(115200)
      port:set_flow_control(0)
      if port:available() > 0 then
      gcs:send_text(0, “@4D001F”)
      end
      function spit ()
      if port:available() > 0 then
      read = port:read()
      gcs:send_text(0, read)
      end
      gcs:send_text(0, read)
      return spit, 1000
      end
      return spit, 1000

      Thank you in advance :)