WS2812B (NeoPixel) Integration

Since we can’t get access to the video to see what you mean, could you please describe what you see? Are you referring to the colours being wrong or to the flashing being erratic?

We have discovered that not all WS2812B NeoPixels follow the RGB sequence - some are GRB and thus the displayed colours will be different.

Also, what flight controller are you using the NeoPixels on?

Sorry!
https://drive.google.com/file/d/18cYoKydri3AWCNSzsWD8SwTqXV0C41gy/view?usp=drivesdk

OK, so the colours are correct but sometimes the flashing is out of step with the main LED, or the NeoPixel LEDs stay on and dont flash when they should. All those different symptoms happen all in just one boot up.

The flashing being out of step with the internal LED is a known issue and has been reported by both @Hoehenarbeit and me and is described in earlier posts in this thread. It appears that the data stream that should be sent to the NeoPixel LEDs gets “lost” at times, thus leaving the LEDs in their last state - either ON or OFF - for one or more cycles of flashing.

Looks like there’s loss of signal.
This is the video with LEDs working fine.

This is the video during loss of signal.

Looks like it’s happening because of priority.

I have opened a issue for sync loss.

@Mallikarjun_SE @Hoehenarbeit and anyone else who has this issue, can you add the firmware version you were using and any more information I have missed to the issue.

Thanks

Hey @iampete
I’m using Pixhawk 1 with fmuv2 firmware. My board is 1MB flash one. If you insist, I can try on CubeBlack or CubeOrange.


Hey @rmackay9
If possible we should add NTF_NEO_LEN to upcoming version of Arducopter. This is only available in AC4.0.3dev

Sync loss should now be fixed in the master/latest. Not NeoPixels but this is a example of what can be done with scripting and ProfiLEDs.

Example scripts here: https://github.com/ArduPilot/ardupilot/pull/13658

Its just a matter of a single line change in the script to do this with NeoPixels, although the update rate is not so good as ProfiLEDs, I doubt it would make much difference for this example.

2 Likes

That’s good news … :grinning:

I don’t understand how the releases of AP versions work, so when does “master/latest” become a release that we can safely upgrade to - an official/stable version?

Also, the parameter NTF_NEO_LEN was in AP ver 4.0.3-dev, but did not make it into the V4.0.3 official/stable version. How do I know when it will progress to an official/stable version?

It’s working without any sync loss.

1 Like

I’ve been trying to write my own LUA script with neopixel leds and a Pixhawk black cube. Did Tridge use any kind of program to write the LUA script? I have found that taking out the micro sd card and writing code and then putting it back in the cube is basically trial and error and very difficult to find bugs in the code. I’m really just looking for an easier way to debug the LUA script controlling the neopixel leds.

if you flash to latest there you can use MAVftp to upload the script via the usb connection. You will also need beta mission planner, its ctrl +x on the main page or a tab on the config page somewhere. You can also reboot with ctrl + f -> reboot pixhawk. Speeds it up quite a lot. On latest you also get extended messages in the messages tab so you can see the full error.

1 Like

Hi.

I am starting to test this on a test Pixhawk and a test Micropix (no AUX outputs) controllers with ArduCopter versions both beta and latest (I observe that lua calls are changing). I am watching outputs on an oscilloscope so as not to have level problems.

No outputs up to now.

On the test Pixhawk (beta):
22/03/2020 13:09:39 : RCOut: PWM:1-8 NeoP:9-12 PWM:13-14
22/03/2020 13:09:39 : fmuv3 004B0036 3436510A 32393637
22/03/2020 13:09:39 : ChibiOS: d4fce84e
22/03/2020 13:09:39 : ArduCopter V4.0.3 (ffd08628)

On the test Micropix (latest):
22/03/2020 10:53:30 : RCOut: PWM:1-12
22/03/2020 10:53:30 : fmuv3 003C002D 50485011 20323450
22/03/2020 10:53:30 : ChibiOS: d4fce84e
22/03/2020 10:53:30 : ArduCopter V4.0.4-dev (f4f2caee)

Since “NeoP” only appears on the Pixhawk, does that mean that WS2812 leds will not work on the Micropix, and on the Pixhauw only on AUX 1-4?

You can do all 6 aux on the Pixhawk, you need to set BRD_PWM_COUNT = 6. I am not failure with the Micropix, but it looks like a Pixhawk clone with no aux outputs. If this is the case then NeoPixels won’t work.

I left apart the Micropix. First I tried a Pixracer (outputs PE14/PE13/PE11/PE9/PD13/PD14 as Pixhawk AUX’s), obtaining:
RCOut: PWM:1-6
(no NeoP indication), without success.

The Pixhawk, depending on version (beta, latest…) resets continuously, beeps or shows message “Lua: No scripts to run”, even reporting 2MB when programmed, so I wonder if it is an appropiate controller for WS2812’s.

It is not clear on the documentation which number to assign to SERVOx_FUNCTION’s: 94-109 or 120-123 for WS2812’s:


On the lua examples appears 94.

After many trials I have seen on the oscilloscope mostly constant 0V on outputs, and occasionally a constant level at 2.4V, which I don’t understand.

It depends what your trying to do, for notify you use the 120 - 123 for scripting you use the scripting outputs. To see them assigned you need to enable them in the NTF_LED_TYPE bit mask or set them to neopixels in your script.

Thanks, understood.

