How do I send some data with NRF905? (modules working, just a software question)

Hi, y'all!
I have set up two arduinos with a nrf905 on each. Using Zak Kemble's nrf905 wireless serial link example, it works like a charm.
But after searching everywhere for some time, I cannot find any example where DATA is sendt with Arduino/NRF905, all examples I have found are for sending a fixed text ("hello world") etc.
Can anyone point me in the right direction?

I want to make a data structure (or what you pros call them):

struct dataStruct {
int temperature;
int alarm;
int humidity
}myData;

and in the loop fill it with data:

temperature= sensor blah.blah
alarm=0;
humidity= sensor blah.blah

And with the NRF24 with the RF24 library I can use simply

radio.write( &myData, sizeof(myData) );

and there it goes.
Do you pros know if sending data this simple is possible with the nrf905 module?

Thanks,
Tore Stabell Kulo,
Norway

Post a simple program that illustrates how you send data with the nRF905. I am only familiar with the nRF24L01+.

If it is just serial data then have a look at the examples in Serial Input Basics - simple reliable ways to receive data. It should be easy to figure out the corresponding code to send data.

...R

thank you for the reply.
I guess someone out there are using NRF905 modules to send data from sensors, and I am hoping one of them will help me out.
Oddly, or typically, the RadioHead library example for the NRF905 is only sending text, too. ("hello world").

The NRF24 modules work really well, but the 905 has ten times more transmitting power and a much lower frequency, probably allowing the signals to pass through walls and trees more easily. But again I want to send some data, not "hello world":wink:

R,
Tore

Do you pros know if sending data this simple is possible with the nrf905 module?

With radiohead nrf905 I do not see why the standard instruction with a byte cast will not work. You won't harm anything to try.

RH_NRF905 nrf905;
nrf905.send((uint8_t*)&data, sizeof(data));

I believe that the radiohead library uses common methods across the devices, and when I used the syntax above with RH NRF69 and that radio unit, all was well.

EDIT: corrected typo "unit8_t*"

am I supposed to change the unit8_t* part into something?

#include <SPI.h>
#include <RH_NRF905.h>

RH_NRF905 nrf905;

struct dataStruct {
  int temp;
  int humidity;
  } myData;

  
void setup() 
{
  Serial.begin(9600);
 
  if (!nrf905.init())
    Serial.println("init failed");
 
}


void loop()
{
 myData.temp=20;
 myData.humidity=50;
 

 nrf905.send((unit8_t*)&myData, sizeof(myData)); 


  delay(400);
}

Now it says “unit8_t* was not declared”, etc.

this

nrf905.send(&myData, sizeof(myData));

halts as well, saying there is no matching function for call to..

now I think I understand that the data is supposed to be in the const uint8_t * format.

So how can I get the data struct thing to be in that format? Or can it be done at all?

torestabell:
thank you for the reply.
I guess someone out there are using NRF905 modules to send data from sensors, and I am hoping one of them will help me out.

How about posting a link to the documentation for the Radiohead library that you are using?

Help us to help you.

...R

Sorry, I should have done that.

http://www.airspayce.com/mikem/arduino/RadioHead/classRH__NRF905.html

And it says

bool send (const uint8_t *data, uint8_t len)

Zak Kembles nrf905 library has this when it comes to sending:

uint8_t nRF905_TX(uint32_t sendTo, void* data, uint8_t len, nRF905_nextmode_t nextMode);

https://github.com/zkemble/nRF905/blob/master/arduino/nRF905/src/nRF905.h

In the Radiohead examples one is called nrf905_client.pde

It includes the line

nrf905.send(data, sizeof(data));

which suggests that sending is exactly the same as with an nRF24. Drawing from your Original Post that suggests

nrf905.send( &myData, sizeof(myData) );

...R

I tried, but it tells me

No matching function for call to RH_NRF905::Send(dataStruct*,unsigned int)

And this is the data:

struct dataStruct {
  int temp;
  int humidity;
  } myData;

and more specifically:

"C:\Users\acer\Documents\Arduino\libraries\RadioHead/RH_NRF905.h:347:10: note: virtual bool RH_NRF905::send(const uint8_t*, uint8_t)

bool send(const uint8_t* data, uint8_t len);

^

C:\Users\acer\Documents\Arduino\libraries\RadioHead/RH_NRF905.h:347:10: note: no known conversion for argument 1 from 'dataStruct*' to 'const uint8_t* {aka const unsigned char*}'

Now it says “unit8_t* was not declared”, etc.

There was a typo in my first posting. Use uint8_t* for the byte cast, which RadioHead requires for the sending of the struct. This compiles and should be received with an equivalent struct in the receiving sketch.

#include <SPI.h>
#include <RH_NRF905.h>

RH_NRF905 nrf905;

struct dataStruct {
  int temp;
  int humidity;
  } myData;

  
void setup() 
{
  Serial.begin(9600);
 
  if (!nrf905.init())
    Serial.println("init failed");
 
}


void loop()
{
 myData.temp=20;
 myData.humidity=50;
 

 nrf905.send((uint8_t*)&myData, sizeof(myData)); 


  delay(400);
}

"uint" in stead of "unit", of course;)
Now it actually compiles!
I will try to figure out the receiving part!

In the receiver, it seems that it does not go into the same kind of "data", but in a buffer:

bool RH_NRF905::recv	(uint8_t * 	buf, uint8_t * len)

and:

"If there is a valid message available, copy it to buf and return true else return false."

Is there much hassle to get something meaningful out of that "buf" and magically convert it into the data struct thing I have in the transmitter?

In the receiver you need code like this to read the bytes into the declared struct myDatya

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

rf905.recv((uint8_t*)(&myData), &buflen))

You, Sir, are a genious wizard and magician! Now I can send doubles, longs and whatever from one nrf905 to the other.
That saves my day, week, month and year! You have no idea how much time I have spent trying to figure that out.

Than you so much for your super help!

T

I'm glad you worked it out.

Unfortunately different libraries have slightly different syntax. VirtualWire, and the follow on RadioHead use the byte cast wth

xxx.send((uint8_t*)&dataToSend, sizeof(dataToSend))

I think that the TMRh20 version of the RF24 library and the ManiacBug RF24 library used with the nRF24L01 radios use

radio.write(&dataToSend, sizeof(dataToSend))

On the receive, you can use memcpy to transfer the bytes from the standard library receive buffer into the data structure you want, or receive directly to the memory address of the data structure.

thank you so much, the sollution you came up with works very well.

T