How send sensors value via Lua

Hello every one,
Firstly sorry for my bad English skills.
I am working on Rover robot, using Nora AP,
I have used a set of unsupported sensors by Ardupilot (RPM, temp, battery voltage),Any way I get there values successfully by using another controller.
Now I want to send there values to GCS and display them on quick_tape of MP, by connect an UART port of controller to the AP UART.
I understand that I can do that by using Lua scripts, but I am beginner with Lua, and I want to know what is the function that should I used,

I read the Ardupilot document of Lua
and check the githup examples, but I cant understand how to do that,
can any one help me with any quick guide please or at least inform me what is the main functions that should be used.

Have you seen this one?

Good luck!

1 Like

Thank you dear @VRquaeler

I check the link and understand that I should use this function: gcs:send_named_float() to send the value of sensor to display it on quick tap in mission planner, but I still can’t find out the right form of this function, Although I have read many examples.
I attach photo for the Lua code and the results in mission planner and the quick tape page.
can you guide me how change the value of battery_temp in the quick tape


Hello every one,
Hello Mr. @VRquaeler
I check the Status window, and I noted that the mission planner is responding to the Lua code, but the responsive variables are not the desired one, the responsive variables are:

  1. customfield0
  2. customfield1
  3. customfield2
  4. customfield3
  5. customfield4

And the desired values are:

  1. battery_temp
  2. Bat Voltage
  3. Bat Current
  4. Bat km left EST
  5. groundspeed2

Can anyone guide me please.

Named float values from Lua show up as MAV_XXXX.

1 Like

Do you mean like this (gcs:send_named_float(‘MAV_battery_voltage2’,30))?
Thank you.

No. The values in the quick tab will be prefixed with “MAV_”. Look there.

Sorry Mr @Yuri_Rage
I try to change Lua code like this, but doesn’t work:
MAV_battery_voltage2 = 30
gcs:send_named_float(‘battery_voltage2’,MAV_battery_voltage2) – send a values

I didn’t understand what the problem in my Lua
Should I make change in Lua or Mission planner?
Kindly can you explain to me more

Make no changes. Look in the quick tab value list for your values to be called “MAV_HELLO_WORLD”, etc.


Yes I get it

Thank you very much.

1 Like

Hello dear @Yuri_Rage
I want to receive data from the controller that connected to Nora autopilot via UART to the telem2 port,
I am facing issue with configure the telem2 in Lua code, where no data received, is this is the right forma:

-- find the serial first 
local port = serial:find_serial(0)

if not port or baud == 0 then
    gcs:send_text(0, "No Scripting Serial Port")

-- begin the serial port

-- the main update function that is used to read in data from serial port
function update()
    gcs:send_text(0, "byte2")
    if not port then
        gcs:send_text(0, "no Scripting Serial Port")
        return update, 300
    local n_bytes = port:available()
    gcs:send_text(0, tostring(n_bytes))
    --gcs:send_text(0, n_bytes)
    while n_bytes > 0 do
        local byte = port:read()
        gcs:send_text(0, "byte")

    return update, 300

return update, 300

what the value should be used for telem2 in the serial:find_serial() function?
where I have already modified the parameters of telem2 in mission planner, I make the baud rate = 9600 and the serial2_option = 28 as recommended in ardupilot-lua document.

Sorry for bothering you again and thank you for your time.

I don’t have time to type it all out right now, but your script is full of logic errors and comparisons of undeclared variables. Also, you probably want to run it faster than 3Hz.

Specifically, the baud variable in the first conditional statement is never assigned, and the while loop becomes infinite anytime serial data is available.