So I started with notifying, and things began to work with latest Copter version:
25/03/2020 11:37:16 : Frame: HEXA
25/03/2020 11:37:16 : RCOut: PWM:1-8 NeoP:9-12 PWM:13-14
25/03/2020 11:37:16 : fmuv3 004B0036 3436510A 32393637
25/03/2020 11:37:16 : ChibiOS: d4fce84e
25/03/2020 11:37:16 : ArduCopter V4.0.4-dev (bfc4802b)
even not using level converters (direct connection).

I connected four 8x8 WS2812 panels on Pixhawk AUX1 to AUX4 with:
BRD_PWM_COUNT=4
NTF_LED_LEN=64
NTF_LED_OVERRIDE=0
NTF_LED_TYPES=258
SCR_ENABLE=0
SERVO9_FUNCTION=120
SERVO10_FUNCTION=121
SERVO11_FUNCTION=122
SERVO12_FUNCTION=123
and got (4K):

(Note that trying 64 leds is not for flying; there are many problems).

Pixhawk led red and WS2812 leds yellow is easy to reproduce: disconnect and connect the USB cable to a USB power bank.

Trying all the same on a Pixracer didn’t work. It reported:
25/03/2020 12:17:33 : Frame: QUAD
25/03/2020 12:17:33 : RCOut: PWM:1-6
25/03/2020 12:17:33 : ArduCopter V4.0.4-dev (bfc4802b)
25/03/2020 12:17:33 : Pixracer 004F002F 34385108 35383135
25/03/2020 12:17:33 : ChibiOS: d4fce84e
but it didn’t work (leds off) even its outputs are the same as Pixhawk AUX’s (PE14/PE13/PE11/PE9/PD13/PD14).

With that working, I tried a lua script, changing:
NTF_LED_LEN=8
SCR_ENABLE=1
SERVO9_FUNCTION=94
with the following lua script:

local num_leds = 5
local vez = 0
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)

function update_LEDs()
serialLED:set_RGB(chan, 1, 127, 127, 127)
serialLED:send(chan)
gcs:send_text(6, “LEDs94: vez=” … tostring(vez))
vez = vez + 1
return update_LEDs, 2000 – run at 50Hz
end

return update_LEDs, 1000

obtaining on MP:
25/03/2020 12:36:21 : LEDs94: vez=6
25/03/2020 12:36:21 : Lua: Running /APM/scripts/LED_roll_test94.lua
25/03/2020 12:36:19 : Lua: Time: 190 Mem: 23789 + 373
25/03/2020 12:36:19 : LEDs94: vez=5
25/03/2020 12:36:19 : Lua: Running /APM/scripts/LED_roll_test94.lua
25/03/2020 12:36:17 : Lua: Time: 297 Mem: 23789 + 373
25/03/2020 12:36:17 : LEDs94: vez=4
25/03/2020 12:36:17 : Lua: Running /APM/scripts/LED_roll_test94.lua
25/03/2020 12:36:15 : Lua: Time: 167 Mem: 23789 + 373
25/03/2020 12:36:15 : LEDs94: vez=3
25/03/2020 12:36:15 : Lua: Running /APM/scripts/LED_roll_test94.lua
25/03/2020 12:36:13 : Lua: Time: 1758 Mem: 23789 + 373
25/03/2020 12:36:13 : LEDs94: vez=2
25/03/2020 12:36:13 : Lua: Running /APM/scripts/LED_roll_test94.lua
25/03/2020 12:36:13 : Frame: HEXA
25/03/2020 12:36:13 : RCOut: PWM:1-8 NeoP:9-12 PWM:13-14
25/03/2020 12:36:13 : fmuv3 004B0036 3436510A 32393637
25/03/2020 12:36:13 : ChibiOS: d4fce84e
25/03/2020 12:36:13 : ArduCopter V4.0.4-dev (bfc4802b)
25/03/2020 12:36:11 : Lua: Time: 166 Mem: 23789 + 373
25/03/2020 12:36:11 : LEDs94: vez=1
25/03/2020 12:36:11 : Lua: Running /APM/scripts/LED_roll_test94.lua
25/03/2020 12:36:11 : EKF2 IMU1 tilt alignment complete
25/03/2020 12:36:11 : EKF2 IMU0 tilt alignment complete

So there seems to be no problem on the two bold lines, but the panel on AUX1 (SERVO9_FUNCTION=94) was off all the time (the other three were on as before, with 8 leds each).

What am I missing to get lua script output on AUX1 and notifying on AUX2 to AUX4?

AUX1, 2, 3 and 4 are in the same group, because of the way it works you can only send whole group at a time. So notify is sending the group before the script has had a chance to tell the LED’s what color to be. Basically you need to update the whole group colors at once. I’m excited to see what your going to use those panels for, although I suspect the Pixhawk1 might struggle to do anything to fancy before it runs out of memory. There is a scrolling display example script, I should think you could get that working without too much effort.

I was trying with development versions after observing that lua objects calling syntax was being improved.

Edited: see forward post. The problem came because of having 94 scripting value duplicated on a MAIN and AUX output, having tested previously on the MAIN outputs, so desired AUX1 output was not found.

I had those panels before. Eventually they would be placed on this balance bot with Pixhawk (Barbie) but all AUX outputs are being used now, and with all these problems perhaps an Arduino or a companion computer should be used for these panels.

QGC reports 2MB when programming these Pixhawk’s. There seems to be no problems with 32 leds.

Memory is not the same as flash, memory is like your PC’s RAM, you already don’t have enough left to run the EKF.

The more things you turn off the more you can use for scripting, things like terrain and the second EKF you can turn off without much issue. If your planning on using a rover that will use less than copter from the start.