Comunicação sem fio entre PC e Arduino para exibição de mensagens (Parte 20/23)

Wireless communication between PC and Arduino to display messages (Part 20/23)

It is common to use screens in railway stations, airports, bus stops and other public places to display messages or alerts. Just like in the railway station, display boards are installed on the platform to show the alert of a train arriving at the platform and show the carriage numbers at the specific location on the platform. Similar displays are used in airports and bus stops to display useful information to travelers. Even in banks and offices, displays are used to show the current token number or other relevant customer information. These display cards obtain the information to be displayed on a computer. Often, the computer and the monitor board are connected via a cable for data transmission.

The wired connection between the computer and the display board is sufficient and viable until the message is sent to a single display unit. Like a bank teller, the wired connection between the computer and the token display board is no longer expensive due to the need for short wire, and it is not very complex as only one display board needs to be connected to the computer. This is not the case with display boards installed at railway stations and airports. The cost of installing a wired connection becomes more expensive and complex in this case. Therefore, the computer and video cards need to be connected wirelessly.

Protótipo de circuito lateral do PC para comunicação de dados RF com PC

Fig. 1: PC side circuit prototype for RF data communication with PC

This project shows a similar wireless transmission of message from a computer to the display circuits using 434 MHz RF module. The RF module has a range between 50-60 meters and can be extended to 300-350 meters using an antenna and increasing transmission power.

Therefore, this low-cost project can be installed in public places to connect multiple display cards to one computer. A computer cannot interact directly with the RF module, so it must connect through the RF module using an Arduino board.

Required components

Mr. No. Required components Amount
1 RF Rx Module (434Mhz) 1
two RF Tx Module (434Mhz) 1
3 Desktop PC with Arduino software 1
4 LCD 1
5 1K pot 1
6 10K resistor 1
7 Arduino pro mini development board two
8 Battery – 9V two
9 Test board two
10 Connecting wires

Diagrama de blocos de comunicação de dados RF de PC para Arduino

Figure 2: PC to Arduino RF Data Communication Block Diagram

Circuit Connections

The data to be transmitted to the display units is passed through the serial monitor on the PC. To connect PC to RF, first PC is connected to Arduino board using USB cable. The RF transmitter interfaces directly with the Arduino by connecting its serial input pin (pin 2) to pin 12 of the Arduino Pro Mini and an antenna connected to pin 4 of the module. In the receiver display unit, an RF receiver is connected to another Arduino Pro Mini with serial output pin (pin 2) connected to pin 11 of the Arduino board on the receiver side and an antenna connected to pin 8 of the RF module. An LCD is connected to the Arduino board on the receiver side to display the transmitted messages. The 16X2 LCD display is connected to the Arduino board by connecting its data pins to pins 7 to 4 of the Arduino board. The RS and E pins of the LCD are connected to pins 3 and 2 of the Arduino Pro Mini, respectively. LCD RW pin is grounded.

LCD Arduino UNO
LOL 3
R.W. GRND
AND two
D7,D6,D5,D4 7,6,5,4 respectively

The standard code library for interfacing Arduino UNO and Arduino Pro Mini is used in the project to program the LCD with the board.

How the circuit works

The characters that must be transmitted are passed from the PC's serial monitor. These characters are read by the Arduino board using the USB connection. The character read by the microcontroller remains in the buffer. The VirtualWire library is used in the program code to transmit the buffer characters over RF. The library allows transmitting only one serial character at a time. The characters in the buffer first need to be stored in an array, and each element in the array must be serially eliminated one by one.

On the receiver side, the character buffer is detected by the RF receiver and passed serially to the Arduino Pro Mini on the receiver side. The Arduino Pro Mini on the receiver side has the built-in program code to fetch the character buffer into an array and convert each character element into a respective integer representation. The entire character representation is passed to the 16X2 LCD for message display.

Protótipo de Circuito Arduino para comunicação de dados RF com PC

Fig. 3: Arduino circuit prototype for RF data communication with PC

Programming Guide

On the transmitter side Arduino, first, the VirtualWire library is imported to facilitate interfacing with the RF module.

#include

An LED is connected to pin 13 to indicate serial transmission in progress. Thus, a variable “ledpin” is declared and assigned to pin 13 of the Arduino. The variable “MsgData” is declared to store reading characters and the array “MsgcharAR” is declared to store multiple characters before serial transmission. Some global variables – “length” to store the message length, “data_available” to check data availability and a counter “i” are initialized.

A setup function is called, where ledpin is set to output mode using the pinMode function, the system baud rate is set to 9600 bits per second using the Serial.begin function, and the vw_setup function is used to set the baud rate. RF serial transmission transmission to 2,000 bits per second.

A loop function is called, within which the first length variable is initialized to 0 and the serial data is checked if available using the Serial.available function. If serial data is available, it is read using the Serial.read function and stored in the MsgcharAR array. The length counter is incremented and data_available is set to 1 for boolean logic. The code block is repeated in a While loop until serial data is available.

If data is available, the dat_available flag variable is left with a Boolean setting of 1, then the message stored in the MsgcharAR array is serially sent to the buffer using the Serial.print function.

The message stored in the buffer must be sent serially in RF. The led that indicates transmission in progress is turned on by sending a HIGH logic to the ledpin. The message is sent serially in RF using the vw_send function, where the message characters are first converted to unsigned character format. vw_wait_tx is used to wait until the entire message is transmitted. When the transmission ends, the ledpin receives a logic LOW to turn off the LED of the ongoing transmission.

The data_available is set to 0 and each element of the MsgcharAR array is set to 0 as the default value.

