Tuesday, October 8, 2013

Sending floats using VirtualWire

We have a problem when we want to send floats using Virtual Wire.If you read the previous tutorials, and you tryed to send floats, you probably got ? .Arduino haven`t got enought power for using all functions with floats. Some functions like sscanf or sprintf are implanted but with out all the functions. You can send strings, ints but not floats because the hardware isn't enought powerfull to suport this part of the function.

 What can we  do?

Well, insted of sending floats we can convert the data into an string, send it and then, in the receiver, convert into a float again . This will be very easy using this function

dtostrf (double __val, signed char __width, unsigned char __prec, char *__s);

For more information: http://www.nongnu.org/avr-libc/user-manual/group__avr__stdlib.html#ga060c998e77fb5fc0d3168b3ce8771d42

In the receiver when we get the string we have to use the following lines of code:

char floatbuf[32]; // make this at least big enough for the whole string
stringwithfloat.toCharArray(floatbuf, sizeof(floatbuf));
float f = atof(floatbuf);


  1. Can you give a code example?

  2. Very interesting article is quite informative. I love the virtual development. Especially news about cloud servers storing information. Thank you for sharing
    Richard Brown data room services