This project intends to provide a tool that we consider might be useful for ESP32 hackers and developers: a Command Language Interface (CLI) application built for ESP32 using the Arduino(c) IDE, using the ESP32 RMT peripheral to transmit and decode Radio Control codes on ISM radio bands (433Mhz, 315Mhz, ...) . It is based on a FreeRTOS+CLI(c) "unofficial port" for ESP32, which is also provided.
RMT Radio Code is an interactive Arduino Sketch built for ESP32, that provides 2 different methods to receive and decode 24 bits PWM encoded Radio Code Words, compatible with the 2262/72 and EV1527 ICs, usually used in the ISM RF bands (433Mhz, 315Mhz) for radio remote controls.
One method is based in the use of the RC-Switch(c) library, and the second is based in the RMT peripheral.
The RC-Switch(c) library we understand could be considered as the "de facto" standard in the field of radio remote controls in the Arduino world, so an interactive tool to use the library without any extra coding could be benefitial for hackers trying to exercise and prototype with radio remote controls that use PWM encoded bits.
Regarding the RMT peripheral, we could not find until now an application using it for radio remote controls. It is positioned only for Infrared Remotes, and all the code examples provided by the manufacturer point in that direction. In fact, its use in the radio environment is quite tricky. The RMT receiver has all the advantages of being based in a hardware peripheral: timing capture is very precise, and the API is simple to use. The end of reception is triggered by a configurable threshold. The main design challenge for this use case (radio) is at what point the RMT is to be "fired" to start receiving the RF signal: if you start the receiver at any point, it just keeps grabbing noise. To avoid that, RMT Radio Code relies on the PulseIn Arduino function to identify when a Radio Code starts (the "SYN" code, see the data sheets of the manufacturers). So this may be a starting point trying to take advange of the RMT peripheral for other use cases.
The cli (based on FreeRTOS+CLI(c)) provides commands to enable the transmission of 24 bits Code Words using 2 different methods, one based in the RC-Switch library, the second based in the RMT peripheral. In this way, a complete “workbench” is provided to test and prototype with remote radio controls.
RMT Radio Code relies in the functionalities provided by FreeRTOS and FreeRTOS+CLI. It provides 2 independent tasks to simultaneously receive and decode 24 bits Radio Code Words. It receives commands and sends the outputs of the decoders via the Arduino Serial Monitor console. The FreeRTOS+CLI(c) library provides all the structure for the CLI. It provides a very good platform to create an extensible interface, with support for "help", parameter control and command execution. Since FreeRTOS+CLI(c) is actually not supported by Espressif's FreeRTOS, minor modifications are needed to be able to compile the library (indicated in the sources). RMT Radio Code provides 2 outputs for transmission: one based on the RMT Transmit peripheral of the ESP32 chip, and the other based on the RC-Switch(c) library. There is one command to transmit with RMT ("rmtxmit") and another one to transmit using RC-Switch(c) ("rcsxmit"). Both methods can also be configured using commands ("rcscfg" and "rmtcfg"). Use the “help” oommands for instructions on its use.
RMT Radio Code provides 2 independent inputs and methods to receive and decode the Radio Codes; each method is handled by a separate FreeRTOS Task, running simultaneously in parallel. To choose which method will be used to decode the received Radio code, the user has to connect the corresponding input pin to the Data PIN of the RF Receiver. Using a protoboard, the 2 input PINS can be connected simultaneously to the RF Receiver Data PIN, so the user can compare the behavior and the results of the 2 methods. Please remember to provide VOLTAGE LEVEL SHIFTING between the radio receiver interfaz (usually 5V or higher) and the ESP32 input pins.
To decode a bit, the usual method is to capture the pulse timing intervals ("high" and "low"), and based on that compare with the pre defined timings ("protocols") to define if it is a "1" or a "0". Very roughly, this is the method used by the RC-Switch(c) library (read the sources, it is actually much more elaborated).
PLEASE READ THE INSTALLATION INSTRUCTIONS in the Docs folder, both for the hardware and software. It is recommended to initially start using RMT Radio Code by cross-connecting directly one of the Transmit PINs (either RCSXmit OR RMTXmit, NOT BOTH TOGETHER!!) to the Receive PINs (the receive PINS CAN be connected together) to ensure everything is working correctly. After you are comfortable with the results, start testing using an RF transmitter and a receiver.
Please refer to the documentation and sources at https://github.com/abellisco/liscolab for details.
In the Docs folder you will find many documents that might be also useful for you:
- an Atmel Application Note explaining a method to decode PWM encoded bits
- Datasheets of the IC (PT2262 , EV1527) manufacturers
- Installation and user Guide
Previous knowledge of RC-Switch (specially about protocols and timings), FreeRTOS and FreeRTOS+CLI are expected.
https://www.freertos.org/index.html
https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_CLI/FreeRTOS_Plus_Command_Line_Interface.html
For RC-Switch documentation, refer to Project home: https://github.com/sui77/rc-switch/
For RMT API documentation, in your local Arduino/hardware/espressif/esp32/cores/esp32/ folder, you may find the API sources: esp32-hal-rmt.c and esp32-hal-rmt.h
In the same Repository ( https://github.com/abellisco/liscolab ) you will find another Arduino sketch, ledc, which provides a cli to prototype with the hal-ledc and ledc APIs for ESP32, as an example that allows prototyping with ESP-IDF APIs without coding.
We hope you find it useful for you
The Liscovsky-Barrera team.