How to connect neopixel or profiled and program them with pixhawk

Hello Everyone !
First of all, sorry if I make some mistakes, I’m a begineer and I probably just need clarifications/explanations from someone more experienced.

As a software engineer, I was trying to get down inside the “drone stuff”. So I’ve bought a quadcopter (QAV 250 - Pixhawk4 mini based) complete kit from Holybro. It looks really great to get started and I’d like to thank you for bringing us this (ardupilot) awesome project, well documented even for a begineer like me.

I’m going to get my hands dirty with mission planner in my region, but before that, I am considering adding some strip leds, ideally fixed under the four arms of my quadcopter. From my understanding and previous googling researchs, Ardupilot does support some of them !

So far, I’ve understood that theses strip leds should be connected to PWM ports to my flight controller (pixhawk 4 mini) and might be powered externally ?

From my research, I’ve found this documentation page:
https://ardupilot.org/copter/docs/common-external-leds.html

However, I don’t where to start to get the thing working. If someone could help me a little understanding what to buy, how to wire and how to script, I will be happy to write some tutorial for ardupilot.

After further researches, I’ve found in the documentation two projects, NeoPixel and ProfiLed. Links:
https://ardupilot.org/copter/docs/common-serial-led-neopixel.html
https://ardupilot.org/copter/docs/common-serial-led-ProfiLED.html

However I am not understanding hardware schemas. How many PWM outputs do I need to powers how many leds ? Is PWM pins equivalent to MAIN OUT pins on my pixhawk 4 mini ? schema: https://docs.px4.io/master/assets/img/pixhawk4mini_interfaces.b1a7a364.png

Also, How I should program them using ardupilot ?

Thank you per avance

Lua scripting is the best way to control them - some examples here: https://github.com/ArduPilot/ardupilot/tree/master/libraries/AP_Scripting/examples
ArduPilot provides greater flexibility than the documentation link you provided for your Pixhawk4-Mini. Best resource for you is https://github.com/ArduPilot/ardupilot/blob/master/libraries/AP_HAL_ChibiOS/hwdef/PH4-mini/README.md
You can have a huge number of LED’s, depending on your board type. Software wise, it’s up to 16 strips, with I think up to 128 LED’s per strip.
For powering them, budget 50mA per ws2812, then add a fudge factor.

Thank you for answering me so fast !
Okay, it seems that ardupilot supports very well ws218b leds !
Regarding the documentation of the ph4-mini you provide me, I should be able to use PWM 5 to PWM 11 ports to connects strip leds ! This is truely awesome !

I’ve read a little the examples of lua scripts gaven. I’ve understood that each SERVO can be scripted with lua using SERVOn_FUNCTION, channels between 94-106 (wich explain the 16 led strip limitation (largely generous)). But I haven’t understood how one could “select” a specific PWM or PWM group where to run lua scripts ? (for example my PWM 5 to 11).

Finally, more hardware interrogations, I’ve estimated that a strip of 1m led should be a good start. I was looking for buying something like this:
https://www.amazon.com/BTF-LIGHTING-WS2812B-Individual-Addressable-Non-waterproof/dp/B01CDTEJR0/ref=mp_s_a_1_1_sspa?dchild=1&keywords=ws2812b%2Bled%2Bstrip%2B1m&qid=1608886194&sr=8-1-spons&psc=1&spLa=ZW5jcnlwdGVkUXVhbGlmaWVyPUEzRUdWTVFOTFJDMFZDJmVuY3J5cHRlZElkPUEwNDY4NTM0M1RPQ1dNSU5VQUNMRCZlbmNyeXB0ZWRBZElkPUEwMDQ1Nzk3MTRQMDhQTDlUSlowMiZ3aWRnZXROYW1lPXNwX3Bob25lX3NlYXJjaF9hdGYmYWN0aW9uPWNsaWNrUmVkaXJlY3QmZG9Ob3RMb2dDbGljaz10cnVl&th=1

