hi.... roughly, i have a sketch with large texts, and some numeric values stored in eeprom.. that barely doesn't fit in my arduino uno
as i want to make it fit i shrinked the texts all i could, and as it dindn't was enough now i want to shrink the numbers array, the numbers represent an outdoor temperature taken hourly... like...
... according documentation floats takes 4 bytes and ints take 2 bytes... and as i don't need too much precision for temps (no more than 100 C deg, with 2 decimals at most) i thougth to use an int and divide/multiply by 100... something like..
It would help if you looked at Arduino variable types. You will see the range of each type of variable and it should be obvious why there are different memory requirements.
Well, you didn't actually. You're running out of room in your Uno but you don't say which memory is running low and your snippet of code doesn't give us the full picture of what you're doing.
@Blackfin@anon57585045 yes i declared as f-strings ... actually i use vars and arrays of __FlashStringHelper * ... i have a lot of it and print them according the situation .... but that's not the problem really
well, i know i also can do it without printing anything.... but i was just curious why floats occupies more memory than ints in my arduino uno
AFAIK avr-gcc, the compiler, adheres to the IEEE754 definition of a single-precision float which is 32-bits.
You might be able to save some memory by going to fixed-point math using (not vouching, just found after a search...) a library like this or do it manually.
For sure, and sometimes the interface obscures the fixed point nature of the actual sensor readings. So if, for example, you have control over the sensor transmission, don't allow the sensor library to translate it to a float, find a way to get and transmit the actual sensor reading. IIRC, it might be the DS3231 that senses temperature in 1/4 degree steps, so the value is an integer scaled by 1/4 (e.g. the lowest two bits represent the fraction and the remaining upper bits, the integer portion. I believe it fits in an 'int' type which would be a 2 times saving of storage or transmission.
What do you mean by excess size?
An array of 24 ints will take 48 bytes and 24 floats will take 96 bytes.
That is if you change int into int16_t to specifically specific a 16 bit integer.
However as TheMemberFormerlyKnownAsAWOL cryptical points out without seeing all your code we don't stand a hope in hell of solving your problem.
@Grumpy_Mike when i compile the sketch the log window says something like (simplified):
Sketch uses 32120 bytes (101%) of flash space, max is 32000 bytes
ERROR compiling my_cool_sketch.ino
(not so cool actually...) you see the sketch don't fit in flash memory... by 'excess' i mean the difference between the flash capacity and the actual size of compiled sketch... here is an excess of 120 bytes
-- @Blackfin@anon57585045 interesting .... so ints in arduino uno are actually 8 bytes?.. or floats are... i dont know, i am confused o_Ô ... how can ints could be bigger than floats ??? ???
Sketch uses 8084 bytes (25%) of program storage space. Maximum is 32256 bytes.
Please show the full compiler output.
What version of IDE, are you using?
If you need help with your code - post your code including links to all external libraries.
Arrays of __FlashStringHelper* implies that you are generating the array at runtime using F(), might take slightly less code to store directly in PROGMEM at compile time.
Have you checked for duplicate text being used with the F() macro? The compiler does not automatically combine identical text when using F() like it does with text literals.