RMT
The RMT (Remote Control) module 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.
Quick Usage Example: sending
import machine
# create a RMT object for transmission
rmt = machine.RMT(channel=3, gpio="P20", tx_idle_level=0)
# create series of bits to send
data = (1,0,1,0,1,0,1,0,1)
# define duration of the bits, time unit depends on the selected RMT channel
duration = 10000
# send the signal
rmt.send_pulses(duration, data)Quick Usage Example: receiving
import machine
# create a RMT object
rmt = machine.RMT(channel=3)
# Configure RTM for receiving
rmt.init(gpio="P20", rx_idle_threshold=12000)
# wait for any number of pulses until one longer than rx_idle_threshold
data = rmt.recv_pulses()Constructors
class machine.RMT(channel,...)
Construct an RMT object on the given channel. channel can be 2-7. With no additional parameters, the RMT object is created but not initialised. If extra arguments are given, the RMT is initialised for transmission or reception. See init for parameters of initialisation. The resolution which a pulse can be sent/received depends on the selected channel:
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
Methods
rmt.init(gpio, rx_idle_threshold, rx_filter_threshold, tx_idle_level, tx_carrier)
Initialise the RMT peripheral with the given parameters:
gpiois the GPIO Pin to use.rx_idle_thresholdis the maximum duration of a valid pulse. The represented time unit (resolution) depends on the selected channel, value can be 0-65535.rx_filter_thresholdis the minimum duration of a valid pulse. The represented time unit (resolution) depends on the selected channel, value can be 0-31.tx_idle_levelis the output signal's level after the transmission is finished, can be RMT.HIGH or RMT.LOW.tx_carrieris the modulation of the pulses to send.
Either rx_idle_threshold or tx_idle_level must be defined, both cannot be given at the same time because a channel can be configured in RX or TX mode only. rx_filter_threshold is not mandatory parameter. If not given then all pulses are accepted with duration less than rx_idle_threshold. tx_carrier is not mandatory parameters. If not given no modulation is used on the sent pulses.
The tx_carrier parameter is a tuple with the following structure:
carrier_freq_hzis the carrier's frequency in Hz.carrier_duty_percentis the duty percent of the carrier's signal, can be 0%-100%.carrier_levelis the level of the pulse to modulate, can be RMT.HIGH or RMT.LOW.
rmt.deinit()
Deinitialise the RMT object.
rmt.pulses_get(pulses, timeout)
Reads in pulses from the GPIO pin.
pulsesif not specified, this function will keep reading pulses until therx_idle_thresholdis exceeded. If it is specified this function will returnthe exactly that number of pulses, ignoring anything shorter than
rx_filter_thresholdor longer thanrx_idle_threshold.timeoutis specified, this function will return if the first pulse doesnot occur within
timeoutmicroseconds. If not specified, it will waitindefinitely.
Return value: Tuple of items with the following structure: (level, duration):
levelrepresents the level of the received bit/pulse, can be 0 or 1.durationrepresents the duration of the received pulse, the time unit (resolution) depends on the selected channel.
rmt.pulses_send(duration, data, start_level, wait_tx_done)
Generates pulses as defined by the parameters below
durationrepresents the duration of the pulses to be sent, the time unit (resolution) depends on the selected channel.dataTuple that represents the sequence of pulses to be sent, must be composed of 0 or 1 elements.start_leveldefines the state (HIGH/LOW) of the first pulse given bydurationifdatais not given.datamust be a tuple anddurationcan be a tuple or a single number, withdatabeing optional. In the case that onlydurationis provided, it must be a tuple and you must also providestart_levelwhich will dictate the level of the first duration, the signal level then toggles between each duration value.If
datais provided anddurationis a single number, each pulse indatawill have have an equal length as set byduration.If
dataanddurationare provided as tuples, they must be of the same number of elements, with each pulse lasting its matching duration.
wait_tx_done:False: Allows the function to send asynchronosly without waiting for the transmission to be done.True: will wait for transmission to be done
Constants
Define the level of the pulse:
RMT.LOW,RMT.HIGH
Last updated