0
Offline
Full Member
Karma: 0
Posts: 102
Arduino rocks
|
 |
« on: January 09, 2011, 08:44:41 am » |
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
Edison Member
Karma: 8
Posts: 1988
|
 |
« Reply #1 on: January 09, 2011, 09:31:10 am » |
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
Full Member
Karma: 0
Posts: 102
Arduino rocks
|
 |
« Reply #2 on: January 09, 2011, 09:42:16 am » |
 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
Brattain Member
Karma: 316
Posts: 35566
Seattle, WA USA
|
 |
« Reply #3 on: January 09, 2011, 09:49:18 am » |
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
Full Member
Karma: 0
Posts: 102
Arduino rocks
|
 |
« Reply #4 on: January 09, 2011, 10:18:10 am » |
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... 
|
|
|
|
|
Logged
|
|
|
|
|
Lancashire, UK
Offline
Edison Member
Karma: 8
Posts: 1988
|
 |
« Reply #5 on: January 09, 2011, 10:25:30 am » |
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
Full Member
Karma: 0
Posts: 102
Arduino rocks
|
 |
« Reply #6 on: January 09, 2011, 10:32:11 am » |
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
Edison Member
Karma: 8
Posts: 1988
|
 |
« Reply #7 on: January 09, 2011, 10:38:08 am » |
Geek by name, but not by nature ? Heres a start : http://arduino.cc/en/Reference/Byte
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 102
Arduino rocks
|
 |
« Reply #8 on: January 09, 2011, 10:48:00 am » |
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
Brattain Member
Karma: 316
Posts: 35566
Seattle, WA USA
|
 |
« Reply #9 on: January 09, 2011, 11:08:56 am » |
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
Full Member
Karma: 0
Posts: 102
Arduino rocks
|
 |
« Reply #10 on: January 09, 2011, 11:17:39 am » |
Thanks. I'm reading arduino reference, I'll try to make this work!
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 102
Arduino rocks
|
 |
« Reply #11 on: January 09, 2011, 11:53:04 am » |
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 
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 316
Posts: 35566
Seattle, WA USA
|
 |
« Reply #12 on: January 09, 2011, 12:24:17 pm » |
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.
|
|
|
|
« Last Edit: January 09, 2011, 12:24:38 pm by PaulS »
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 102
Arduino rocks
|
 |
« Reply #13 on: January 09, 2011, 01:26:10 pm » |
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 
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 316
Posts: 35566
Seattle, WA USA
|
 |
« Reply #14 on: January 09, 2011, 01:33:17 pm » |
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?
|
|
|
|
|
Logged
|
|
|
|
|
|