attiny flash memory versus sketch memory requirements

I am trying to figure out if my sketch will fit in an attiny85 dev. board. As I read the spec's., it has 8k flash, with 6k left after bootloader.

But when I look at the memory used at the bottom of the sketch, it talks about everything But flash.
It says my sketch uses

"Sketch uses 13282 bytes (43%) of program storage space. Maximum is 30720 bytes.
Global variables use 1025 bytes (50%) of dynamic memory, leaving 1023 bytes for local variables. Maximum is 2048 bytes."

Will someone explain to me how to figure out if it will fit ?

That first number (13282) is the flash memory used, which suggests it's not going to fit.

Blast. it is just a voltage divider and ssd1306 oled.
i moved all of the variables inside the loop function, but it doesn't show any change in global variable memory size.

Maybe I don't understand what a variable actually is.

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

Adafruit_SSD1306 display = Adafruit_SSD1306();    // Creates an Instance of the Adafruit_SSD1306 Object

void setup ()
{
  Serial.begin(9600);      // Initialize serial communications at 9600 bps
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // Selects Display Power Source Type(SWITCHCAPVCC or EXTERNALVCC). Doesn't work using EXTERNALVCC.
                                              //  initialize with the I2C addr 0x3C instead of 0x3D (for the 128x64).   
  display.clearDisplay();   // Clear the Display Buffer
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(16,2);
  display.setCursor(100,2);
  display.display();
}

void loop ()
{
  const int sensorPin = A0;  // Analog input pin that senses Vout
  float sensorValue = 0;       // sensorPin default value
  float Vin = 5;             // Input voltage
  float Vout = 0;            // Vout default value
  float Rref = 3000;          // Reference resistor's value in ohms
  float R = 0;               // Tested resistors default value
  float R1=0;

  
  sensorValue = analogRead(sensorPin);  // Read Vout on analog input pin A0 (Arduino can sense from 0-1023, 1023 is 5V)
  Vout = (Vin * sensorValue) / 1023;    // Convert Vout to volts
  R = Rref * (1 / ((Vin / Vout) - 1));  // Formula to calculate tested resistor's value
  Serial.print("R: ");                  
  Serial.println(R);                    // Give calculated resistance in Serial Monitor

  display.setTextSize(2);
  display.setTextColor(WHITE);

  display.setCursor(4,0);  // sets the Horizontal position at 6 pixels from the left side
  display.setCursor(4,17);  // sets the Horizontal position at 6 pixels from the left side
    
  R1=R/1000;

  if(R<1000){
    display.print("R= ");
    display.print(R,0);
    display.println(" ohms");
    display.display();
  }

  else
    {display.print("R = ");
    display.print(R1,2);
    display.println(" K");
    display.display();
    }
  
  display.clearDisplay();
  delay(5);

   delay(1000);                          // Delay in milliseconds between reeds
}

Any suggestions on how to shrinkafy it ? I don't need to have a serial connection, if that helps.

Oled libraries are huge. See if you can remove font tables.

ok. thanks. I will do some reading up.

Doesn't look good. Here's a dump of the "big" pieces of code ("avr-nm -SC -t decimal --size-sort *.elf")

