views:

901

answers:

6

I want to store a shitload of data onto my Arduino whith ATmega168/328 Controller, but unfortunately there's only 256KB / 512KB of EEPROM storage.

My idea is to make use of an compression algorithm to strip down the size. But well, my knowledge on compression algorithms is quite low and my search for ready-to-use libraries failed.

So, has anybody had experience with that and can recommend me a good way to optimize the storage size?

+5  A: 

You might have a look at the LZO algorithm, which is designed to be lightweight. I don't know whether there are any implementations for the AVR system, but it might be something you could implement yourself.

You may be somewhat misinformed about the amount of storage available in EEPROM on your chip though; according to the datasheet I have the EEPROM sizes are:

ATmega48P: 256
ATmega88P: 512
ATmega168P: 512
ATmega256P: 1024

Note that those values are in bytes, not KB as you mention in your question. This is not, by any measure, a "shitload".

Greg Hewgill
LZO apparently needs 8 or 64 KB of memory during compression, which may be a problem on these processors
fvu
I guess it depends on what the application is; the question does not state whether the data will be compressed by the Arduino, or compressed by something else and *decompressed* by the Arduino. I had assumed the decompression case.
Greg Hewgill
thanks for your suggestion. Sorry, true sure, I mixed up the EEPROM sizes, Greg is right. In true as well actually I need just the decompression part. well I'll give it a try..
RngTng
+2  A: 

A NASA study here (Postscript)

A repost of 1989 article on LZW here

Keep it simple and perform analysis of the cost/payout of adding compression. This includes time and effort, complexity, resource usage, data compressibility, etc.

pst
+6  A: 

AVRs only have a few kilobytes of EEPROM at the most, and very few have many more than 64K Flash (no standard Arduinos do).

If you are needing to store something and seldom modify, for instance an image, you could try using the Flash as there is much more space there to work with. For simple images, some crude RLE encoding would go a long way.

Compressing anything more random, for instance logged data, audio, etc, will take a tremendous amount of overhead for the AVR, you will have better luck getting a serial EEPROM chip to hold this data. Arduino's site has a page on interfacing with a 64K chip, which sounds . If you want more than that, look at interfacing with a SD card with SPI, for instance in this audio shield

Nick T
+1  A: 

An algorithm something like LZSS would probably be a good choice for an embedded platform. They are simple algorithms, and don't need much memory.

LZS is one I'm familiar with. It uses a 2 kB dictionary for compression and decompression (the dictionary is the most recent 2 kB of the uncompressed data stream). LZS has been patented by HiFn, however. I'm not sure what is the current status of the patents.

But I see that an ATmega328, used on recent Arduinos, only has 512 bytes to 2 kB SRAM, so maybe even LZS is too big for it. I'm sure you could use a variant with a smaller dictionary, but I'm not sure what compression ratios you'd achieve.

Craig McQueen
+1  A: 

You might also want to take a look at LZJB, being very short, simple, and lightweight: http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/uts/common/os/compress.c

Also, FastLZ might be worth a look. It gets better compression ratios than LZJB and has pretty minimal memory requirements for decompression: http://www.fastlz.org/

James Snyder
A: 

http://cmsadler.googlepages.com/

Might run on a 328

C. Sadler and M. Martonosi, “Data Compression Algorithms for Energy-Constrained Devices in Delay Tolerant Networks,” Proceedings of the ACM Conference on Embedded Networked Sensor Systems (SenSys) 2006, November 2006. .pdf. S-LZW Source for MSPGCC: slzw.tar.gz. Updated 10 March 2007.

rmorgans