Go Down

Topic: RF modules can't send numbers with virutalWire (Read 2834 times) previous topic - next topic

Geek Ionizado

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?

pluggy

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.  

http://pluggy.is-a-geek.com/index.html

Geek Ionizado

:( 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.

PaulS

Quote
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?

Geek Ionizado

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...

:)

pluggy

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.
http://pluggy.is-a-geek.com/index.html

Geek Ionizado

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.

pluggy

Geek by name, but not by nature ?  

Heres a start :

http://arduino.cc/en/Reference/Byte
http://pluggy.is-a-geek.com/index.html

Geek Ionizado

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?

PaulS

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.

Geek Ionizado

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

Geek Ionizado

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 :(

PaulS

#12
Jan 09, 2011, 06:24 pm Last Edit: Jan 09, 2011, 06:24 pm by PaulS Reason: 1
200 = 0b11001000

Code: [Select]
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.

Geek Ionizado

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 :(

PaulS

Code: [Select]
char numAsStg[10];
int num = 200;

itoa(num, numAsStg, 10);

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

Quote
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?

Go Up