But I have not understood how to wire them. Do they need 3 pin for programmable signal + two for power supply ? this picture confuse me:
https://images-na.ssl-images-amazon.com/images/I/51XGvEPf9GL.AC_SY780.jpg

If you can answer this I will be sufficiently confident to buy required hardware, I just dont want to miss a point before doing something wrong or buying unusable electronic. Thank you per avance, specially for answering on christmas period !

Hello, I can’t open the link of the picture which confuses you, but I guess it’s because there are five wires coming from the strip. This is normal. The supply lines are doubled. You just need 3 wires, one signal, one 5V and one ground.

I don’t have any experience with the programming via lua, so I’m afraid I can’t help you with that…

Few days later,
I’ve received my ws2812 module ! I’ve switched my flight controller software from PX4 to ARDUPILOT and perform all required calibrations (sensors + channels) using QGroundControl. I’ve tried to arm the quadcopter and it appears that it works.

So now, I’m trying to connect my new ws2812 and make sure I control it before finish the drone build and go flight !

So, if you still wants to help me, here are the steps I’ve tried so far:

  1. bought this module (french link) :
    https://www.amazon.fr/gp/aw/d/B078HYP681?psc=1&ref=ppx_pop_mob_b_asin_title
    it’s not exactly the same as a strip led, but from my understanding it works the same way (use only three pins, every led should be adressable and leds number is below 128 wich is the maximum manageable on one 5v PWM port).

  2. The matrix mentioned in step 1) is shipped with a little connector MALE-to-MALE (3 pin). I’ve used one my pixhawk 4 mini wire FEMALE-to-FEMALE (3pins) , to connect one MALE side on the PWM 6th port still available on my pixhawk 4 mini, and the other MALE directly inside the led MATRIX. It’s not fixed yet on the led matrix but I will when everything will works as expected.

  3. I’ve connected my drone with USB to QGroundControl and have edited few parameters.
    -I’ve set SCR_ENABLE to 1 and then reboot (doc: https://ardupilot.org/copter/docs/common-lua-scripts.html#common-lua-scripts )
    -I’ve set NTF_LED_TYPES by checking all cases (doc: https://ardupilot.org/copter/docs/common-serial-led-ProfiLED.html)

  4. Then I’ve unplug my drone. I’ve explore my SD Card, have found the APM folder but no “scripts” folder as expected here

: “Upload scripts (files with extension .lua) to the autopilot’s SD card’s APM/scripts folder (if this folder does not exist you can create it by setting SCR_ENABLE to 1 and rebooting)”

Then I’ve download the following lua script: https://github.com/ArduPilot/ardupilot/blob/master/libraries/AP_Scripting/examples/LED_roll.lua and put it inside my “APM/scripts” folder, on the SD CARD. I’ve plugged back the sd card inside the drone (powered OFF).

  1. I’ve powered my drone with my liPo battery, because I believe that PWM pins are not powered through USB wires. And of course the matrix stays completely off :confused:

Some aditionnal informations:

  1. my NTF_LED_LEN (the length of the longest string that is connected) is set to 33 wich is incorrect as my matrix has 64 LEDS (8x8).

  2. the example script use 30 leds. I have’NT modified it yet.

  3. I don’t understand if I should and How (if needed) “say” to my pixhawk 4 mini to run the script on the 6th MAIN OUT pin of my flight controller, where my matrix is plugged in.

Thank you if you took the time to read everything and hope you’ve got any clue about this. I may provide you some pictures if you wants, about the wiring part. I’ve got a raspberry pi, so I might try to create some environment on it to test the LED Matrix on some environment I understand much more to make sure it’s not broke ?

I’ve identified more aspects of ardupilot about SERVOn_FUNCTION wich helped me to takes down my third problem. I’ve posted a new topic here: Control ws2812 matrix led with script lua on PIXHAWK 4 MINI