Sending a byte and/or byte array with RFM69

Hi all,

So I am using the RFM69 library and simply trying to (first) send a byte (numbers 0 through 5) from one radio to another. On the receiver I want to receive the byte, put it in a variable so I can decide what to do with it.

Once I have that, I want to send a byte array. The first byte is the same as above, a single number 0 through 5. The second byte is a number from 0 to 20 and on the receiving end I want to put it in a variable and use it to choose how long I "delay" to keep an LED on.

In the past I've converted the single byte to a char and sent that through the radio and then on the receiving end converted the single char back to an int by subtracting '0'. However, I was told that the RFM69 library sends the packets as bytes so it doesn't really make sense to go back and forth between chars and strings when I just want to send bytes in the first place.

So I tried just sending a single byte first, my sending code looks like the following. I removed all of the radio initialization code and more just to keep things simple and short to read:

byte message = 0;   //this is the outgoing byte to send to the receiver
//send it
message = 1;          //change the message to '1' to command the LED to turn on
radio.sendWithRetry(TONODEID, message, 1);

and then on the receiving end if I do this:

byte remote = 0;
remote = radio.DATA[0]; //the incoming remote command set to variable remote

Serial.print("remote variable sent: ");
Serial.println(remote);

//then I can check if the remote variable == 1 then do something etc

So you would expect, "remote variable sent: 1"

However, this results in the following being printed to the serial monitor--> "remote variable sent: 0"

If I change the message variable to '2' and I send that, I get: "remote variable sent: 109"

I'm confused! Any help would be greatly appreciated!

Thank you

You need to post your code.

Okay, here is the code in it's entirety.

This is the "remote" where two buttons can be pressed. The intent is for the one button to send a message that = 1, and the other button sends a message that = 2

See attachment as the code exceeds the allowed number of characters to post

feedback_sleep_test.ino (9.96 KB)

And this is the code for the "receiver." It should take that message and put it in a byte variable where the switch statement decides what to do:

You can see in the receiver code I put my Serialprint functions before the switch statement to see what was being received. This is where I get an output of 0 if the button was pressed that is supposed to result in 1. If the second button is pressed and a '2' is supposed to be sent, the serial monitor shows 109

Please see attached.

receiver_for_feedback_sleep_test.ino (5.8 KB)

FYI for those who are newbs trying to use the RFM69 library like me... apparently when you send the packet, you need to reference the array using pointers. My problem was that I was missing an & before my variable 'message'.

It should have looked like this:

radio.sendWithRetry(TONODEID, &message, 1);

when sending a single byte.

When sending an array of bytes, if my variable was message[5] then I could use it without the ampersand.

radio.sendWithRetry(TONODEID, message, 1);