Saturday, February 18, 2017

LiteSerialLogger: Zero SRAM Serial Logging

Last week, I talked about Arduino library memory use - and pointed out that the Serial library, in particular, is entirely wasteful for the purpose of simply writing log messages out to the serial port.

What's one to do about this?  Well, one can do many things, but what I chose to do is to write my own serial logging library - that uses zero SRAM except when actually writing messages to the serial port!

This isn't the first time I've written something along these lines.  Every few years, I seem to find myself writing yet another serial output library for some reason or other, and serial UARTs are pretty boring to bang bits into at this point.  They're slightly more exciting if they have a FIFO bolted on and a high speed clock, but not by much.

In any case - take a look at this!  A basic Arduino sketch uses 9 bytes of dynamic memory or SRAM (for the millisecond timer), and with an awful lot of serial logging, I also use a mere 9 bytes!


What's this library?  How did I write it?  And how can you use it?  Read on!

Saturday, February 11, 2017

Common Arduino Library SRAM Use

I've been playing with Arduino for a few months now, and one of the things I've found incredibly frustrating is just how much dynamic/global memory (SRAM) most of the common libraries use - the standard Serial library uses nearly 200 bytes of precious RAM, always and forever, just to print a single log message, and a lot of others aren't that much better.

Further, advice about Arduino memory pressure tends towards the handwavy "Well... don't use globals, and use the F() macro..." side of things - which, while accurate, is missing some very important information for understanding what is happening and how you can resolve the issues.

Here's a particularly bad example of what I'm talking about.  With literally nothing done but some libraries initialized, this code is using 1101/2048 bytes of RAM - 53%, and I haven't done a single useful thing yet!


I'm going to dive into library memory use in some depth, look at a few examples, and profile some commonly used libraries!  Read on if you're interested!

Saturday, February 4, 2017

Building a Button Box: Technical Discussion

My daughter (23 months old) likes pressing buttons and anything involving lights ("yight!").  I had some time off this winter - and some parts to build something I call a "Button Box."  And what, realistically, is both a toy that can grow with her, and a subtle way to teach low level programming when she's older (if she's at all interested).  Because nobody is learning C in schools anymore, and C still matters.

This box contains an Arduino Uno, a 20x4 LCD, a few NeoPixel strips, a bunch of buttons, some LEDs, a battery and power supply, and the supporting wiring mess to make it all work - entirely hand soldered, and certainly one of a kind!


I'm doing two posts on this.  You've found the "highly technical discussion" post - this will be useful if you happen to want to build something similar, or find out what I did, in rather substantial detail.  This post also includes lessons learned - places I wasted time, had to rework things, or would just do things differently if I were to do it again.

If you're simply interested in what the build process looked like, you may be more interested in my other post, which is a (somewhat) shorter description of the build process.  This post includes that content as well, so there's no real point in reading both unless you want to.

In any case, if you want the gory technical details, read on!