clip_image001.jpg

Low Cost Wireless UART

By: Kong Wai Weng

RH2T Magazine Vol.6, Sep 10

We have been receiving a lot of emails asking us how to use the low cost RF module for wireless communication. In this article, we discuss some tricks and tips on how to make the low cost wireless communication as reliable as possible.

1.0 Introduction

clip_image001

clip_image002

Low cost RF Transmitter and Receiver

Have you always wanted to add a wireless device in your project but you are tight on budget? Fortunately, Cytron does provide a low cost wireless solution for you. The low cost RF modules are available in 315MHz and 433MHz version. With less than RM50, you are able to get yourself a pair of RF Transmitter and Receiver.

However, a lot of users complain that these RF modules are very noisy and unreliable. Nonsensical signals are received at the Rx side all the time. We have tried it out ourselves and found out that the reliable wireless link can be achieved by implementing a few tips and tricks. This has been demonstrated in the previous issue’s project – Two Wheeled Balancing Robot. In this article, we will describe the problems with low cost RF module and provide resolution for every problem found. DIY Project Set “PR16: Sending Data Using RF Module” will be used for various demonstration.

2.0 The Problem

Before we solve any problem, we must understand its cause. After carrying out a few experiments by probing here and there with an oscilloscope, we found that the unreliable wireless link issue faced by most of the users is due to a few factors as discussed below:

· Antenna Length – The length of the antenna is critical in determining the effectiveness of the wireless link. Most users use the incorrect length antenna or even no antenna at all. This can greatly reduce the range of the RF module.

· Transmitting Constant Digital State – The low cost RF module has a limitation where it is not capable of transmitting a constant state (either ‘1’ or ‘0’) over the wireless link. From the picture below, we can see that when the input to the RF Transmitter is constantly ‘1’ or ‘0’, the output from the RF Receiver is very noisy. In contrast, if the input to the RF Transmitter alternates between ‘1’ and ‘0’, the output from the RF Receiver is pretty much the same as the input to the transmitter.

clip_image004

Transmitting a constant logic 0 (Blue – Input, Yellow – Output)

clip_image006

Transmitting a constant logic 1 (Blue – Input, Yellow – Output)

clip_image008

Transmitting 500Hz square wave (Blue – Input, Yellow – Output)

· Common Ground – These RF modules will not work when both the transmitter and receiver share common ground. The output from the RF Receiver will be inverted if it shares the same ground as RF Transmitter. This also applies when both the transmitter and receiver are powered from the AC-DC adapter, even though they are using the different adapters.

3.0 The Resolution

After identifying the main causes of the problem, we can take necessary action to solve it. Basically, in order to have a solid wireless link by using the low cost solution, we need to take care of the following steps.

3.1 Antenna

The antenna can be made from a single core wire cut into the correct length. As a rule of thumb, the optimized antenna length is quarter the wavelength of the RF signal. In this example, we are using the 315MHz RF module and the optimized antenna length is around 23.8cm. For other frequency, we can calculate the antenna length by using the online calculator here: http://www.romandock.com/static/antennalength.html

Besides, the antenna should also be straightened and positioned in the upright position as illustrated in some of the pictures of PR16.

3.2 Power Supply

As discussed in the previous section, the power source of the RF Transmitter and Receiver cannot be shared. Both of them must use a separated power source with separate ground. The easiest way is to use two separate batteries for transmitter and receiver; or one of the boards uses an AC-DC adapter while another board uses battery as the power supply.

3.3 Protocol

The software protocol for the wireless communication has to be packetized to ensure the reliability of the wireless link. In this example, we will have 10 bytes of data in one packet. In other words, instead of sending the data one byte by one byte, the transmitter will need to send 10 bytes of data at once.

The content of the packet is as follow:

Byte 0 – 7 Byte 8 Byte 9 Byte 10
Sync Data (0x00) Header (0xAA) Data Checksum

· Sync Data (0x00) – As discussed earlier, the low cost RF module is not capable of transmitting / receiving a constant state of either ‘1’ or ‘0’. Thus, we need to transmit a sequence of 10101010 to get the RF Transmitter and Receiver in sync prior to transmitting the actual data. We choose 0x00 here is because it only has 1 high bit (stop bit) and 9 low bit (start bit + data byte). This will ease the syncing process between the transmitter and receiver.

· Header (0xAA) – The header is to indicate that the bytes after this will be the command byte.

· Data – This is the data that we want to send to the receiver board.

· Checksum – This byte is used for error checking. The value should be equal to Header + Data.

3.4 Repeated Transmission

The low cost wireless solution is best for application where the data is being transmitted continuously and repeatedly. For example, when we use the wireless module to turn on a relay, we can send the command to turn on the relay several times. Even though some of the packet might get lost during the transmission, the receiver can still process the command and turn on the relay as long as not all data were lost.

4.0 Examples

