Some of you already know my enthusiasm for ArduPilot Lua scripting, and if you’re reading this, you’ll probably pick up on it pretty quickly. When I discovered the I2C, UART, and CAN bindings, the gears started turning, wondering how well we could leverage those comms protocols to expand the ArduPilot peripheral ecosystem without requiring firmware updates and dedicated, baked-in drivers.
Today, I uploaded an Arduino library to speed that endeavor along. It allows you to use an Arduino (or compatible) microcontroller as an autopilot connected I2C device, acting as a bridge between unsupported sensors and the autopilot.
Install the library via the Arduino Library Manager or PlatformIO Library Registry.
Alternatively, download the zip file from releases and follow Arduino’s instructions for importing a zip file. If you prefer PlatformIO, unzip or clone the library to your project’s lib/
directory.
The library includes an example sketch and Lua script that supports multiple DS18B20 OneWire temperature sensors connected to the Arduino. Temperature data gets passed across the I2C bus and is made available to the user as MAVLink named float values, as shown here in the Mission Planner “Quick” tab:
Beyond just providing temperature values for display, such a script could include logic to warn of impending overtemperature or fire, RTL in an out of limits scenario, reduce power to a non-critical script controlled component to reduce battery consumption, etc. Other sensor types could easily be connected and added to the sketch, allowing for a broad fusion of data within the scripting environment that would otherwise be impossible using the autopilot alone.
The project’s README file should be laid out well enough for you to begin using the library on your own, but please fire up the discussion here and ask questions or provide feedback!
To date, I’ve tested the library with an Arduino Pro Mini and a MatekH743 autopilot running Rover 4.3. I did successfully compile the code for an ESP32 but did not hardware test it. All development was done under PlatfomIO, but it is Arduino IDE compatible and compliant with the Arduino library specification. If this gains some traction and is tested more widely in the community, I will explore uploading it as a community/3rd party library available within the Arduino Library Registry (Library Manager). Pull requests welcome!
Many sincere thanks to @iampete, @hendjosh, @geofrancis, @ktrussell, @swebre, and others who’ve joined in the discussions regarding scripting and use cases. If this library proves useful, it’s not much of a stretch to use it as a template for a similar CAN communication library or craft a means to poll/control many of the I/O functions on a microcontroller via Lua.