RF communication, half duplex, problem after responding.

Hello, this is my first time writing here.
I’ve searched a lot this week and haven’t found anything similar to what am i trying to do.
My project is this.

Components
1 arduino UNO R3 and 1 atmega328.
1 RF set (Tx and Rx) at 433MHz.
1 RF set at 315MHz.

My setup
Arduino - 433 Tx - 315 Rx (ID : Receiver)
Atmega328 - 315 Tx - 433 Rx (ID : Transmitter)

I want to send data from atmega to arduino, then arduino to process it and respond back to atmega.
So far, i’ve managed to send an array, check it if it is the corrent incoming data (and not noise) and send back another array. Atmega should get the incoming data, but nothing happens.

I use leds to signal receiving/transmitting and serial monitor at arduino’s side is reporting everything normal.
So i guess, my problem is either in the code (it’s the Transmitter/atmega328 code) or maybe the atmega Rx isn’t getting enough voltage.

Voltage range (measured between data pin and ground pin)
Atmega’s Tx - 0.04 to 1.2 V
Arduino’s Rx - 0.4 to 1.52 V
Arduino’s Tx - 0 to 1 V
Atmega’s Rx - 0.5 to 2.1 V

Transmitter code

#include <VirtualWire.h>

const int led_pin = 10;  //Trasmitter led
const int led_R = 8;  //Receiver led
const int receive_pin = 11;
const int transmit_pin = 12;
const char OK[7] = "all ok";
int ground_found = 0;

void setup()
{
  Serial.begin(9600);
  Serial.print("Start : ");
  pinMode(led_pin,OUTPUT);
  pinMode(led_R,OUTPUT);
   
  vw_set_tx_pin(transmit_pin);
  vw_set_rx_pin(receive_pin);

  vw_setup(2000);  // Bits per sec
  //vw_rx_start();   // Start the receiver PLL running
}

void loop()
{
  char msg[5] = {'c','h','e','c','k'};
  
  digitalWrite(led_pin, HIGH);  // Flash a light to show transmitting
  vw_send((uint8_t *)msg, 5);
  vw_wait_tx();  // Wait until the whole message is gone
  digitalWrite(led_pin, LOW);
  Serial.print(msg);
  delay(100);

  vw_rx_start();
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;
  vw_wait_rx_max(500);
  if (vw_get_message(buf, &buflen))  // Non-blocking
    {
	int i;

        digitalWrite(led_R, HIGH);  // Flash a light to show received good message
	for (i = 0; i < buflen; i++)
	{
            if(buf[i]==OK[i])
            {
              digitalWrite(3,HIGH);
              ground_found = ground_found + 1; //int for future use
              Serial.print(buf[i], DEC);
            }
            else
            {
              delay(5);
            }
	}
        digitalWrite(3,LOW);
        digitalWrite(led_R,LOW);
    }
  vw_rx_stop();
  Serial.println();
  
}

Receiver code

#include <VirtualWire.h>

const int led_pin = 6;
const int led1 = 7;
const int receive_pin = 11;
const int transmit_pin = 12;
const char msg[6]="check";
int j=0;

void setup()
{
  delay(1000);
  Serial.begin(9600);	// Debugging only
  Serial.println("setup");
  pinMode(led_pin,OUTPUT);
  // Initialise the IO and ISR
  vw_set_tx_pin(transmit_pin);
  vw_set_rx_pin(receive_pin);
  vw_setup(2000);	 // Bits per sec

  vw_rx_start();       // Start the receiver PLL running
}

void loop()
{
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;

  if (vw_get_message(buf, &buflen)) // Non-blocking
  {
    int i;

    digitalWrite(led_pin, HIGH); // Flash a light to show received good message
    // Message with a good checksum received, print it.
    Serial.print("Got: ");

    for (i = 0; i < buflen; i++)
    {
      if (buf[i]==msg[i])
      {
        Serial.print(buf[i], DEC);
        Serial.print(msg[i], DEC);
        Serial.print(' ');
        Serial.print(j);
        j=j+1;//check if message received is the one we want
        //j equals the length of checking array -1 (5chars+null)
      }
    }
    if(j==5)//if it is,then start transmitting back
    {
      char answ[7] = "all ok";
      digitalWrite(led1, HIGH); // Flash a light to show transmitting
      vw_send((uint8_t *)answ, 7);
      vw_wait_tx(); // Wait until the whole message is gone
      digitalWrite(led1, LOW);
      Serial.print(answ);
      j=0;
    }
    Serial.println();
    digitalWrite(led_pin, LOW);
  }
}

