Transmitting data via RF

I have two unos set up on as transmitter and one as receiver. using iHaosapce 433MHz RF Wireless Transmitter and Receiver Module.

Transmitter using default pin 12.
Receiver using default pin 11.

Transmission appears to me to be sending correctly but receiving does not.

Any and all help welcome.

Transmitter code:

#include <RH_ASK.h>

float rCount = 0;
struct package {
    float Counter =2.0;
    float test =1.0;
};
typedef struct package Package;
Package data;

RH_ASK rf_driver;

void setup() {

    Serial.begin(9600);
    delay(500);
    rf_driver.init();

}

void loop() {
      rCount++;

    if (rCount == 1000) {
        rCount = 0;
    };

    data.Counter = rCount;
    data.test = rCount + 10;
    rf_driver.send((uint8_t*)&data, sizeof(data));
    rf_driver.waitPacketSent();
    Serial.print("Counter=");
    Serial.println(data.Counter);
    Serial.print("test=");
    Serial.println(data.test);
    delay(1000);

}

Transmitter output

Counter=190.00
test=200.00
Counter=191.00
test=201.00
Counter=192.00
test=202.00
Counter=193.00
test=203.00
Counter=194.00
test=204.00

Receiver Code:

#include <RH_ASK.h>

RH_ASK rf_driver;

struct wsData {
	float Counter ;
	float test ;
};

typedef struct  wsData  wsdata;
wsdata data;


void setup() {
	rf_driver.init();
	Serial.begin(9600);
	delay(1000);

		}

void loop() {

	uint8_t buf[sizeof(data)];
	uint8_t buflen = sizeof(data);


	if (rf_driver.recv((uint8_t*)&buf, &buflen)); {
		memcpy(&data, &buf, buflen);
		Serial.print("COUNTER=");
		Serial.println(  data.Counter);
		Serial.print("TEST=");
		Serial.println(data.test);
		delay(1000);

	}
		  
}

Receiver output:

COUNTER=0.00
TEST=0.00
COUNTER=0.00
TEST=0.00
COUNTER=0.00
TEST=0.00
COUNTER=0.00
TEST=0.00

Over 60 and learning new hobbies in lockdown so any idiot proof advice welcome.!

Hi Gahlrichs,

welcome to the forum. Well done posting code in your first post as code-sections.
There exist so many 433MHz-Rf-modules. I tried to find your by googling iHaosapce 433MHz RF Wireless but had no luck. Where have you bought the modules?
Can you provide a datasheet?

best regards Stefan

perhaps check rf_driver.available() before calling rf_driver.recv()?

Lose the semicolon after the 'if'

	if (rf_driver.recv((uint8_t*)&buf, &buflen)); {

I have looked up the example at GitHub. Usually the initialisation of a "driver"-library wants to have specified the IO-pins that are used. The example-code shows this

RH_ASK driver;// RH_ASK driver(2000, 2, 4, 5);

the out-commented line has some parameters. The used line has no parameters at all.
I guess with thiss call you have to use the standard-hardware-SPI of the Arduino.

So did you connect the RFmodules to the hardware-SPIIO-Pins?

And the example does a check if the initialisation faile

if (!driver.init())         Serial.println("init failed");}

add this to your code to realy determine if sending is working

best regards Stefan

Yes, almost... I think RH library assigns default pins if none are specified, but I don't think they are the SPI pins. In any case, I remember that it is well documented in the source code.

The easy way to test correct program operation is to leave out the RF transmitter and receiver, and connect the two Arduinos with two wires (TX to RX and GND to GND).

Hi All thanks for the prompt replies my response below

##########StaphanL38 ############# Purchased from

but unable to find datasheet.

Added initialization check and serial show "working!"

	if (!rf_driver.init())
		Serial.println("init failed");
		else
		Serial.println("Worked !");

#########pcbbc ############

changed code to

void loop() {

	uint8_t buf[sizeof(data)];
	uint8_t buflen = sizeof(data);

	if (rf_driver.available())
	
	{
		rf_driver.recv((uint8_t*)&buf, &buflen);
		memcpy(&data, &buf, buflen);
			Serial.print("COUNTER=");
			Serial.println(data.Counter);
			Serial.print("TEST=");
			Serial.println(data.test);
			delay(1000);

	}
}

No Data/output to serial so now more confused.

####### aarg ###########

removed semicolon as suggested (see code above)

##############TO ALL##############

Checking on pins as sugested.

You do not need to use the available() function. I don't know if it actually hurts to use it, but anyway it's not necessary. Here is the receive example directly from the RH library:

void loop()
{
    uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
    uint8_t buflen = sizeof(buf);
 
    if (driver.recv(buf, &buflen)) // Non-blocking
    {
        int i;
 
        // Message with a good checksum received, dump it.
        driver.printBuffer("Got:", buf, buflen);
    }
}

HUMBLE APOLOGISES TO ALL*****

After trying all that you have suggested I finally got there by testing a direct connection as suggested by jremington and rather embarrassingly traced it to a bad connection on the receiver.!!

Thanks all for your constructive advice and help.

Hi gahlrichs,

tinkering with microcontrollers includes making all kinds of basic electrical connections. It is the well known experience of everybody here to have a faulty electrical connection now and then. It is the well known experience that you don't think about a faulty electrical connection at first. Though it is a good idea to check them if something behaves strange.

best regards Stefan