433 MHZ connection between two Arduino (nano,uno) fails after some time

Loading...

433 MHZ connection between two Arduino (nano,uno) fails after some time

The goal of this part of my project is to establish a wireless connection between an Arduino nano and an Arduino uno. For this I use 433 MHZ receiver and sender. The nano sends, the uno receives and prints. I have working code and the connection works and I can send, receive and print my message.
But at some point the Uno receives just a part of the message and after this point always receives (or prints) just this part of the message:
 
Nano (sender):
#include  
char *msg = "123456789123456789";

It is not always 2 digits, sometimes more are received.
I searched for errors. The nano is constantly sending and the uno flips to not receiving the whole message. So I reupload the code to the uno without modification and it works again for a few seconds/minutes, so I guess it's a problem at the receiving end.
Here is my code:
Sender(nano):
#include 
char *msg = "123456789123456789"

void setup()   {
 Serial.begin(9600);

 pinMode(7,OUTPUT);
 pinMode(5,OUTPUT);
 digitalWrite(5,LOW); //GND
 pinMode(6,OUTPUT)
 digitalWrite(6,HIGH); //5V
 vw_setup(5000);
 vw_set_tx_pin(7);
}

void loop()     {
 vw_send((uint8_t*)msg, strlen(msg));
 vw_wait_tx();
 delay(500);
}

Receiver(Uno):
#include 

int i;
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;

void setup() {

 Serial.begin(9600);
 pinMode(5,INPUT);
 pinMode(6,INPUT); // two data inputs, we use just one
 pinMode(7,OUTPUT);
 digitalWrite(7,LOW); //GND
 pinMode(4,OUTPUT);
 digitalWrite(4,HIGH); // 5V VCC
 vw_setup(5000);
 vw_set_rx_pin(6);
 vw_rx_start();
 Serial.println("Starting up");

}

void loop() {

 if(vw_get_message(buf,&buflen)) {
   for(i=0;i

Solutions/Answers:

Answer 1:

Regarding the hardware problem, there are some advices in the comments.
As you wrote, the solution is to reduce the bitrate at 2000 bps.

The remaining question is why the receiver always truncates the message (after a receiving error occurs). The answer is in the definition of the buflen parameter of the vw_get_message function. The page https://www.pjrc.com/teensy/td_libs_VirtualWire.html says:

"buflen" should have the array's maximum size upon input, and upon return the number of bytes actually copied is retured.

Therefore, when a transmission error occurs, the buflen variable returns a smaller number to inform you how many characters are received. If you do not reset the buflen variable to VW_MAX_MESSAGE_LEN before calling vw_get_message again, you are telling the library that you expect a smaller number of characters and the function respects that size (thinking that you have a smaller buffer).

In other words, if you want try to receive the full message after a transmission error occured, set the buflen variable to VW_MAX_MESSAGE_LEN before each call of the vw_get_message function.

Answer 2:

Those cheap 433 MHz RF modules can not handle a high bitrate. There are many different 433 MHz modules and the more expensive modules might be able to handle perhaps 10 kHz.
Every pulse from the receiver generates an interrupt. That means also the software has to be able to keep up with it.

For a basic Arduino board at 16 MHz (Arduino Uno, Nano, Leonardo, and so on) and the cheap RF modules the sweet spot is around 1 kHz to 2 kHz bps. The 2 kHz is a safe value.

The 433 MHz frequency requires in most countries that only 1/10 of the time a transmission might be active and the VirtualWire/RadioHead has overhead. That means that the resulting data speed with 2 kHz bps will be between 10 and 20 bytes per second.

The transceiver modules don't have all these (ridiculous) limitations. They can transmit data at a fast rate. Transceiver modules are for example nRF24L01+ modules, CC1101 modules, RFM69 modules, and so on.

Our Awesome Tools

References

Loading...