So, im trying to read the data from a usb device into my pixhawk4 using a pico as host (this part works fine), the part thats giving me some trouble is in the Lua script. Its supposed to read from a serial port and write to gcs so i can see it (and later on be used inside the code), but on mission planner i get the error “attempt to call a nil value (method readstring)”
my code is currently looking like this:
local port = serial:find_serial(0)
port:begin(115200)
port:set_flow_control(0)
function spit ()
local avail = port:available():toint()
if avail > 0 then
gcs:send_text(0, “Hello from serial_test.lua #bytes:” .. avail)
local read = port:readstring(avail)
gcs:send_text(0, "RX: " .. read)
end
return spit, 1000
end
return spit, 1000
Tbh i have literally no clue on what im doing wrong, so thanks in advance for any help!
Edit: I’m using serial port 4, which is already configured as scripting in mission planner