📜 ⬆️ ⬇️

Using RF Modules

Sometimes, a wireless connection is required between the devices. Recently, Bluetooth and Wi-Fi modules have been increasingly used for this purpose. But one thing is to transfer videos and hefty files, and another is to control a typewriter or a robot for 10 teams. On the other hand, radio amateurs often build, adjust and redo the receivers and transmitters to work with ready-made command encoders / decoders. In both cases, you can use quite cheap RF modules. Features of their work and use under the cut.

Types of modules


RF modules for data transmission operate in the VHF band and use standard frequencies of 433 MHz, 868 MHz or 2.4 GHz (less often 315 MHz, 450 MHz, 490 MHz, 915 MHz, etc.) The higher the carrier frequency, the faster the information can be transmitted.
As a rule, manufactured RF-modules are designed to work with any data transfer protocol. Most often it is a UART (RS-232) or SPI. Usually, UART modules are cheaper, and also allow the use of non-standard (user) transmission protocols. At first, I thought about riveting something like this , but recalling my bitter experience in manufacturing radio control equipment, I chose fairly cheap HM-T868 and HM-R868 (60 UAH = less than $ 8 a set). There are also models HM- * 315 and HM- * 433 that differ from the ones described below only by the carrier frequency (315 MHz and 433 MHz, respectively). In addition, there are many other modules similar to the way they work, so the information may be useful to owners of other modules.

Transmitter


Almost all RF modules are a small printed circuit board with contacts for power supply, data transfer and control signals. Consider a transmitter (transmitter) HM-T868 image
It has a three-prong connector: GND (common), DATA (data), VCC (+ power), as well as a pin for soldering the antenna (I used a MGTF wire stub at 8.5 cm - 1/4 wavelength).
')

Receiver


The HM-R868 receiver looks very similar to the corresponding transmitter.
image
but on its connector there is a fourth contact - ENABLE, when power is applied to it, the receiver starts working.

Job


According to the documentation, the operating voltage is 2.5-5V, the higher the voltage, the greater the range of work. In essence, this is a radio extension: when the voltage is applied to the DATA input of the transmitter, a voltage will also appear at the output of the DATA receiver (provided that ENABLE also supplies voltage). BUT, there are a few nuances. First: the frequency of data transmission (in our case, this is 600-4800 bps). Secondly: if there is no signal at the DATA input for more than 70ms, the transmitter goes into sleep mode (in fact, it is turned off). Thirdly: if there is no working transmitter in the receiver's reception area, any noise appears at its output.

Let's make a small experiment: we connect the power to the GND and VCC contacts of the transmitter. Conclusion DATA connect with VCC via a button or jumper. We also connect the power supply to the GND and VCC contacts of the receiver, we close the ENABLE and VCC to each other. Connect the LED to the DATA output (highly desirable through a resistor). As antennas, we use any suitable wire with a length of 1/4 wavelength. You should get this scheme:

Immediately after turning on the receiver and / or energizing the ENABLE, the LED should light up and light up continuously (or almost continuously). After pressing the button on the transmitter, nothing happens with the LED either - it continues to light up. When the button is released, the LED blinks (turns off and then comes on again) and continues to light up. When you press and release the button again, everything should repeat. What happened there? When the receiver was turned on, the transmitter was in a sleeping state, the receiver did not find a normal signal and began to receive any noise, respectively, and every bjaka appeared at the output. By eye, distinguishing a continuous signal from noise is unrealistic, and it seems that the LED shines continuously. After pressing the button, the transmitter comes out of hibernation and starts transmitting, a logical “1” appears at the receiver output and the LED is already really continuous. After the button is released, the transmitter transmits a logical “0”, which is received by the receiver and “0” also appears at its output - the LED finally goes out. But after 70ms, the transmitter sees that the same “0” is at its input and goes to sleep, the carrier frequency generator is turned off and the receiver starts to receive any noise, the output noise is that the LED lights up again.

It follows from the above that if the signal at the transmitter input is absent for less than 70 ms and is in the correct frequency range, then the modules will behave like a normal wire (we still do not pay attention to interference and other signals).

Package format


RF-modules of this type can be connected directly to the hardware UART or computer via MAX232, but taking into account the peculiarities of their work, I would advise using specific protocols described by software. For my purposes, I use packets of the following form: start-bits, bytes with information, a check byte (or several) and a stop bit. It is desirable to make the first start-bit longer, this will give time for the transmitter to wake up, the receiver tunes in to it, and the receiving microcontroller (or whatever you have) starts receiving. Then something like “01010”, if at the receiver output it is, then it is most likely not noise. Then you can put an identification byte - it will help you to understand which of the devices the packet is addressed to and with even greater probability that it will reject noise. Up to this point, it is advisable to read and check the information in separate bits, if at least one of them is wrong, we complete the reception and start listening again to the broadcast. Further, the transmitted information can be read immediately byte by writing to the appropriate registers / variables. At the end of the reception, we execute the control expression, if its result is equal to the control byte - we perform the required actions with the received information, otherwise - we again listen to the broadcast. As a control expression, you can consider any checksum, if the transmitted information is a little, or you are not strong in programming - you can simply calculate some arithmetic expression in which the transmitted bytes are variables. But it is necessary to take into account that the result should be an integer and it should fit in the number of control bytes. Therefore, it is better to use bitwise logical ones instead of arithmetic operations: AND, OR, NOT and, especially, XOR. If there is an opportunity, it is necessary to make a control byte as necessary because the radio is very crap, especially now in the world of electronic devices. At times, the device itself may interfere. I, for example, have a track on a board with 46kHz PWM 10cm from the receiver, which greatly interfered with reception. And this is not to mention the fact that RF-modules use standard frequencies, at which other devices can work at this moment: walkie-talkies, alarms, radio control, telemetry, etc.

What else can you read


HM-T and HM-R - description and documentation on the manufacturer's website.
1 , 2 and 3 are interesting articles and observations (many useful things can be found in the comments).

Source: https://habr.com/ru/post/139947/


All Articles