Pages: [1] 2   Go Down
Author Topic: RF modules can't send numbers with virutalWire  (Read 2417 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Full Member
***
Karma: 0
Posts: 102
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Lancashire, UK
Offline Offline
Edison Member
*
Karma: 9
Posts: 1991
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.  

Logged


0
Offline Offline
Full Member
***
Karma: 0
Posts: 102
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

smiley-sad 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.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Full Member
***
Karma: 0
Posts: 102
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

smiley
Logged

Lancashire, UK
Offline Offline
Edison Member
*
Karma: 9
Posts: 1991
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


0
Offline Offline
Full Member
***
Karma: 0
Posts: 102
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Lancashire, UK
Offline Offline
Edison Member
*
Karma: 9
Posts: 1991
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Geek by name, but not by nature ?  

Heres a start :

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


0
Offline Offline
Full Member
***
Karma: 0
Posts: 102
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Full Member
***
Karma: 0
Posts: 102
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Full Member
***
Karma: 0
Posts: 102
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley-sad
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

200 = 0b11001000

Code:
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]smiley-wink, and you should use the itoa() function to convert the integer to an ASCII array of characters.
« Last Edit: January 09, 2011, 12:24:38 pm by PaulS » Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 102
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley-sad
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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?
Logged

Pages: [1] 2   Go Up
Jump to: