RF24 Transceiver Code Issue

Hi Guys,

I'm having trouble transmitting data through a nRF24L01+ transceiver.

The offending part of the code is below and I have been receiving the following error: "Invalid conversion from 'long unsigned int' to 'const void'"
ino: In function 'void loop()':
64: error: invalid conversion from 'long unsigned int' to 'const void*'
64: error: initializing argument 1 of 'bool RF24::write(const void*, uint8_t)'

Code:

unsigned long logTime; // Time to be logged

void loop()
{
 logTime = millis() - startTime;
 radio.write(logTime, sizeof(logTime));
}

I've read the bool RF::write example here: RF24: RF24 Class Reference and I seem to be using the correct parameters.

Any help would be greatly appreciated.

Thanks,
Ben

Hi Ben

Try this.

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

I think the RF24 write method needs the first parameter passed by address (in C programming language terms). The "&" does this.

Passing by address means the write method can work with variables of different types, and the second parameter tells write how many bytes the variable takes up in memory, so they can be accessed properly.

Regards

Ray

and I seem to be using the correct parameters.

Given that the write function looks like:

bool 	write (const void *buf, uint8_t len)

How can you assert that logTime is of the correct type? Does unsigned long look anything like const void *?

Not that I’m picking; I just want to understand your thought process, in order to be able to explain where you went wrong.

That method requires a pointer and a length. Your code is wrong because it is providing an integer not a pointer.

One possible reason for your confusion is that many examples use an array of integers for the message and then pass the array variable to the method. It happens that an array variable is syntactically equivalent to a pointer, so this works fine. But when you change from message from an array to a simple type, this is no longer a pointer so you need to take its address via the & operator.