Change MAVLink function mask back to 256 (#489)
[betaflight.git] / docs / LedStrip.md
blob81775f6bb047299e8494f8b5a0f5cfd79d0846c5
1 # LED Strip
3 INAV supports the use of addressable LED strips.  Addressable LED strips allow each LED in the strip to
4 be programmed with a unique and independant color.  This is far more advanced than the normal RGB strips which
5 require that all the LEDs in the strip show the same color.
7 Addressable LED strips can be used to show information from the flight controller system, the current implementation
8 supports the following:
10 * Up to 32 LEDs.
11 * Indicators showing pitch/roll stick positions.
12 * Heading/Orientation lights.
13 * Flight mode specific color schemes.
14 * Low battery warning.
15 * AUX operated on/off switch.
16 * GPS state.
17 * RSSI level.
18 * Battery level.
20 Support for more than 32 LEDs is possible, it just requires additional development.
22 ## Supported hardware
24 Only strips of 32 WS2811/WS2812 LEDs are supported currently.  If the strip is longer than 32 LEDs it does not matter,
25 but only the first 32 are used.
27 WS2812 LEDs require an 800khz signal and precise timings and thus requires the use of a dedicated hardware timer.
29 Note: Not all WS2812 ICs use the same timings, some batches use different timings.  
31 It could be possible to be able to specify the timings required via CLI if users request it.
33 ### Tested Hardware
35 * [Adafruit NeoPixel Jewel 7](https://www.adafruit.com/products/2226) (preliminary testing)
36   * Measured current consumption in all white mode ~ 350 mA.
37   * Fits well under motors on mini 250 quads.
38 * [Adafruit NeoPixel Stick](https://www.adafruit.com/products/1426) (works well)
39   * Measured current consumption in all white mode ~ 350 mA.
41 ## Connections
43 WS2812 LED strips generally require a single data line, 5V and GND.
45 WS2812 LEDs on full brightness can consume quite a bit of current.  It is recommended to verify the current draw and ensure your
46 supply can cope with the load.  On a multirotor that uses multiple BEC ESC's you can try use a different BEC to the one the FC
47 uses.  e.g. ESC1/BEC1 -> FC, ESC2/BEC2 -> LED strip.   It's also possible to power one half of the strip from one BEC and the other half
48 from another BEC.  Just ensure that the GROUND is the same for all BEC outputs and LEDs.
51 | Target                | Pin  | LED Strip | Signal |
52 | --------------------- | ---- | --------- | -------|
53 | Naze/Olimexino        | RC5  | Data In   | PA6    |
54 | CC3D                  | RCO5 | Data In   | PB4    |
55 | ChebuzzF3/F3Discovery | PB8  | Data In   | PB8    |
56 | Sparky                | PWM5 | Data In   | PA6    |
58 Since RC5 is also used for SoftSerial on the Naze/Olimexino it means that you cannot use SoftSerial and led strips at the same time.
59 Additionally, since RC5 is also used for Parallel PWM RC input on both the Naze, Chebuzz and STM32F3Discovery targets, led strips
60 can not be used at the same time at Parallel PWM.
62 If you have LEDs that are intermittent, flicker or show the wrong colors then drop the VIN to less than 4.7v, e.g. by using an inline
63 diode on the VIN to the LED strip. The problem occurs because of the difference in voltage between the data signal and the power
64 signal.  The WS2811 LED's require the data signal (Din) to be between 0.3 * Vin (Max) and 0.7 * VIN (Min) to register valid logic
65 low/high signals.  The LED pin on the CPU will always be between 0v to ~3.3v, so the Vin should be 4.7v (3.3v / 0.7 = 4.71v).
66 Some LEDs are more tolerant of this than others.
68 The datasheet can be found here: http://www.adafruit.com/datasheets/WS2812.pdf
70 ## Configuration
72 The led strip feature can be configured via the GUI.
74 GUI:
75 Enable the Led Strip feature via the GUI under setup.
77 Configure the leds from the Led Strip tab in the INAV GUI.
78 First setup how the led's are laid out so that you can visualize it later as you configure and so the flight controller knows how many led's there are available.
80 There is a step by step guide on how to use the GUI to configure the Led Strip feature using the GUI http://blog.oscarliang.net/setup-rgb-led-cleanflight/ which was published early 2015 by Oscar Liang which may or may not be up-to-date by the time you read this.
82 CLI:
83 Enable the `LED_STRIP` feature via the cli:
85 ```
86 feature LED_STRIP
87 ```
89 If you enable LED_STRIP feature and the feature is turned off again after a reboot then check your config does not conflict with other features, as above.
91 Configure the LEDs using the `led` command.
93 The `led` command takes either zero or two arguments - an zero-based led number and a sequence which indicates pair of coordinates, direction flags and mode flags and a color.
95 If used with zero arguments it prints out the led configuration which can be copied for future reference.
97 Each led is configured using the following template: `x,y:ddd:mmm:cc`
99 `x` and `y` are grid coordinates of a 0 based 16x16 grid, north west is 0,0, south east is 15,15
100 `ddd` specifies the directions, since an led can face in any direction it can have multiple directions.  Directions are:
102  `N` - North
103  `E` - East
104  `S` - South
105  `W` - West
106  `U` - Up
107  `D` - Down
109 For instance, an LED that faces South-east at a 45 degree downwards angle could be configured as `SED`.
111 Note: It is perfectly possible to configure an LED to have all directions `NESWUD` but probably doesn't make sense.
113 `mmm` specifies the modes that should be applied an LED.
115 Each LED has one base function:
117 * `C` - `C`olor.
118 * `F` - `F`light mode & Orientation
119 * `A` - `A`rmed state.
120 * `R` - `R`ing thrust state.
121 * `G` - `G`PS state.
122 * `S` - R`S`SSI level.
123 * `L` - Battery `L`evel.
125 And each LED has overlays:
127 * `W` - `W`warnings.
128 * `I` - `I`ndicator.
129 * `T` - `T`hrust state.
130 * `B` - `B`link (flash twice) mode.
131 * `O` - Lars`O`n Scanner (Cylon Effect).
132 * `N` - Blink on la`N`ding (throttle < 50%).
134 `cc` specifies the color number (0 based index).
136 Example:
139 led 0 0,15:SD:AWI:0
140 led 1 15,0:ND:AWI:0
141 led 2 0,0:ND:AWI:0
142 led 3 0,15:SD:AWI:0
143 led 4 7,7::C:1
144 led 5 8,8::C:2
145 led 6 8,9::B:1
148 To erase an led, and to mark the end of the chain, use `0,0::` as the second argument, like this:
151 led 4 0,0:::
154 It is best to erase all LEDs that you do not have connected.
156 ### Modes
158 #### Warning
160 This mode simply uses the LEDs to flash when warnings occur.
162 | Warning | LED Pattern | Notes |
163 |---------|-------------|-------|
164 | Arm-lock enabled | flash between green and off | occurs calibration or when unarmed and the aircraft is tilted too much |
165 | Low Battery | flash red and off | battery monitoring must be enabled.  May trigger temporarily under high-throttle due to voltage drop |
166 | Failsafe | flash between light blue and yellow | Failsafe must be enabled |
168 Flash patterns appear in order, so that it's clear which warnings are enabled.
170 #### GPS state
172 This mode shows the GPS state and satellite count.
174 No fix = red LED
175 3D fix = green LED
177 The LEDs will blink as many times as the satellite count, then pause and start again.
179 #### RSSI level
181 This mode binds the LED color to RSSI level.
183 | Color      |   RSSI   |
184 | ---------- | ---------|
185 | Green      |   100%   |
186 | Lime green |    80%   |
187 | Yellow     |    60%   |
188 | Orange     |    40%   |
189 | Red        |    20%   |
190 | Deep pink  |     0%   |
191     
192 When RSSI is below 50% is reached, LEDs will blink slowly, and they will blink fast when under 20%.
195 #### Battery level
197 This mode binds the LED color to remaining battery capacity.
199 | Color      | Capacity |
200 | ---------- | ---------|
201 | Green      |   100%   |
202 | Lime green |    80%   |
203 | Yellow     |    60%   |
204 | Orange     |    40%   |
205 | Red        |    20%   |
206 | Deep pink  |     0%   |
207     
208 When Warning or Critial voltage is reached, LEDs will blink slowly or fast.
209 Note: this mode requires a current sensor. If you don't have the actual device you can set up a virtual current sensor (see [Battery](Battery.md)).
211 #### Blink
213 This mode blinks the current LED, alternatively from black to the current active color.
215 #### Blink on landing
217 This mode blinks the current LED, alternatively from black to the current active color, when throttle is below 50% and the craft is armed.
219 #### Larson Scanner (Cylon Effect)
221 The Larson Scanner replicates the scanning "eye" effect seen on the mechanical Cylons and on Kitt from Knight Rider.
223 This overlay merely varies the brightness of each LED's current color.
225 #### Flight Mode & Orientation
227 This mode shows the flight mode and orientation.
229 When flight modes are active then the LEDs are updated to show different colors depending on the mode, placement on the grid and direction.
231 LEDs are set in a specific order:
232  * LEDs that marked as facing up or down.
233  * LEDs that marked as facing west or east AND are on the west or east side of the grid.
234  * LEDs that marked as facing north or south AND are on the north or south side of the grid.
236 That is, south facing LEDs have priority.
238 The mapping between modes led placement and colors is currently fixed and cannot be changed.
240 #### Indicator
242 This mode flashes LEDs that correspond to roll and pitch stick positions.  i.e.  they indicate the direction the craft is going to turn.
244 | Mode | Direction | LED Color |
245 |------------|--------|---------------------|
246 |Orientation | North  | WHITE                   |
247 |Orientation | East   | DARK VIOLET     |  
248 |Orientation | South  | RED                     |
249 |Orientation | West   | DEEP PINK               |
250 |Orientation | Up     | BLUE                    |
251 |Orientation | Down   | ORANGE          |
252 | | | |
253 |Head Free   | North  | LIME GREEN      |
254 |Head Free   | East   | DARK VIOLET     |
255 |Head Free   | South  | ORANGE          |
256 |Head Free   | West   | DEEP PINK       |
257 |Head Free   | Up     | BLUE                    |
258 |Head Free   | Down   | ORANGE          |
259 | | | |
260 |Horizon     | North  | BLUE                    |
261 |Horizon     | East   | DARK VIOLET     |
262 |Horizon     | South  | YELLOW          |
263 |Horizon     | West   | DEEP PINK       |
264 |Horizon     | Up     | BLUE                    |
265 |Horizon     | Down   | ORANGE          |
266 | | | |
267 |Angle       | North  | CYAN                    |
268 |Angle       | East   | DARK VIOLET     |
269 |Angle       | South  | YELLOW          |
270 |Angle       | West   | DEEP PINK       |
271 |Angle       | Up     | BLUE                    |
272 |Angle       | Down   | ORANGE          |
273 | | | |
274 |Mag         | North  | MINT GREEN      |
275 |Mag         | East   | DARK VIOLET     |
276 |Mag         | South  | ORANGE          |
277 |Mag         | West   | DEEP PINK       |
278 |Mag         | Up     | BLUE                    |
279 |Mag         | Down   | ORANGE          |
280 | | | |
281 |Baro        | North  | LIGHT BLUE      |
282 |Baro        | East   | DARK VIOLET     |
283 |Baro        | South  | RED                     |
284 |Baro        | West   | DEEP PINK       |
285 |Baro        | Up     | BLUE                    |
286 |Baro        | Down   | ORANGE          |
288 #### Armed state
290 This mode toggles LEDs between green and blue when disarmed and armed, respectively.
292 Note: Armed State cannot be used with Flight Mode.
294 #### Thrust state
296 This mode fades the LED current LED color to the previous/next color in the HSB color space depending on throttle stick position.  When the
297 throttle is in the middle position the color is unaffected, thus it can be mixed with orientation colors to indicate orientation and throttle at
298 the same time.  Thrust should normally be combined with Color or Mode/Orientation.
300 #### Thrust ring state
302 This mode is allows you to use one or multiple led rings (e.g. NeoPixel ring) for an afterburner effect.  The light pattern rotates clockwise as throttle increases. 
304 A better effect is acheived when LEDs configured for thrust ring have no other functions.
306 LED direction and X/Y positions are irrelevant for thrust ring LED state.  The order of the LEDs that have the state determines how the LED behaves.
308 Each LED of the ring can be a different color. The color can be selected between the 16 colors availables.
310 For example, led 0 is set as a `R`ing thrust state led in color 13 as follow. 
313 led 0 2,2::R:13
316 LED strips and rings can be combined.
318 #### Solid Color
320 The mode allows you to set an LED to be permanently on and set to a specific color.
322 x,y position and directions are ignored when using this mode.
324 Other modes will override or combine with the color mode.
326 For example, to set led 0 to always use color 10 you would issue this command. 
329 led 0 0,0::C:10
332 ### Colors
334 Colors can be configured using the cli `color` command.
336 The `color` command takes either zero or two arguments - an zero-based color number and a sequence which indicates pair of hue, saturation and value (HSV).
338 See http://en.wikipedia.org/wiki/HSL_and_HSV
340 If used with zero arguments it prints out the color configuration which can be copied for future reference.
342 The default color configuration is as follows:
344 | Index | Color       |
345 | ----- | ----------- |
346 |     0 | black       |
347 |     1 | white       |
348 |     2 | red         |
349 |     3 | orange      |
350 |     4 | yellow      |
351 |     5 | lime green  |
352 |     6 | green       |
353 |     7 | mint green  |
354 |     8 | cyan        |
355 |     9 | light blue  |
356 |    10 | blue        |
357 |    11 | dark violet |
358 |    12 | magenta     |
359 |    13 | deep pink   |
360 |    14 | black       |
361 |    15 | black       |
364 color 0 0,0,0
365 color 1 0,255,255
366 color 2 0,0,255
367 color 3 30,0,255
368 color 4 60,0,255
369 color 5 90,0,255
370 color 6 120,0,255
371 color 7 150,0,255
372 color 8 180,0,255
373 color 9 210,0,255
374 color 10 240,0,255
375 color 11 270,0,255
376 color 12 300,0,255
377 color 13 330,0,255
378 color 14 0,0,0
379 color 15 0,0,0
382 ### Mode Colors Assignement
384 Mode Colors can be configured using the cli `mode_color` command.
386 - No arguments: lists all mode colors
387 - arguments: mode, function, color
389 First 6 groups of ModeIndexes are :
391 | mode | name        |
392 |------|-------------|
393 | 0    | orientation |
394 | 1    | headfree    |
395 | 2    | horizon     |
396 | 3    | angle       |
397 | 4    | mag         |
398 | 5    | baro        |
399 | 6    | special     |
401 Modes 0 to 5 functions:
403 | function | name  |
404 |----------|-------|
405 | 0        | north |
406 | 1        | east  |
407 | 2        | south |
408 | 3        | west  |
409 | 4        | up    |
410 | 5        | down  |
412 Mode 6 use these functions:
414 | function | name               |
415 |----------|--------------------|
416 | 0        | disarmed           |
417 | 1        | armed              |
418 | 2        | animation          |
419 | 3        | background         |
420 | 4        | blink background   |
421 | 5        | gps: no satellites |
422 | 6        | gps: no fix        |
423 | 7        | gps: 3D fix        |
425 The ColorIndex is picked from the colors array ("palette").
427 Examples (using the default colors):
429 - set armed color to red: ```mode_color 6 1 2```
430 - set disarmed color to yellow: ```mode_color 6 0 4```
431 - set Headfree mode 'south' to Cyan: ```mode_color 1 2 8```
433 ## Positioning
435 Cut the strip into sections as per diagrams below.  When the strips are cut ensure you reconnect each output to each input with cable where the break is made.
436 e.g. connect 5V out to 5V in, GND to GND and Data Out to Data In.
438 Orientation is when viewed with the front of the aircraft facing away from you and viewed from above.
440 ### Example 12 LED config
442 The default configuration is as follows
444 led 0 15,15:ES:IA:0
445 led 1 15,8:E:WF:0
446 led 2 15,7:E:WF:0
447 led 3 15,0:NE:IA:0
448 led 4 8,0:N:F:0
449 led 5 7,0:N:F:0
450 led 6 0,0:NW:IA:0
451 led 7 0,7:W:WF:0
452 led 8 0,8:W:WF:0
453 led 9 0,15:SW:IA:0
454 led 10 7,15:S:WF:0
455 led 11 8,15:S:WF:0
456 led 12 7,7:U:WF:0
457 led 13 8,7:U:WF:0
458 led 14 7,8:D:WF:0
459 led 15 8,8:D:WF:0
460 led 16 8,9::R:3
461 led 17 9,10::R:3
462 led 18 10,11::R:3
463 led 19 10,12::R:3
464 led 20 9,13::R:3
465 led 21 8,14::R:3
466 led 22 7,14::R:3
467 led 23 6,13::R:3
468 led 24 5,12::R:3
469 led 25 5,11::R:3
470 led 26 6,10::R:3
471 led 27 7,9::R:3
472 led 28 0,0:::0
473 led 29 0,0:::0
474 led 30 0,0:::0
475 led 31 0,0:::0
478 Which translates into the following positions:
481      6             3
482       \           /
483        \   5-4   /
484         \ FRONT /
485     7,8 | 12-15 | 1,2
486         /  BACK \
487        /  10,11  \
488       /           \
489      9             0
490        RING 16-27
493 LEDs 0,3,6 and 9 should be placed underneath the quad, facing downwards.
494 LEDs 1-2, 4-5, 7-8 and 10-11 should be positioned so the face east/north/west/south, respectively.
495 LEDs 12-13 should be placed facing down, in the middle
496 LEDs 14-15 should be placed facing up, in the middle
497 LEDs 16-17 should be placed in a ring and positioned at the rear facing south.
499 This is the default so that if you don't want to place LEDs top and bottom in the middle just connect the first 12 LEDs.
501 ### Example 16 LED config
504 led 0 15,15:SD:IA:0
505 led 1 8,8:E:FW:0
506 led 2 8,7:E:FW:0
507 led 3 15,0:ND:IA:0
508 led 4 7,7:N:FW:0
509 led 5 8,7:N:FW:0
510 led 6 0,0:ND:IA:0
511 led 7 7,7:W:FW:0
512 led 8 7,8:W:FW:0
513 led 9 0,15:SD:IA:0
514 led 10 7,8:S:FW:0
515 led 11 8,8:S:FW:0
516 led 12 7,7:D:FW:0
517 led 13 8,7:D:FW:0
518 led 14 7,7:U:FW:0
519 led 15 8,7:U:FW:0
522 Which translates into the following positions:
525      6             3
526       \           / 
527        \   5-4   / 
528       7 \ FRONT / 2
529         | 12-15 | 
530       8 /  BACK \ 1
531        /  10-11  \
532       /           \ 
533      9             0
536 LEDs 0,3,6 and 9 should be placed underneath the quad, facing downwards.
537 LEDs 1-2, 4-5, 7-8 and 10-11 should be positioned so the face east/north/west/south, respectively.
538 LEDs 12-13 should be placed facing down, in the middle
539 LEDs 14-15 should be placed facing up, in the middle
541 ### Exmple 28 LED config
544 #right rear cluster
545 led 0 9,9:S:FWT:0
546 led 1 10,10:S:FWT:0
547 led 2 11,11:S:IA:0
548 led 3 11,11:E:IA:0
549 led 4 10,10:E:AT:0
550 led 5 9,9:E:AT:0
551 # right front cluster
552 led 6 10,5:S:F:0
553 led 7 11,4:S:F:0
554 led 8 12,3:S:IA:0
555 led 9 12,2:N:IA:0
556 led 10 11,1:N:F:0
557 led 11 10,0:N:F:0
558 # center front cluster
559 led 12 7,0:N:FW:0
560 led 13 6,0:N:FW:0
561 led 14 5,0:N:FW:0
562 led 15 4,0:N:FW:0
563 # left front cluster
564 led 16 2,0:N:F:0
565 led 17 1,1:N:F:0
566 led 18 0,2:N:IA:0
567 led 19 0,3:W:IA:0
568 led 20 1,4:S:F:0
569 led 21 2,5:S:F:0
570 # left rear cluster
571 led 22 2,9:W:AT:0
572 led 23 1,10:W:AT:0
573 led 24 0,11:W:IA:0
574 led 25 0,11:S:IA:0
575 led 26 1,10:S:FWT:0
576 led 27 2,9:S:FWT:0
580        16-18  9-11
581 19-21 \           / 6-8
582        \  12-15  / 
583         \ FRONT /
584         /  BACK \
585        /         \
586 22-24 /           \ 3-5
587        25-27   0-2  
590 All LEDs should face outwards from the chassis in this configuration.
592 Note:
593 This configuration is specifically designed for the [Alien Spider AQ50D PRO 250mm frame](http://www.goodluckbuy.com/alien-spider-aq50d-pro-250mm-mini-quadcopter-carbon-fiber-micro-multicopter-frame.html).
596 ## Troubleshooting
598 On initial power up the LEDs on the strip will be set to WHITE.  This means you can attach a current meter to verify
599 the current draw if your measurement equipment is fast enough.  Most 5050 LEDs will draw 0.3 Watts a piece.
600 This also means that you can make sure that each R,G and B LED in each LED module on the strip is also functioning.
602 After a short delay the LEDs will show the unarmed color sequence and or low-battery warning sequence.
604 Also check that the feature `LED_STRIP` was correctly enabled and that it does not conflict with other features, as above.