Question regarding EtherCard Library - Ethernet::Buffer


I've been using Arduinos for just about over a year now. Until recently my use was fairly basic, but now I've started to upgrade my project with a EtherCard and therefore started using the appropriate library.

I'm using a Arduino Nano with a ENC28J60.

After a while I figured out how it works and now I've got a tiny webserver that accepts some buttons and text fields. However, I've run into limitations soon. I guess my webcontent got too large (only a handfull of html lines!) so I tried to increase the reserved buffer for it - with mixed results.

This being the command in question:

byte Ethernet::buffer[700];

I've seen examples on the internet where people used 1000, even with a comment that this should be increased, where the HTML code to become more.

I've found that I can't increase the buffer any larger than 850, otherwise my Arduino will not process the code as expected ( not accepting anything from the ethernet, no serial output or reboots).

Can someone explain to me how this buffer correlates to other code or my HW ?
Do I need to have a "larger" Arduino ? Or declare less arrays or something similar ?

Any help appreciated!
PS: I've not placed my whole code here on purpose, since it is not finished...

Free-up RAM - move fixed strings to PROGMEM.

(of course, you may already have done this, but I don't know because you haven't posted your code)

Can someone explain to me how this buffer correlates to other code or my HW ?

Your Arduino has a fixed amount of SRAM. The heap, the stack, and all string literals go in that space. The heap includes all global and local variables, including that huge buffer.

Do I need to have a "larger" Arduino ?

Maybe. Maybe not. Depends on what your code looks like, and what your intents are.

Or declare less arrays or something similar ?

Yes. The "or something" part, most likely.

Since this thread is stale, probably the OP did stop its investigation, but since I can contribute, here is my thought :

Of course PaulS is correct as usual. But maybe it won't help a lot the OP. The size of the Ethernet buffer is the RAM space that is kept to hold the Ethernet packet.

That packet is about 50 bytes of overhead and a variable payload (your HTTP page or request).

So if you see some errors about 850, the good move would be to lower the buffer size. It also depends on which sketch/function you use on your board. HTTP server is more hungry than a simple UDP application.

And it is indeed important to avoid putting strings (web pages parts) in RAM, which is why you'll see things like PROGMEM or PSTR everywhere.

Another interesting but complex option is to use one of the latest addition of the Ethercard library, called "stashes". Here the idea is to move the buffer from the AVR memory to the ENC28J60 memory. Of course this is quite tricky, and the documentation of the Ethercard was never really completed. Similarly to EtherShield (the original library), EtherCard is now not longer really supported by anyone. Look for example at for some discussion.

One reason to have it high is that in theory an Ethernet packet could be as big as 1500 byte, so 700 was kind of a usable compromise. But decreasing to 500 should be no problem, and allow you to use the RAM for other usages.

I didn't test yet an application with 500 bytes instead of 700, but I saw sketches where it was reduced to 300, apparently without issue.