Copying a float into a uint8_t array efficiently


i putting uint8_t array payload xbees , reading data sensor in uint8_t array.  this array copied payload loop this.

code: [select]

ds2438 hum1(&onewire, tempserial);                    //call sensor
dtostrf(hum1.readhum(),5, 1, dtostrfbuffer);         //read humidity(float) array buffer
humidity_string = dtostrfbuffer;                             // coppy string
for (  int j = 0; j < 6; j++)
       payload[9+j] = humidity_string.charat(j);


the location same , length of data same.  is there way avoid loop here or float string conversion?

code: [select]
humidity_string = dtostrfbuffer;                             // coppy string
this not copy string. (wastefully) copies string. big difference, , unnecessary.

what doing string representation of humidity on other end?

it might better send humidity value in binary, , reconstruct float on other end.


Arduino Forum > Using Arduino > Programming Questions > Copying a float into a uint8_t array efficiently


arduino

Comments

Popular posts from this blog

Thread: PKI Client 5.00 install (for eToken Pro)

ATmega2560-Arduino Pin Mapping

Crossfader Arduino Tutorial