RF modules can't send numbers with virutalWire

I'm doing this:

int msg = 1000; // test number
vw_send(msg);
vw_wait_tx();

But i'm getting this compiling error:
Invalid conversion from 'int' to 'uint8_t*'

Can't send numbers, only text!

Can somebody help me?

You can't send a value of 1000 in a single byte (which is what 'uint8_t*' is about).An int value would need to be split into an high order byte and a low order byte in order to transfer it using that method. I'd declare a couple of byte variables and make one the high order by integer dividing it by 256 and the low order using modulo 256 (%). And then send one after the other and reassemble it at the far end.

:frowning: didn't understand.

I tried some codes that i found but got nothing...

I'm not good with bytes and this things, if I could make a function to send 16 variables of a array and recognize every single one at the receiver, would be soo good.

if I could make a function to send 16 variables of a array and recognize every single one at the receiver, would be soo good.

What kind of array? Sent as binary data or string data?

All arrays are values between 0 and 1023, only this. I want to receive and transform this values in int numbers to control, for example, servos and led's brightness...

:slight_smile:

You're trying to squash a quart into a pint pot in simple terms. I'm not feeling nice enough to write the code for you.......

If the values aren't too important, you could divide them by 4 so they will fit in a byte value and if needed multiply them back up at the far end.

The vars must be very precisive. I don't know how it works, but gonna try to find something.

Never thought this would be so hard.

Geek by name, but not by nature ?

Heres a start :

http://arduino.cc/en/Reference/Byte

Ok, sorry by the questions, gonna try here.

Basically, I have to convert a number from 0 to 255 to byte, send it by virtualWire, read it with receiver and then 'unbyte' it to number?

There are two handy functions, lowByte and highByte that will transform an integer into two bytes.

On the receiving end, simply multiply the high byte by 255 and add the low byte.

It really isn't that hard.

If the values are in an array, it's even simpler. The memory where the data is stored is byte sized. Create a byte pointer, and point to the array. Send the pointer, with a length of twice the number of elements in the array.

Receive the data, as bytes, and store it using byte pointer notation, into space reserved for an integer array.

No need to do any manipulation of the bytes.

Thanks. I'm reading arduino reference, I'll try to make this work!

I didn't understand so much what you said so I tried this:

int numb = 200;
int var;
String texto;
void setup () {
Serial.begin(9600);
}
void loop () {
texto = "";
for (int i=0; i<6; i++) {
var = bitRead(numb, i);
texto += var;
}
Serial.println(texto);
}

It converts 200 to text, in bytes, I think.

If this is possible to send text: const char *msg = "text";
Why I can't send the String that I generated? like: const char *msg = texto;

sorry if I'm annoying :frowning:

200 = 0b11001000

for (int i=0; i<6; i++) {
 var = bitRead(numb, i);
 texto += var;
}

When i = 0, 1, 2, 4, and 5, var will be 0. When i = 3, var will be 1. Neither 0 or 1 are printable characters. So, adding them to a string is pretty meaningless.

The string texto ends up containing NULL, NULL, 1 (not '1'), NULL, NULL, NULL.

When you print the string, the printing starts on the left, and terminates with the first NULL. Oh, that didn't take long.

If you want to convert 200 to '2', '0', '0', NULL, in a string, then texto should be a char array (char texto[4];), and you should use the itoa() function to convert the integer to an ASCII array of characters.

I am trying here, but don't works!

const char *msg = "test";

I can send a text, but how I'm gonna send a single piece of a number, like 2 2 5 ?

Can't understand, sorry :frowning:

char numAsStg[10];
int num = 200;

itoa(num, numAsStg, 10);

numAsStg will now contain '2', '0', '0', and a NULL terminator.

I can send a text, but how I'm gonna send a single piece of a number, like 2 2 5 ?

Which piece of that number do you want to send? Why do you want to send only a piece of it?

Thank you so much, I'm receiving data here, but now I have to work in how to put the numbers togheter to form a int number to flash a led

Ok I tried SO MANY times, but I can't!

Look: I received data and transformed it to a String. Now I can't convert it to int to analogWrite and LED.
I tried like it too:
for (i = 0; i < buflen; i++) {
var = char(buf*);*

  • int a = atoi(var);*
  • }*
  • }*
    But I can't :frowning:
    Could somebody help me?
    Sorry by asking so many times, I'm not lazy, but I really got not results doing this, if somebody helps me I can understand, like the transmitter code...
    :slight_smile:

you must atoi the whole buffer at once ... assuming there is only one number in the buf

char buf[20] = "123";

void setup()
{
  Serial.begin(9600);
  Serial.print(atoi(buf));
}

loop()
{
}

Thanks, I did it!

:D:D

Thanks to everyone!

Here's the video: Arduino 433.92mhz rf modules test - YouTube :smiley:

Thanks so much!