Skip to content

Commit 7f235cb

Browse files
mattytrentinidpgeorge
authored andcommitted
docs/esp32: Add quickref and full docs for esp32.RMT class.
1 parent 0e0e613 commit 7f235cb

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed

docs/esp32/general.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ For your convenience, some of technical specifications are provided below:
5252
* I2S: 2
5353
* ADC: 12-bit SAR ADC up to 18 channels
5454
* DAC: 2 8-bit DACs
55+
* RMT: 8 channels allowing accurate pulse transmit/receive
5556
* Programming: using BootROM bootloader from UART - due to external FlashROM
5657
and always-available BootROM bootloader, the ESP32 is not brickable
5758

docs/esp32/quickref.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,20 @@ Notes:
365365

366366
p1 = Pin(4, Pin.OUT, None)
367367

368+
RMT
369+
---
370+
371+
The RMT is ESP32-specific and allows generation of accurate digital pulses with
372+
12.5ns resolution. See :ref:`esp32.RMT <esp32.RMT>` for details. Usage is::
373+
374+
import esp32
375+
from machine import Pin
376+
377+
r = esp32.RMT(0, pin=Pin(18), clock_div=8)
378+
r # RMT(channel=0, pin=18, source_freq=80000000, clock_div=8)
379+
# The channel resolution is 100ns (1/(source_freq/clock_div)).
380+
r.write_pulses((1, 20, 2, 40), start=0) # Send 0 for 100ns, 1 for 2000ns, 0 for 200ns, 1 for 4000ns
381+
368382
OneWire driver
369383
--------------
370384

docs/library/esp32.rst

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. currentmodule:: esp32
2+
13
:mod:`esp32` --- functionality specific to the ESP32
24
====================================================
35

@@ -86,6 +88,91 @@ Constants
8688

8789
Used in `Partition.find` to specify the partition type.
8890

91+
92+
.. _esp32.RMT:
93+
94+
RMT
95+
---
96+
97+
The RMT (Remote Control) module, specific to the ESP32, was originally designed
98+
to send and receive infrared remote control signals. However, due to a flexible
99+
design and very accurate (as low as 12.5ns) pulse generation, it can also be
100+
used to transmit or receive many other types of digital signals::
101+
102+
import esp32
103+
from machine import Pin
104+
105+
r = esp32.RMT(0, pin=Pin(18), clock_div=8)
106+
r # RMT(channel=0, pin=18, source_freq=80000000, clock_div=8)
107+
# The channel resolution is 100ns (1/(source_freq/clock_div)).
108+
r.write_pulses((1, 20, 2, 40), start=0) # Send 0 for 100ns, 1 for 2000ns, 0 for 200ns, 1 for 4000ns
109+
110+
The input to the RMT module is an 80MHz clock (in the future it may be able to
111+
configure the input clock but, for now, it's fixed). ``clock_div`` *divides*
112+
the clock input which determines the resolution of the RMT channel. The
113+
numbers specificed in ``write_pulses`` are multiplied by the resolution to
114+
define the pulses.
115+
116+
``clock_div`` is an 8-bit divider (0-255) and each pulse can be defined by
117+
multiplying the resolution by a 15-bit (0-32,768) number. There are eight
118+
channels (0-7) and each can have a different clock divider.
119+
120+
So, in the example above, the 80MHz clock is divided by 8. Thus the
121+
resolution is (1/(80Mhz/8)) 100ns. Since the ``start`` level is 0 and toggles
122+
with each number, the bitstream is ``0101`` with durations of [100ns, 2000ns,
123+
100ns, 4000ns].
124+
125+
For more details see Espressif's `ESP-IDF RMT documentation.
126+
<https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/rmt.html>`_.
127+
128+
.. Warning::
129+
The current MicroPython RMT implementation lacks some features, most notably
130+
receiving pulses and carrier transmit. RMT should be considered a
131+
*beta feature* and the interface may change in the future.
132+
133+
134+
.. class:: RMT(channel, \*, pin=None, clock_div=8)
135+
136+
This class provides access to one of the eight RMT channels. *channel* is
137+
required and identifies which RMT channel (0-7) will be configured. *pin*,
138+
also required, configures which Pin is bound to the RMT channel. *clock_div*
139+
is an 8-bit clock divider that divides the source clock (80MHz) to the RMT
140+
channel allowing the resolution to be specified.
141+
142+
.. method:: RMT.source_freq()
143+
144+
Returns the source clock frequency. Currently the source clock is not
145+
configurable so this will always return 80MHz.
146+
147+
.. method:: RMT.clock_div()
148+
149+
Return the clock divider. Note that the channel resolution is
150+
``1 / (source_freq / clock_div)``.
151+
152+
.. method:: RMT.wait_done(timeout=0)
153+
154+
Returns True if `RMT.write_pulses` has completed.
155+
156+
If *timeout* (defined in ticks of ``source_freq / clock_div``) is specified
157+
the method will wait for *timeout* or until `RMT.write_pulses` is complete,
158+
returning ``False`` if the channel continues to transmit.
159+
160+
.. Warning::
161+
Avoid using ``wait_done()`` if looping is enabled.
162+
163+
.. method:: RMT.loop(enable_loop)
164+
165+
Configure looping on the channel, allowing a stream of pulses to be
166+
indefinitely repeated. *enable_loop* is bool, set to True to enable looping.
167+
168+
.. method:: RMT.write_pulses(pulses, start)
169+
170+
Begin sending *pulses*, a list or tuple defining the stream of pulses. The
171+
length of each pulse is defined by a number to be multiplied by the channel
172+
resolution ``(1 / (source_freq / clock_div))``. *start* defines whether the
173+
stream starts at 0 or 1.
174+
175+
89176
The Ultra-Low-Power co-processor
90177
--------------------------------
91178

0 commit comments

Comments
 (0)