Which RF modules are you using ? A link to it or attach a photo please. Are they powered with 5V ?

In Europe, only the 433MHz is allowed. In the US, I think only the 315MHz is allowed.

Is your ATmega328 running at 16MHz ?

Is the led flashing at the ATmega328 that it did receive something ?

You wait 500ms, it should be long enough, but try making it 2 seconds.

How far apart are they ? Do you use an antenna ?

Erdin:
Which RF modules are you using ? A link to it or attach a photo please.
Are they powered with 5V ?

These i am using.
433 MHz
315 MHz

Powered by 5V.

Erdin:
In Europe, only the 433MHz is allowed.
In the US, I think only the 315MHz is allowed.

Don’t care about frequencies now, i’m just testing. Afterwards, i’ll just throw away the illegal one.

Erdin:
Is your ATmega328 running at 16MHz ?

Yes, its XTALs are connected to an 16 MHz crystal.

Erdin:
Is the led flashing at the ATmega328 that it did receive something ?

No, it is not flashing. The only way to get a feedback that the Atmega Rx is receiving something (but i don’t know what) is to use a voltometer and measure Data and Ground pins.

Erdin:
You wait 500ms, it should be long enough, but try making it 2 seconds.

I’ll try to increase the time.

Erdin:
How far apart are they ? Do you use an antenna ?

Atmega to arduino about 20 cm and each pair to Tx Rx about 10 cm. (check photo)
433 MHz has 16,5cm antenna and 315 MHz has 22,6 cm (more or less).

Green for Transmitter route, yellow for receiver route.

Thanks for the info and photo. Those cheapest Ebay modules use a normal signal, not inverted. You already use VirtualWire for normal signals, that's good.

You have a few things together. So you have to test them one by one. Do you have another Arduino board ? That would rule out any problems with the ATmega.

A breadboard can have bad contacts. If you set up a new test, also change the location on the breadboard if possible.

Could you add a decoupling capacitor at the ATmega 5V and GND of 100nF?

A few weeks ago, someone could not get the 315MHz modules working, but it did work with 433MHz.

Perhaps you can do a few test sketches. Very simple, don't test the data that is received, just print it to the serial monitor. - Arduino with TX 433MHz -> ATmega as RX - ATmega with TX 433MHz -> Arduino as RX And the same for 315MHz.

I know, it is some work and it takes time. But this way you will get (slowly) to the problem.

Thank you for the leads. Seems that my problem is that after receiving the message from Arduino, i wasn't waiting. I added a delay and everything seems to work. The Atmega Rx was receiving data, but it wasn't receiving the whole correct message, but just a part of it. I'm going to test it and see if my serial monitor reports everything as correct.

hi..

Im also doing the same thing.. but I'm using 2 rf module 433Mhz.. can you kindly tell me where you add the delay in the coding you given above..

regards

First of all, excuse me for replying speed :stuck_out_tongue:
By saying

deen:
but I’m using 2 rf module 433Mhz.

you mean 1 pair of 433 (1 Tx and 1 Rx for simplex communication) or 2 pairs ( Tx-A → Rx-B, Tx-B → Rx-A for duplex communication) ?
If it is the 2nd configuration, you might have problems, in case Tx-i and Rx-i (where i=A or B) are close to each other, due to same frequency.

I think the solution you seek, is the addition of a “delay(250)”, right before “if (j==5)”

 j=j+1;//check if message received is the one we want
        //j equals the length of checking array -1 (4chars+null)
      }
    }
    delay(250);
    if(j==3)//if incoming message is correct, then start transmitting back
    {
      for(repeat = 0; repeat < 2; repeat++)

Receiver’s code, line 48.