available_data = 0;

This ends the Arduino code on the transmitter side

On the receiver side Arduino, the program code first imports the required standard libraries. LiquidCrystal.h is imported to interface with the LCD and the VirtualWire library is imported to read the serial input from the RF receiver. Pins 2 to 7 are mapped to the LCD of the liquid crystal object.

The pin 13 where the transmission progress indicator LED is connected is assigned to the ledpin variable and two variables – “Sensor1Data” to capture the message in entire form and “Sensor1CharMsg” to store the character representation of the message to be displayed are declared.

A setup function is called where the Arduino baud rate is set to 9600 bits per second using the Serial.begin function. The LCD object is initialized in 16X2 mode and initial messages are displayed on the LCD. The pin connected to the led and the pin connected to RS and RW are set to output mode using the pinMode function.

The RF transmitter and receiver module does not have a Push To Talk pin. They are inactive when no data is present to transmit or receive respectively. Therefore, vw_set_ptt_inverted(true) is used to set the push to talk polarity and request the receiver to continue receiving data after fetching the first character. The baud rate for serial input is set to 2000 bits per second using the vw_setup function. Data reception is started using vw_rx_start .

A loop function is called within which the “buf” array to read the serial buffer and the “buflen” variable to store the buffer length are declared.

The character buffer is detected using the vw_get_message function, if present, an “i” counter is initialized and the LED connected to pin 13 is turned on sending a HIGH on pin 13 to indicate successful detection of the character buffer.

The character buffer is stored in the Sensor1CharMsg array using the for loop with the counter initialized.

The null character is detected in the buffer stream so that no junk values ​​go to the LCD display. The characters received from the buffer are converted to the integer value and stored in the “Sensor1Data” variable.

The variable value along with the relevant strings included is passed to the microcontroller buffer and passed to the LCD for display in a presentable format.

This ends the loop function and the Arduino code on the receiver side.

Project source code

###


 #include

 // LED's

 const int ledPin = 13;

 int MsgData;

 //int Sensor2Data;

 char MsgcharAR(40);

 int length, data_available;

 int i;
 void setup {

 // PinModes

 //LED

 pinMode(ledPin,OUTPUT);

 // for debugging

 Serial.begin(9600);

 // VirtualWire setup

 vw_setup(2000); // Bits per sec

 }
 void setup {

 // PinModes

 // LED

 pinMode(ledPin,OUTPUT);

 // for debugging

 Serial.begin(9600);

 // VirtualWire setup
 
vw_setup(2000); // Bits per sec

 }
 MsgcharAR(length) = Serial.read ;

 length++;

 delay(100);

 data_available = 1;

 }
 // Convert integer data to Char array directly

 // itoa(data,Sensor1CharMsg,10);

 if(data_available == 1)

 {

 // DEBUG

 Serial.print(" Sending data : ");

 Serial.println(MsgcharAR);

 //Serial.println(" ");

 delay(1000);

 // END DEBUG
 digitalWrite(13, true); // Turn on a light to show transmitting

 vw_send((uint8_t *) MsgcharAR, length);

 vw_wait_tx ; // Wait until the entire message is gone

 digitalWrite(13, false); // Turn off a light after transmission

 delay(200);

 for(i = 0 ; i < 40 ; i++)

 {

 MsgcharAR (i) = 0;

 }
 }

 } // END void loop...

 #include

 #include

 LiquidCrystal lcd(2, 3, 4, 5, 6, 7);

 // LED's

 int ledPin = 13;

 // Sensors

 int Sensor1Data;
 // RF Transmission container

 char Sensor1CharMsg(4);

 void setup {

 Serial.begin(9600);

 lcd.begin(16, 2);

 lcd.print("ENGINEERS GARAGE");

 lcd.setCursor(0, 1);

 // sets the digital pin as output

 pinMode(ledPin, OUTPUT);

 pinMode(9, OUTPUT);
 
pinMode(8, OUTPUT);
 //VirtualWire

 // Initialize the IO and ISR

 // Required for DR3100

 vw_set_ptt_inverted(true);

 // Bits per sec

 vw_setup(2000);

 // Start the receiver PLL running

 vw_rx_start ;

 } // END void setup
 void loop {

 uint8_t buf(VW_MAX_MESSAGE_LEN);

 uint8_t buflen = VW_MAX_MESSAGE_LEN;

 // Non-blocking

 if (vw_get_message(buf, &buflen))

 {
 int i;

 // Turn on a light to show received good message

 digitalWrite(13, true);

 // Message with a good checksum received, dump it.

 for (i = 0; i < buflen; i++)
 {

 // Fill Sensor1CharMsg Char array with corresponding

 // chars from buffer.

 Sensor1CharMsg(i) = char(buf(i));

 }
 // Null terminate the char array

 // This needs to be done otherwise problems will occur

 // when the incoming messages have fewer digits than the

 // one before.

 Sensor1CharMsg(buflen) = '';
 
// Convert Sensor1CharMsg Char array to integer

 Sensor1Data = atoi(Sensor1CharMsg);
 // DEBUG

 Serial.print("Sensor 1: ");

 Serial.println(Sensor1Data);

 lcd.setCursor(0, 2);

 lcd.print("Temperature =");

 lcd.print(Sensor1Data); // change the analog out value:

 if(Sensor1Data > 50){

 digitalWrite(9,HIGH);

 delay(2000);

 }
 digitalWrite(9,LOW);

 }

 } 

###

Circuit diagrams

Circuit Diagram-PC-Arduino-RF-Data Communication

Project video

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.