4

I'm working on a project with a Digispark ATTiny85, that performs keystrokes using the DigisparkKeyboard library (https://github.com/digistump/DigisparkArduinoIntegration/tree/master/libraries/DigisparkKeyboard). Besides the DigiKeyboard, I also import EEPROM.h.

My own code is only about 150 lines, I've cut down the size following a number of online guides, trying to avoid larger data types and so on. The Digispark is limited to ~6kB and the imported DigiKeyboard library takes up a little more that 5.4kB. In total the compiled project takes up about 7kB, which exceeds the boards capacity.

From the DigiKeyboard library I only use DigiKeyboard.sendKeyStroke() and DigiKeyboard.print() (with about only ten different characters). So I assume there is a lot of unused code I could remove, but I don't know how to approach this. I use Visual Studio Code and PlatformIO.

How could I reduce the size of the used DigisparkKeyboard library?

emma.makes
  • 105
  • 6

2 Answers2

4

With input from @EdgarBonet, I looked into the functions used and it turned out that the String() function, I used once in my code, takes up about 3kB of space in the compiled program.

I ended up removing the line with String() and kept the imported DigiKeyboard library as it is.

emma.makes
  • 105
  • 6
1

The compiler/linker will remove unused functions/methods automatically, so I doubt you can save memory by removing unused functions/methods yourself.

However, you could possibly gain by:

  • Removing the calls of check functions/methods when you know the result will be always false, true, or always the same number, string or data type in general.
  • Removing (parts of) functions/methods which are related to physical or logical functionality you never use. Like e.g. if, case statements that will never apply).
  • Prevent using an entire class (e.g. String) (see second comment of Emma Makes below).
Michel Keijzers
  • 13,014
  • 7
  • 41
  • 58