00005822 00000100 T __vector_18
00001736 00000108 t Adafruit_SSD1306::fastSPIwrite(unsigned char) [clone .constprop.19]
00006074 00000116 T delay
00011970 00000122 T __floatunsisf
00006986 00000136 T Adafruit_GFX::drawFastHLine(int, int, int, unsigned int)
00007122 00000138 T Adafruit_GFX::drawFastVLine(int, int, int, unsigned int)
00002606 00000142 T HardwareSerial::write(unsigned char)
00001906 00000146 t Adafruit_SSD1306::ssd1306_command(unsigned char) [clone .constprop.17]
00005132 00000146 t Print::printNumber(unsigned long, unsigned char)
00006190 00000148 T __vector_16
00005922 00000152 T digitalWrite
00006826 00000160 T Adafruit_GFX::fillRect(int, int, int, int, unsigned int)
00001550 00000186 t TwoWire::endTransmission(unsigned char) [clone .constprop.24]
00006338 00000190 T Adafruit_GFX::drawRect(int, int, int, int, unsigned int)
00009744 00000200 t global constructors keyed to 65535_0_sketch_dec17a.ino.cpp.o.2416
00011468 00000204 T __addsf3x
00012374 00000210 T __mulsf3x
00011688 00000220 T __divsf3x
00006528 00000238 T Adafruit_GFX::drawLine(int, int, int, int, unsigned int)
00002052 00000260 t Adafruit_SSD1306::display() [clone .constprop.16]
00004298 00000316 T Adafruit_SSD1306::drawPixel(int, int, unsigned int)
00007358 00000340 T Adafruit_GFX::writeLine(int, int, int, int, unsigned int)
00004662 00000428 T Adafruit_GFX::write(unsigned char)
00005278 00000468 T Print::printFloat(double, unsigned char)
00009140 00000604 T __vector_24
00002910 00000692 T Adafruit_SSD1306::drawFastVLine(int, int, int, unsigned int)
00003602 00000696 T Adafruit_SSD1306::drawFastHLine(int, int, int, unsigned int)
00008072 00001068 T Adafruit_GFX::drawChar(int, int, unsigned char, unsigned int, unsigned int, unsigned char)
00000184 00001280 t font
00009944 00001396 T main

There are a bunch of functions in there that it's not obvious why they're present (line drawing?), but I expect they're buried pretty deeply and hard to remove. I was hoping that there would be several "font"-like tables you could eliminate by being more conservative with what you called, but I only see the one, and it's only about 1k...

thanks for looking into that. looks like i'm trying to fit 2 lbs of baloney into a 1 lb bag.
i'm wondering if u8glib might work better for me. i know almost nothing about it, but maybe it is smaller.

i will look into whether it can be used with oled. any thoughts ?

that looks like the wrong approach. i found an ssd1306 library that says it is made to be used with limited flash size, like the attiny.

i got the library installed and am trying to get it working in the sketch, but i see that the terms must be different in different libraries (like 'display'). when i say

ssd1306 display = ssd1306();

it asks for a type. i will try to find where somebody has made a sketch using this library and see what the terms are. but it looks as tho the bloated library problem is not insurmountable. i hope.

the things is, my little oled arduino ohmmeter will fit so nicely above my breadboard if i can use an attiny85 development board behind the oled. the whole package will be about the size of a postage stamp.

Hmm. that's a good find. It looks like the tiny library supports print(), so probably all you have to do is figure out the initialization. Have you tried the examples?

I have, but they don't seem very helpful.

while i was roaming around looking at different libraries someone mentioned the Micro USB Digispark Pro Development Board Kickstarter ATTiny167 For Arduino S2, which has 14.5k ram after bootloader install.

i wasn't aware that this board existed. i was aiming at using (and already purchased) the digispark attiny85 dev board. but that is the one with the severe ram problem.

I had watched a youtube video by Julian Ilett where he compared the different libraries for the ssd1306 oled. he showed the adafruit was the largest, followed by the u8glib, and one he had written which was very small.

but he showed that, for his sketch, the ram size using the u8glib was about 8.2k. i can live with that, so i just ordered 3 of these boards. we'll see.

but you were right, the adafruit library is huge.

I would like to thank you for helping me. It is so nice to talk with a knowledgeable person who doesn't feel the need to make me feel stupid.

1 Like

i'm wondering if u8glib might work better for me. i know almost nothing about it, but maybe it is smaller.

The u8g2 library is the current version. It uses much less RAM than the common Adafruit library, because it refreshes the screen by "pages". Pages are really subsections of the complete display. You essentially draw the same thing, multiple times. The library clips the drawing to each page and then sends that portion to the display. This is all-to-familiar trade-off between RAM usage and CPU time.

I suspect it would use less program space; it has many ways to reduce the font's footprint.

pratto:
I have, but they don't seem very helpful.

It depends on what you're trying to do. Ssd1306 library mainly has c-style api. It has some helper c++ classes, but most examples show how to control display in c-style.
And another thing: ssd1306 library is intended to work with lcd directly without any buffers.