Hello, I am trying to add 2 floats, an integer, and a single charachter -, to an char array. But so far it is not working with different functions.
Would anyone be nice enough to explain what is going wrong?
ss.getLat = 52.283199 and ss.getLng = 4.851055
The result what i am getting is this: 4.85114252.283130 ( lng is first then lat but no - or the integer value from randominteger=10;)
Walorda:
Hello, I am trying to add 2 floats, an integer, and a single charachter -, to an char array.
If the purpose is just to send a sequence of characters with Serial there is no need to build them into an array. Just send them with separate Serial.print() commands. The receiving device won't know the difference.
Robin2:
If the purpose is just to send a sequence of characters with Serial there is no need to build them into an array. Just send them with separate Serial.print() commands. The receiving device won't know the difference.
...R
Hai, i am trying to send it with the rf24 library to my raspberry so it can get the values separated by the - character. it just seemed like an easy way to do but clearly i was wrong -__-
strcpy(x,y) replaces x with y. If you are trying to build on ling character array of sequential items then use strcat(x,y) char x[] will be appended with y[].
You didn't list the expected result, so I'm guessing from the information in the OP.
You expect to have
52.2831994.85105510-
as your output
That would be:
dtostrf(ss.getLat(),8,6,tmp);
strcat(testarray,tmp);
dtostrf(ss.getLng(),7,6,tmp);
strcat(testarray,tmp);
itoa(randominteger,tmp,10);
strcat(testarray,tmp);
strcat(testarray,"-");
Serial.print(testarray);
Or like Robin2 said just Serial.print() each item individually. The pi will receive the same data.
Walorda:
Hai, i am trying to send it with the rf24 library to my raspberry so it can get the values separated by the - character. it just seemed like an easy way to do but clearly i was wrong -__-
For the RF24 I would put the data into an array or a struct