Controlling WS2813 LEDs using Lua scripting


So I have been attempting to set up WS2813 strip LEDs to function as direction / status indicators for my quad using the Pixhawk 2.4.8 and Lua scripting. However I have been having some issues.

Firstly, I always see the ‘Lua: No scripts to run’ message regardless as to whether a Lua script is running or not.

I have had success running a simple ‘hello world’ script example taken from here: (although for some reason I got a syntax error for the commented line). However when I attempt to run the LED roll script I am faced with multiple Lua errors (that always seem to cut off after a certain amount of characters in Mission Planner’s Messages tab rather annoyingly).

Setting SERVO12_FUNCTION to 94 and running this basic LED test script:

local num_leds = 4
local vez = 0
local chan

chan = SRV_Channels:find_channel(94)

if not chan then
  gcs:send_text(0, "LEDs: channel not set")

chan = chan + 1

gcs:send_text(0, "LEDs started.")

serialLED:set_num_LEDs(chan, num_leds)

function update_LEDs()
  serialLED:set_RGB(chan, 1, 255, 255, 255)
  return update_LEDs, 500

return update_LEDs, 500

Giving me this in Mission Planners Messages log:

I have attempted removing the variables and hard coding it but get the same error. It is very frustrating to debug as I can only see part of the error message!

As an aside, I was hoping to use the beta Mission Planner and MavFTP to upload my Lua scripts (instead of manually moving them across to the scripts folder in the SD card), however these are the only folders it gives me:

Thank you for any help!

what version of Copter are you running?, the master examples only work on master, If you click on the unlabeled folder you should get to scripts i think

I am running ArduCopter V4.0.3. Clicking on the either of the folders shows no additional folders / files.

Start with these examples,

MavFTP should be working, if your not on USB it might be very slow (even on usb is a little slow)


If that fails

Be sure to try on an output admitting Neopixels. On common Pixhawks 9-12; on log:
RCOut: PWM:1-8 NeoP:9-12

Thanks for your replies.

On MAVFtp I select the empty folder and at the bottom I see ‘/ Listing’, then a progress bar fills up until ‘/ Ready’, however with no files or folders showing.

I also keep coming across a problem with the beta version of Mission Planner whereby when connecting to the Pixhawk it gets stuck going through ‘Already Got param’ parameters?


@iampete I tried uploading the hello_world and LED_roll lua scripts from that link to the Pixhawk and both seemed to work straight away! The LED strip goes a solid green. I no longer see those ‘Lua: No scripts to run’ messages either. I will have to study the files more carefully!

@Webillo In the documentation and in the LED_roll example I just uploaded they don’t include a channel, so I am not sure if they changed it? I am running on channel 12 luckily but hadn’t realised you had to assign a channel for Neopixels?

I was hoping to have a set of 4 LEDs on each arm with the back two being red and the front two using the NTF_LEDS (as seen in this link to copy the status LED on the Pixhawk, however it only uses the first LED in the LED strip? These two documents: WS2812B (NeoPixel) Integration refer to a NTF_LED_LEN parameter, however this does not exist in my parameter list?

Thanks again! :slight_smile:

Both of these things are in master but have not made it to stable yet

It is not currently possible to have some of the leds in one strip be NTF and others be scripting, really you need to use a different group other wise the send from the notify and scripting clash and send before the other is ready.

Hopefully we can fix this by making the notify rgb color available to scripting, then you can read out the notify color into the script and set them that way.

Ah I see thank you.

I was planning on having the two back strips controlled by a lua script and connected to one AUX channel whilst the front two strips are NTF LEDs and are controlled by a separate channel, so that should work fine for me! But it would be great if the NTF colour was made available for Lua scripting.

Is it possible for me to update my Arducopter to the master branch to get these features?

yep, cntrl + q on the mission planner load firmware screen, the notify length param should be coming to the next beta release. Note that the master firmware is less well tested so there might be bugs and it might do unexpected things

Excellent thank you very much for you help.

I don’t suppose you have any ideas why MAVFtp or the beta Mission Planner don’t seem to work for me?

no FTP ideas, try it on master and check for MP beta updates

Write script on the µSD directly.

For some reason the error came up again for the example LED_roll script?


I’m not sure if this has anything to do with me updating to the master branch.

I decided running what I thought would be a very simple script:

local chan1 = SRV_Channels:find_channel(94) + 1
local chan2 = SRV_Channels:find_channel(95) + 1

gcs:send_text(6, string.format("LEDs: Channel 1 = " .. tostring(chan1) .. ", Channel 2 = " .. tostring(chan2)))

serialLED:set_num_LEDs(chan1, 4)
serialLED:set_num_LEDs(chan2, 4)

for led = 1, 4 do
  serialLED:set_RGB(chan1, uint32_t(1 << led), 255, 0, 0)
  serialLED:set_RGB(chan2, uint32_t(1 << led), 255, 0, 0)


However it still gives me this error:


Managed to fix it by changing serialLED:set_num_LEDs to serialLED:set_num_profiled

you should be using serialLED:set_num_neopixel if you have neopixles. Scripting is evolving very quickly hence the differences between stable and master.

I see, thank you very much!

hello, help in compiling a lua script to control external LEDs. on and off control from control equipment and color control.