LED scripting lua bad argument

I wanted to use the example code for roll LEDs, but there are some parts where this doesn’t seem to work for me. Here is the relevant part of the code:

local update
local num_leds = 9

–[[
use SERVOn_FUNCTION 94 for LED. We can control up to 16 separate strips of LEDs
by putting them on different channels
–]]
local chan = SRV_Channels:find_channel(94)

if not chan then
gcs:send_text(6, “LEDs: channel not set”)
return
end

– find_channel returns 0 to 15, convert to 1 to 16
chan = chan + 1

gcs:send_text(6, “LEDs: chan=” … tostring(chan))

– initialisation code
–serialLED:set_num_neopixel(chan, num_leds)
–serialLED:set_num_profiled(chan, num_leds)

serialLED:set_num_LEDs(chan, num_leds)
serialLED:set_RGB(chan,1,0,0,0)


the 2 functions set_num_neopixel and set_mum_profiled can’t be found and I can’t find them in any doc. So I switched to set_num_LEDs…
when running the last line in the code i get the error message bad argument #2 in QGroundControl

Can somebody explain what this means, and what could be the reasons. I tested so much and still couldn’t figure it out…

That example works on the latest version of the firmware. There have been some improvements to the led control that have not yet made it to the stable release. This version of the example should work fine on stable.

1 Like

Hello! I’m having the same issue. when serialLED:set_num_profiled(chan, num_leds) is called, the GCS (mission planner) gives the error lua:[scriptname].lua:29 attempted to call, where 29 is the line number for this funtion call. I tried both @iampete 's version and the one on the master branch to no avail. Anything more on this? Running Pixhawk 2.4.8 on latest stable copter release

On copter stable you will need to use the old interface, note that the link above is now using the new interface ready for the next beta release. Try this version.

Thanks @iampete ! It works, no errors.

There is but one problem, it seems to be taking too much memory. With the script running,when I connect to Mission planner it says that it cannot allocate enoupgh memory for EKF2 and gives some NAV errors.

Also, when I try to connect to the GCS, it freezes on retreiving the param STAT_RUNTIME… I left it running for about 2 mins but it didnt unstick. Other MAVlink data is bieng traansfered fine, GPS updates on gcs etc.

Just putting this out there. I’m running a chinese clone of the Pixhawk 1 (pixhawk 2.4.8). I don’t think this flight controller has enough memory to do scripting on…

Is it just me?

Yeah, running out of memory can make bad stuff happen. You can turn off some stuff, things like terrain. This might get you enough. Driving lots of LED’s from scripting uses loads, this is where the new generation H7 fight controllers are great.

1 Like

Thanks! I’ll also try reducing the scr heap size. That durandal is looking pretty good…