We have made several simple examples to demonstrate how to implement the wireless communication using low cost solution. All the examples are based on the DIY Project Set “PR16: Sending Data Using RF Module” and also the UC00A USB to UART Converter. The full source code can be downloaded from http://www.robothead2toe.com.my

4.1 Sending Data from MCU to MCU

The first example will demonstrate how to send data from a PIC microcontroller to another PIC microcontroller. The PR16 RF_TX board will act as a transmitter and the PR16 RF_RX will be the receiver.

clip_image010

DIY Project Set PR16: Sending Data Using RF Module

In this example, user can increase or decrease the number and send the data over to the receiver. The receiver will then display the received data on the 7 segment.

Please take note that the data will be packetized and sent to the receiver continuously in the main loop even though user does not press any button. This is to increase the reliability of the system. The code snippet below shows how we packetized and transmit the data.

clip_image012

Function to packetized and transmit the data for PIC MCU

At the receiving side, we use the polling method to check the data received from the UART until a valid packet is received. We will also make sure the checksum is received correctly. The function to read a packet of data is shown below:

clip_image014

Function to read a packet of data from the UART for PIC MCU

4.2 Sending Data from PC to MCU

The second example will demonstrate how to send data from PC to PIC microcontroller. This was exactly what we used to control the 2-Wheeled Balancing Robot in the previous issue. In this demonstration, the RF transmitter is connected to the PC via the UC00A USB to UART Converter. The PR16 RF_RX will be the receiver and it will display the data sent from the PC on the 7 segment. No modification is needed for the firmware in the PR16 RF_RX.

clip_image016

Components for sending data from PC to MCU

clip_image018

clip_image019

Connection from UC00A to RF Transmitter(need to use wire besides white color)

We have created a GUI in the PC to send data to MCU via the low cost wireless UART. When the button on the GUI is clicked, the number will be sent to PR16 RF_RX and displayed on the 7 segment.

clip_image021

GUI for sending data over the low cost wireless UART

The GUI was written in C# with Microsoft Dot Net Framework. The code used to packetized and transmit the data is shown below.

clip_image023

Function to packetized and transmit the data in C#

4.3 Sending Data from MCU to PC

In the third example, we will show you how to transmit data from PIC MCU to PC via the low cost wireless UART. This is extremely useful for applications such as remote data logging, sensor monitoring and etc. The PR16 RF_TX board will act as a transmitter and PC, receiver. No modification is needed for the firmware in PR16 RF_TX board. The RF Receiver is connected to the PC via UC00A USB to UART Converter.

clip_image025

Components for sending data from PC to MCU

clip_image026clip_image028

Connection from UC00A to RF Receiver. Get better pic try not to use white wires, kinda not clear.

The GUI used in the previous example can be reuse in this example. The GUI will display the data transmitted by PR16 RF_TX board. The code snippet to read the packetized data and compare the checksum is as below.

clip_image030Serial Port Data Received event handler to read the packetized data in C#

5.0 Summary

We know that good things do not come cheap and vice versa. Of course the low cost wireless UART does have some limitations such as:

· Unreliable – That’s why it only good for application with repeated transmission and when data integrity is not that critical.

· Slow – With baud rate of 1200bps, and a packet of data which consists of 10 bytes of data, we only have a useful data rate of 12 bytes per second.

· Unidirectional – The data can only be sent from the Transmitter to the Receiver but not vice versa.

Nevertheless, the low cost RF module is still capable of handling some basic wireless communication. This can be seen in our daily life application such as central locking system for automobile, remote control for auto gate, wireless doorbell and etc. If you any question or suggestion, please come to our technical forum to discuss, hope to see you there 🙂

References:

http://www.cytron.com.my/datasheet/WirelessDevice/RF_TX_User%27s_Manual.pdf

http://www.cytron.com.my/datasheet/WirelessDevice/RF_RX_User%27s_Manual.pdf

Buy

, , ,

Related Post

Jpeg

How to Make your Line Following Robot Faster?

Control Mobile Robot through WiFi with ESP-WiFi Shield (Arduino + Andriod)

image2

Let ESPresso thingSpeak for You

dsc00784 (1)

Lights Up Your Twitterland! :)

10 thoughts on “Low Cost Wireless UART

  1. Hi to all

    Now i am using a simple RF module with the Frequency range of 434MHz, interfacing with PIC controller.
    This controller is not having any communication protocol like UART /I2C. I want to send data through a port pin. Any one suggest how to implement communication protocol and data transmission and receiving in this RF module.

  2. I would like to use this for some remote temperature and humidity sensors, operated on batteries. But a constant transmission would drain the batteries quite fast. I am looking for a way to ‘shut down’ the device for a while and than wake it every 5 minutes or so to send the sensor values several times. Suggestions?

  3. hi
    i want to send data from mcu to pc. i have already 433Mhz RF link kit. but i dont know how to use. and is it possible that can i send data through the 433Mhz RF link kit to pc from mcu or not.

Leave a Reply

Your email address will not be published. Required fields are marked *