|
| 1 | +.. currentmodule:: esp32 |
| 2 | + |
1 | 3 | :mod:`esp32` --- functionality specific to the ESP32 |
2 | 4 | ==================================================== |
3 | 5 |
|
@@ -86,6 +88,91 @@ Constants |
86 | 88 |
|
87 | 89 | Used in `Partition.find` to specify the partition type. |
88 | 90 |
|
| 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 | + |
89 | 176 | The Ultra-Low-Power co-processor |
90 | 177 | -------------------------------- |
91 | 178 |
|
|
0 commit comments