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)
Waveform of example 1

In this example we define the signal by a tuple of durations and what state the signal starts in.

Waveform of example 2

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.

Waveform of example 3

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

Waveform of example 4

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

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