Infrared and Radio Frequency Service

Last Updated on : 2024-05-11 08:07:07download

This topic describes the infrared (IR) and radio frequency (RF) service for developing universal IR remotes.

  • The IR capabilities can enable the device to send and learn IR codes.
  • With Tuya’s standard RF solution, the RF capabilities can enable the device to send and learn 433 MHz codes.

IR features

Processes

  1. Configure the IR feature on the Developer Platform, or contact your account manager to enable the required service.

  2. The MCU specifies the IR transmission (TX) pin and IR reception (RX) pin in the ir field when responding to the product information query (0x01).

    For example, 5.12 indicates the IR TX pin is I/O 5 and the IR RX pin is I/O 12.

    If the module works in the self-processing mode, the IR I/Os must not be used for the reset button or the Wi-Fi status indicator. For cross-module I/O configuration, the pin number plus 32 makes the pin number we need. For example, the pin number to be set for PB20 is 52 (20 + 32 = 52). The IR TX pin requires PWM signals. The IR RX pin requires I/O interrupts. For more information about the pin configuration, see the datasheet of your modules.

  3. To reuse the Wi-Fi indicator GPIO when the module works in the self-processing mode, you can set it using Sync new feature settings.

Commands

The commands used in the IR service.

Commands Description
0x2e Sync IR status
0x2f Trigger IR reception and transmission testing

Send IR status (0x2e)

IR status Description Status value
Status 1 IR code is being sent. 0x00
Status 2 IR code is sent. 0x01
Status 3 IR learning is in progress. 0x02
Status 4 IR learning is completed. 0x03
  • The short retention of IR code availability determines that serial data is sent directly without a resending mechanism.

  • You can configure the IR status indication as needed.

  • IR transmission and reception will use two GPIO pins on the module. If the module works in the self-processing mode, ensure that the IR GPIO pins are not configured for other features. For more information about the module self-processing mode, see Query working mode (0x02).

The module sends the following data.

Field Bytes Description
Header 2 0x55aa
Version 1 0x00
Commands 1 0x2e
Data length 2 0x0001
Data Data Indicate the IR status.
  • 0x00: Status 1
  • 0x01: Status 2
  • 0x02: Status 3
  • 0x03: Status 4
Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.

Example: 55 aa 00 2e 00 01 00 2e

The MCU returns the following data.

Field Bytes Description
Header 2 0x55aa
Version 1 0x03
Commands 1 0x2e
Data length 2 0x0000
Data Data None
Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.

Example: 55 aa 03 2e 00 00 30

Trigger IR reception and transmission testing (0x2f)

MCUModuleIR RemoteIR Controlled DeviceTrigger IR reception andtransmission testing with0x2f.Enter IR receptionstatus.Notify the MCU of IR statuswith 0x2e.Send an IR code to controlthe device, such as turningit on.Send the received IR code 2 seconds after receivingthe command from the IR remote.If the device isturned oncorrectly, the testpasses. Otherwise,it fails.MCUModuleIR RemoteIR Controlled Device
  • Only the unpaired module can enter IR test mode.
  • The module enters IR learning status as it enters test mode.
  • Once the module enters test mode, it will stay in the IR learning process and keep transmitting the learned code until the module is paired or powered off.

The MCU sends the following data.

Field Bytes Description
Header 2 0x55aa
Version 1 0x03
Commands 1 0x2f
Data length 2 0x0000
Data Data None
Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.

Example: 55 aa 03 2f 00 00 31

The module returns the following data.

Field Bytes Description
Header 2 0x55aa
Version 1 0x00
Commands 1 0x2f
Data length 2 0x0001
Data Data
  • 0x00: The module successfully enters test mode.
  • 0x01: The module failed to enter test mode.
Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.

Example: 55 aa 00 2f 00 01 00 2f

RF features

Processes

  1. To turn on the RF feature, enable the abv field in Sync new feature settings (0x37 and 0x00).
  2. When you use the RF code, multiple key values might be transmitted in a single operation. The MCU can use the buf field in Sync new feature settings (0x37 and 0x00) to send its serial buffer size to the module. According to the maximum data length of the key value, the MCU serial buffer must be larger than 256 bytes.
    When sending multiple key values in a single operation, the module can determine whether to fragment the packet based on the MCU serial buffer. The minimum packet size is a key value. Multiple key values are sent using one command by default.
  3. Since the MCU executes RF commands, the module is not intended to process status indication itself.

