RMT
Detailed information about this class can be found in RMT.
The RMT (Remote Control) peripheral of the ESP32 is primarily designed to send and receive infrared remote control signals that use on-off-keying of a carrier frequency, but due to its design it can be used to generate various types of signals, this class will allow you to do this.
The RMT has 7 channels, of which 5 are available and can be mapped to any GPIO pin (Note: Pins P13 -P18 can only be used as inputs).
Channel
Resolution
Maximum Pulse Width
0
Used by on-board LED
1
Used by pycom.pulses_get()
2
100nS
3.2768 ms
3
100nS
3.2768 ms
4
1000nS
32.768 ms
5
1000nS
32.768 ms
6
3125nS
102.4 ms
7
3125nS
102.4 ms
Transmitting
The following examples create an RMT object on channel 4, configure it for transmission and send some data in various forms. The resolution of channel 4 is 1000 nano seconds, the given values are interpreted accordingly.
In this first example, we define the signal as a tuple of binary values that define the shape of the desired signal along with the duration of a bit.
from machine import RMT
# Map RMT channel 4 to P21, when the RMT is idle, it will output LOW
rmt = RMT(channel=4, gpio="P21", tx_idle_level=RMT.LOW)
# Produces the pattern shown in data, where each bit lasts
# duration * channel resolution = 10000 * 1000ns = 10ms
data = (1,0,1,1,1,0,1,0,1)
duration = 10000
rmt.pulses_send(duration, data)
In this example we define the signal by a tuple of durations and what state the signal starts in.

This third example, is a combination of the above two styles of defining a signal. Each pulse has a defined duration as well as a state. This is useful if you don't always want the signal to toggle state.

The following example creates an RMT object on channel 4 and configures it for transmission with carrier modulation.

The following example creates an RMT object on channel 2, configures it for receiving, then waits for the first, undefined number of pulses without timeout
If tx_idle_level is not set to the opposite of the third value in the tx_carrier tuple, the carrier wave will continue to be generated when the RMT channel is idle.
Receiving
The following example creates an RMT object on channel 2, configures it for receiving a undefined number of pulses, then waits maximum of 1000us for the first pulse.
The following example creates an RMT object on channel 2, configures it for receiving, filters out pulses with width < 20*100 nano seconds, then waits for 100 pulses
Last updated