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.
the location same , length of data same. is there way avoid loop here or float string conversion?
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 stringthis 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
Post a Comment