1

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 array – Juraj Mar 2 '18 at 17:20
  • how big is the .h file? – Chad G Mar 2 '18 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 Mar 2 '18 at 17:26
  • 1
    @ChadG – it's about 140kb. – JeffThompson Mar 2 '18 at 17:27
  • 2
    how do you expect it to fit in 8KB worth of program space( thats what the ATtiny85 has) – Chad G Mar 2 '18 at 17:32
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 Mar 2 '18 at 17:47
3

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.

1

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 Mar 2 '18 at 19:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.