I have an ATtiny and am trying to send a very large byte array stored in a separate .h
file over SoftwareSerial:
for (int i=0; i<numElements; i++) {
softSerial.println(myList[i]);
}
I imagine it will very slow, which is fine, but I'm getting a cryptic error when compiling:
Firmware.ino.elf section `.data' will not fit in region `text'
It seems that this is due to the println()
command running out of memory for some reason – if I comment out the println()
command everything works fine. How to fix this?
-
perhaps, if you remove the line where you use the array, compiler optimizes the code removing the not used arrayJuraj– Juraj ♦2018年03月02日 17:20:52 +00:00Commented Mar 2, 2018 at 17:20
-
how big is the .h file?Chad G– Chad G2018年03月02日 17:26:33 +00:00Commented Mar 2, 2018 at 17:26
-
@Juraj – not sure I understand? The array is what's getting sent over serial, which is the point of my program.JeffThompson– JeffThompson2018年03月02日 17:26:40 +00:00Commented Mar 2, 2018 at 17:26
-
1@ChadG – it's about 140kb.JeffThompson– JeffThompson2018年03月02日 17:27:20 +00:00Commented Mar 2, 2018 at 17:27
-
2how do you expect it to fit in 8KB worth of program space( thats what the ATtiny85 has)Chad G– Chad G2018年03月02日 17:32:05 +00:00Commented Mar 2, 2018 at 17:32
3 Answers 3
Your sketch doesn't fit into program memory of the ATtiny. If you comment out the println
of the array, the compiler evaluates that the array is not used and doesn't attach it to the program. Then the program fits into memory.
EDIT
Chad suggests some good alternatives below, if you need to store more data than flash or PROGMEM
will allow.
-
Thanks – 140kb is the ascii representation of all those bytes. I had read that it gets crunched down to binary on compile, and was trying to see if it fit. Didn't realize the array would be ignored until invoked by
println()
.JeffThompson– JeffThompson2018年03月02日 17:47:09 +00:00Commented Mar 2, 2018 at 17:47
There is not enough room in program memory for 140KB. ATiny only has 8KB for the whole program. So there is no way to fix this with your current hardware.
Options-
add a storage device (SD card, sram module, others....) where you can store the data, and then read it in small chunks and send it out
possibly use a arduino mega. It has 256KB of program space. you will still have to make sure you are not trying to store the whole byte array in an array since that would get stored in sram (which there is still only 8KB) but it could again to written in chunks to avoid this problem.
The ATTiny only has a limited amount of RAM. A lot less that flash-memory.
Using a normal array, the entire contents of the array are placed into RAM (during initialization). Which is very limited.
I'd suggest, looking into PROGMEM. This is a way to read the data directly from the flash-memory.
-
Looking at the comments, this will still not fit the 140kb you want. But the ATTiny85 only has 512 bytes of RAM, but a whole 8KB of Flash/Program memory.Gerben– Gerben2018年03月02日 19:54:02 +00:00Commented Mar 2, 2018 at 19:54