I have the Mateksys H743 Slim Flight Controller.
I’ve connected the RCIN receiver to Serial Port 4 and have successfully completed radio calibration.
I have a Pololu servo controller that is currently connected to Serial Port 6. I have been able to successfully send serial commands to the servo controller through this test Lua script:
-- Lua script to send a restart command to a Pololu servo controller
-- Find the serial port (replace 0 with the appropriate port number)
local port = serial:find_serial(0)
-- Configure serial port settings
port:begin(9600) -- Adjust the baud rate based on your Pololu servo controller's settings
port:set_flow_control(0)
-- Function to send a restart command to a specific subroutine
function restartSubroutine(subroutineNumber)
local restartCommand = string.char(0xA7, subroutineNumber)
for i = 1, #restartCommand do
port:write(restartCommand:byte(i))
end
gcs:send_text(0, "Sent restart command to Pololu servo controller subroutine " .. subroutineNumber)
end
-- Specify the subroutine number you want to restart (replace with the actual subroutine number)
local targetSubroutine = 4
-- Execute the restart function with the specified subroutine number
restartSubroutine(targetSubroutine)
-- Function to periodically check for data on the serial port
function checkSerial()
if port:available() > 0 then
local read = port:read()
gcs:send_text(0, "Received data: " .. read)
end
return checkSerial, 1000
end
return checkSerial, 1000
I also have a JeVois camera that uses TX/RX communication that will be connected to Serial Port 7.
In Mission Planner, I have currently set Serial Port 6’s Protocol to “Scripting” and am assuming I should do the same thing for Serial Port 7.
However, I’m unable to find any examples online or resources on how to have a single Lua script transmit / receive data from multiple serial ports.
The confusing part in the script above is the
serial:find_serial(0)
The servo controller isn’t on port zero, so I’m not sure why it works (other than, that is the only port with a protocol currently set to “Scripting”. Though, even then, I’m not sure why “0” would target port 6.
Moreover, I’m unsure how I can have a script ALSO read from the RCIN serial port (once I can get it to read from multiple ports).
Any advice on this would be greatly appreciated!