Skip to content

Commit 53145c4

Browse files
jimmodpgeorge
authored andcommitted
docs: Add docs for machine.bitstream and neopixel module.
Signed-off-by: Jim Mussared <[email protected]>
1 parent 62fd450 commit 53145c4

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

docs/library/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ the following libraries.
9292
framebuf.rst
9393
machine.rst
9494
micropython.rst
95+
neopixel.rst
9596
network.rst
9697
uctypes.rst
9798

docs/library/machine.rst

+22
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,28 @@ Miscellaneous functions
137137
above. The timeout is the same for both cases and given by *timeout_us* (which
138138
is in microseconds).
139139

140+
.. function:: bitstream(pin, encoding, timing, data, /)
141+
142+
Transmits *data* by bit-banging the specified *pin*. The *encoding* argument
143+
specifies how the bits are encoded, and *timing* is an encoding-specific timing
144+
specification.
145+
146+
The supported encodings are:
147+
148+
- ``0`` for "high low" pulse duration modulation. This will transmit 0 and
149+
1 bits as timed pulses, starting with the most significant bit.
150+
The *timing* must be a four-tuple of nanoseconds in the format
151+
``(high_time_0, low_time_0, high_time_1, low_time_1)``. For example,
152+
``(400, 850, 800, 450)`` is the timing specification for WS2812 RGB LEDs
153+
at 800kHz.
154+
155+
The accuracy of the timing varies between ports. On Cortex M0 at 48MHz, it is
156+
at best +/- 120ns, however on faster MCUs (ESP8266, ESP32, STM32, Pyboard), it
157+
will be closer to +/-30ns.
158+
159+
.. note:: For controlling WS2812 / NeoPixel strips, see the :mod:`neopixel`
160+
module for a higher-level API.
161+
140162
.. function:: rng()
141163

142164
Return a 24-bit software generated random number.

docs/library/neopixel.rst

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
:mod:`neopixel` --- control of WS2812 / NeoPixel LEDs
2+
=====================================================
3+
4+
.. module:: neopixel
5+
:synopsis: control of WS2812 / NeoPixel LEDs
6+
7+
This module provides a driver for WS2818 / NeoPixel LEDs.
8+
9+
.. note:: This module is only included by default on the ESP8266 and ESP32
10+
ports. On STM32 / Pyboard, you can `download the module
11+
<https://github.com/micropython/micropython/blob/master/drivers/neopixel/neopixel.py>`_
12+
and copy it to the filesystem.
13+
14+
class NeoPixel
15+
--------------
16+
17+
This class stores pixel data for a WS2812 LED strip connected to a pin. The
18+
application should set pixel data and then call :meth:`NeoPixel.write`
19+
when it is ready to update the strip.
20+
21+
For example::
22+
23+
import neopixel
24+
25+
# 32 LED strip connected to X8.
26+
p = machine.Pin.board.X8
27+
n = neopixel.NeoPixel(p, 32)
28+
29+
# Draw a red gradient.
30+
for i in range(32):
31+
n[i] = (i * 8, 0, 0)
32+
33+
# Update the strip.
34+
n.write()
35+
36+
Constructors
37+
------------
38+
39+
.. class:: NeoPixel(pin, n, *, bpp=3, timing=1)
40+
41+
Construct an NeoPixel object. The parameters are:
42+
43+
- *pin* is a machine.Pin instance.
44+
- *n* is the number of LEDs in the strip.
45+
- *bpp* is 3 for RGB LEDs, and 4 for RGBW LEDs.
46+
- *timing* is 0 for 400KHz, and 1 for 800kHz LEDs (most are 800kHz).
47+
48+
Pixel access methods
49+
--------------------
50+
51+
.. method:: NeoPixel.fill(pixel)
52+
53+
Sets the value of all pixels to the specified *pixel* value (i.e. an
54+
RGB/RGBW tuple).
55+
56+
.. method:: NeoPixel.__len__()
57+
58+
Returns the number of LEDs in the strip.
59+
60+
.. method:: NeoPixel.__setitem__(index, val)
61+
62+
Set the pixel at *index* to the value, which is an RGB/RGBW tuple.
63+
64+
.. method:: NeoPixel.__getitem__(index)
65+
66+
Returns the pixel at *index* as an RGB/RGBW tuple.
67+
68+
Output methods
69+
--------------
70+
71+
.. method:: NeoPixel.write()
72+
73+
Writes the current pixel data to the strip.

0 commit comments

Comments
 (0)