How to manage BYTE type.

Hi there.

I hope this is the right section :)

I want to send analogReads from an Arduino to another using wireless communication. Basically I'm using Nordic nRF24L01+ chips and the Mirf library let me send data via [u]byte array[/u] with this synthax:

byte data[2]
data[0] = B1000001;
data[1] = B1111111;
Mirf.send(data);

and in the receiver I can read data with:

byte data[2]
Mirf.getData(data);
Serial.println(data[0]);
Serial.println(data[1]);

but in this way I can't send values more than 2^8 bit per cell. So I wanna ask you how to send integer values with byte array beacuse I'm not very familiar with this variable type. I would also send always an array with 2 o n cell because I want to store and send different analogReads in different cells, something like: data[0] = analogRead(0); data[1] = analogRead(1); ..... .....

Any answer will be really appreciated. Thanks !

Have a look at the language reference for "highByte" and "lowByte"

:)

You mean something like:

SENDER

byte data[2]
int sensorValue = analogRead(A0);
word wordValue = word(sensorValue);
byte data[0] = highByte(wordValue);
byte data[1] = lowByte(wordValue);

RECEIVER

word temp = word(data[0],data[1]);
int sensorValue = temp;

Thanks.

Not quite. You should not be converting from int to word.

Int is a 2 byte signed value, ranging from -32768 to 32767. Word is a 2 byte unsigned value ranging from 0 to 65535.

Really, there's no point in converting from int to word. You can just transmit the int using the same method you are transferring the word with.

Thank you guys.

You rock 8)