Sending Custom UART Message from Serial Port

I would like to dedicate one of the serial ports to sending a simple UART message that I have defined. Is there any documentation for how to configure this? A couple of ideas I have are:

  1. To set the serial protocol to none for a specific port and then follow the example in libraries/AP_HAL/examples/UART_test/UART_test.cpp to configure the serial port to send my UART message.
  2. Create a new Serial Protocol in AP. My protocol would be very simple but I’m not certain which files I will need to modify/create so insight into that would be very helpful.

Do either of these approaches seem reasonable or is there a better way?

I also came across this link discussing how to accomplish this with Lua scripting. I would prefer to modify the code as I think I would learn more but if that proves to be too difficult I might be willing to use the scripting approach.
How to communicate throught UART? - ArduPlane / Plane 4.0 - ArduPilot Discourse

1 Like

While you might learn more by diving into the source code, modifying it is a bit of a can of worms.

Anything custom that you add will have to be added back into any updates that you wish to perform, which becomes a version control nightmare.

A Lua script can exist independently and will require little care and feeding once you have it working. Updating to a new firmware version is typically a non-issue, and the script will remain available on the SD card between updates.

2 Likes

Understood. I am still interested in modifying the source if anyone has advice on that?

1 Like

Hi
I want to do something similar to you. Have you found a solution yet?

Yes.
I recommend taking a look at libraries/AP_HAL/examples/UART_test/UART_test.cpp to so see how the uart write function is used. You might want to create a function or class utilizing what you’ve learned from UART_test.cpp and call it in one of the existing tasks scheduled in arducopter.cpp
You might also want to define your own serial protocol. You can look at AP_SerialManager.cpp and AP_SerialManager.h to see how this is done.

Can you send me some examples?

The files mentioned in my previous post are the examples.

1 Like

thanks for your help. I wrote a driver and it works fine. my problem is solved