Commands

The commands used in the RF service.

Commands Description
0x33 (subcommand: 0x01) Control RF learning
0x33 (subcommand: 0x02) Send RF data
0x33 (subcommand: 0x03) Report RF learning

Control RF learning (0x33 and 0x01)

The module instructs the MCU to enter or exit RF learning mode.

The module sends the following data.

Field Bytes Description
Header 2 0x55aa
Version 1 0x00
Commands 1 0x33
Data length 2 0x0002
Data 1 Subcommand: 0x01: RF learning command
1 Control status:
  • 0x01: Enter RF learning mode.
  • 0x02: Exit RF learning mode.
Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.

Example: 55 aa 00 33 00 02 01 01 36

The MCU returns the following data.

Field Bytes Description
Header 2 0x55aa
Version 1 0x03
Commands 1 0x33
Data length 2 0x0003
Data 1 Subcommand: 0x01
1 Control status: 0x01: Enter RF learning mode.
1 Acknowledgment status:
  • 0x00: Success.
  • 0x02: Exit RF learning mode.
  • 0x01: Failure.
Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.

Example: 55 aa 03 33 00 03 01 01 00 3a

Send RF data (0x33 and 0x02)

  • A piece of RF data can consist of multiple key values. If a piece of RF data exceeds the serial buffer capacity, key values can be transmitted in multiple packets.

  • RF data has a fixed encoding, with the transmission time per bit determined by the rate. When a bit is 1, it is transmitted. When a bit is 0, it is not sent and the high bit goes first.

  • The MCU only needs to parse the Data field, not the frequency and transmission rate fields.

The module sends the following data.

Field Bytes Description
Header 2 0x55aa
Version 1 0x00
Commands 1 0x33
Data length 2 0x07+n*(T+D+I+L+C)
Data 1 Subcommand: 0x02
1 Messaging type:
  • 0x00: Code library.
  • 0x01: Learning code.
1 The number of key values: n
1 Key value offset:
  • 0xFF: Send all key values.
  • 0x00 to 0xFE: The offset value, which is 0 for the first packet. The number of key values for the last packet is -1.
1 Frequency: 0: 315 MHz. 1: 433.92 MHz.
2 Transmission rate: For example, 2,777 bps.
N Data
  • T (1 byte): Times, the number of transmission times. When the module sends learning codes, this field is set to 0x00 as invalid.
  • D (2 bytes): Delay, the interval between key values. When the module sends learning codes, this field is set to 0x0000 as invalid.
  • I (2 bytes): Intervals, the transmission interval. When the module sends learning codes, this field is set to 0x0000 as invalid.
  • L (2 bytes): Code length, the length of data sent by the RF.
  • C (N bytes): Code, the data sent by the RF.
Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.

Example: 55 aa 00 33 00 xx 02 01 00 ff 00 0a d9 00 00 00 00 00 00 xx xx xx xx xx xx xx

The MCU returns the following data.

Field Bytes Description
Header 2 0x55aa
Version 1 0x03
Commands 1 0x33
Data length 2 0x0002
Data 1 Subcommand: 0x02
1 Acknowledgment status:
  • 0x00: Success.
  • 0x01: Failure.
Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.

Example: 55 aa 00 33 00 02 02 00 36

Report RF learning (0x33 and 0x03)

The MCU sends the following data.

Field Bytes Description
Header 2 0x55aa
Version 1 0x03
Commands 1 0x33
Data length 2 0x0002 + N
Data 1 Subcommand: 0x03
1 Status:
  • 0: Success.
  • 1: Failure.
N Data content: If learning fails, the MCU will not send this field. If learning succeeds, the MCU can send data in a custom format.
Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.

Example: 55 aa 03 33 xx xx 03 00 xx xx xx xx xx xx

The module returns the following data.

Field Bytes Description
Header 2 0x55aa
Version 1 0x00
Commands 1 0x33
Data length 2 0x0002
Data 1 Subcommand: 0x03
1 Acknowledgment status:
  • 0x00: Success.
  • 0x01: Failure.
Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.

Example: 55 aa 00 33 00 02 03 00 37