An Arduino webserver

posted 14 Mar 2011, 02:03 by JO3RI Read Grab Share
This weekend I started experimenting with the Arduino Ethernet Shield. This shield gives your ARduino a connection the "cloud" or maybe more simple, your own network. Lot's of stuff you can do with this thing. It even has a Micro SD slot, so you can put files on it or store data your logging.So I started figuring out how this thing works, by making a simple web page. You can see the result in the picture. Nothing fancy, but it has a picture embedded. And just by doing that, I had to start thinking about memory consumption. Because this little web page you see, eats almost all the memory the Arduino has and that isn't all that much.

Flash Memory32 KB (ATmega328) of which 0.5 KB used by bootloader
SRAM2 KB (ATmega328)
EEPROM1 KB (ATmega328)

Now, because eating memory isn't the best thing to do, I stared looking for a way to solve the problem. The things The arduino uses its SRAM to operate and when you set up a webpage within your script, all your bytes or going straight the SRAM. when you have a little gif file of 800 bytes, well then your 2048 bytes are down to 1248. Minus the HTML you need to set up the web page and you'll have nothing left but like 17 bytes. Not so good.

putting all those bytes into Flash memory would be much better, but still when you start the web server, and you visit the page, your arduino has to put all those HTML en gif code into its SRAM for the page to show up. So still no go. And then we found a solution, What if we feed that HTML code from our Flash Memory, peace by peace to our SRAM. Then We will need (let's say maybe 200 bytes) in which we put a piece of HTML, get it to the web client, wipe it and put the the next piece HTML into it and so on. You can read about this on the Arduino site.

Yeah, that works :-). Now We can do the same thing with our GIF file (which has to be in base64 code to get it embedded in the sketch). This reminds me on the way you have to feed your LCD 16x2 with character art. Doing this with a GIF file, means we will have to cut the image in 8 and we will be using an array of "pointers" (only 8 places => 1 byte). I'm not that far, but I'll get to it. Next to all of this I'll have to start a new project: An Arduino Ethernet Shield setup Page. (I'll make 2 versions: simply and fancy and the latter will use more memory)

I have 2 forum posts on this, go check them:,55064.0.html,55044.0.html