Author Topic: I've run out of RAM because of DigiUSB. What can I do?  (Read 4624 times)

josh3736

  • Newbie
  • *
  • Posts: 1
I've run out of RAM because of DigiUSB. What can I do?
« on: January 17, 2013, 08:42:51 pm »
Exactly how much RAM does the DigiUSB library use?

Background:

I'm trying to use Adafruit's LPD8806 library to control a strip of individually addressable LEDs with 48 LEDs.  The strip is a SPI device.

At first, my project would not compile because the library makes references to the SPI library, which apparently does not work on a digispark.  I commented out all native SPI references from the library (it falls back to bitbanging), and it works fine.

However, I then added DigiUSB.h to my project, and my strip stopped working.  (Even though I didn't even call DigiUSB.begin();.)

After much trial an error, I discovered that it appears I ran out of RAM.  The LPD8806 library requires 3 bytes of memory per LED to track the RGB value of each.  48 * 3 = 144 bytes of memory, and the ATtiny85 has 512 bytes.  

Reducing the number of controlled LEDs to 28 (with DigiUSB loaded) got it working again (uses 84 bytes).  However, I'm obviously not really happy with half my strip out.

Also, I've noticed that even if i turn the LPD8806 all the way down to just 1 LED, the DigiUSB device does not show up on my computer -- but one issue at a time.

I ultimately need to communicate with the computer so it can send commands (received from the network) to turn the LED strip.  What can I do?
« Last Edit: January 17, 2013, 09:05:43 pm by josh3736 »

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
I\'ve run out of RAM because of DigiUSB. What can I do?
« Reply #1 on: January 17, 2013, 10:13:14 pm »
@josh3736

Unfortunately, there is not an easy answer here - any solution will require modifications to the DigiUSB library, which without a doubt is very much a first version release. We plan to improve it as soon as our time allows and we invite any community members to improve it as well. It seems reasonable that another 60+ bytes of RAM can be squeezed out of it.

As far as the two libraries not working together, like the combination of any libraries this could be many things, but likely is related to both libraries use of interrupts (or rather DigiUSB turning them off) or timers (again DigiUSB turns them off) - these are at the top of our list for improvements to the DigiUSB library.

We\'ll be announcing some rewards soon for community members that help make these improvements (and will be rewarding those who do in the meantime none-the-less) and we\'ll continue improving the software and libraries at a steady pace as soon as we have the Kickstarter orders out the door (about 60% there!).

semicolo

  • Full Member
  • ***
  • Posts: 137
I\'ve run out of RAM because of DigiUSB. What can I do?
« Reply #2 on: January 18, 2013, 10:32:17 am »
What about using only 2, 1.5 or 1 byte to store the colors instead of 3?
Sure you\'ll lose in accuracy but it should work until you can claim RAM some other way.
For example you could use a 1 byte pattern, the 2 higher bits for red, next 3 for green and last 3 for blue, then just before sending the data through SPI you expand it back to 3 bytes.
Something like :
unsigned char red = data & 0xC0; // keep only 2 higher bits of data
red >>= 1; // shift one bit to the right
unsigned char green = data & 0x38;
green <<= 1; // shift one bit to the left
unsigned char blue = data & 0x7;
blue <<= 4;

then send red, green and blue to the strip
You get 4 different levels of red and 8 levels of green and blue.
« Last Edit: January 18, 2013, 10:33:18 am by semicolo »

semicolo

  • Full Member
  • ***
  • Posts: 137
I\'ve run out of RAM because of DigiUSB. What can I do?
« Reply #3 on: January 18, 2013, 10:35:01 am »
Also if you always drive the strips with your computer, you don\'t need to keep the values in the digispark ram.