Text section exceeds available space in board

I am trying print voltage and temperature value which first i am converting to string and then printing on oled but getting error text section exceeds available space in board

But when i tried assigning value directly to string array it is printing properly but when assigning to float and converting it to string it is showing error.

#include <Tiny4kOLED.h>
extern "C" void __cxa_pure_virtual() { while (1); }
   char vtg[5] ; // Example voltage value
char temp[5] ;
   const DCfont *currentFont = FONT8X16P;
void setup() {

  oled.begin(128, 64, sizeof(tiny4koled_init_128x64br), tiny4koled_init_128x64br);
  oled.clear();
  oled.setFont(currentFont);
 oled.on();
}

void loop() 
{
  float voltage = 23.5;

  // Convert voltage to string and append "V"
  dtostrf(voltage, 4, 2, vtg);  // Convert float to string with 2 decimal places
  strcat(vtg, "V");             // Append "V" to the voltage string

  float temperature = 56;
  dtostrf(temperature, 4, 2, temp);       // Convert temperature to string with 2 decimal places
  strcat(temp, "\xB0C");                  // Append "°C" to the temperature string

  // Update the display with the new values
  oled.setCursor(0, 1);
  oled.print("            "); // Clear previous value (adjust length as needed)
  oled.setCursor(0, 1);
  oled.print(vtg);

  oled.setCursor(0, 3);
  oled.print("            "); // Clear previous value (adjust length as needed)
  oled.setCursor(0, 3);
  oled.print(temp);

  delay(1000); // Update every second (adjust as needed)
}
 
char temp[5] ;

This char array can hold a string of 4 characters plus the '\0' terminator

  dtostrf(temperature, 4, 2, temp);       // Convert temperature to string with 2 decimal places
  strcat(temp, "\xB0C");                  // Append "°C" to the temperature string

How many characters are you putting in it ?

I want 4 characters like T = 00.0 I have remove strcat function now but facing same issue

Please show a error output in full, using a code tags

"C:\\Users\\ADMIN\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\4.8.1-arduino5/bin/avr-size" -A "C:\\Users\\ADMIN\\AppData\\Local\\Temp\\arduino\\sketches\\01B4D97254A38420510A05AC7B2EA1D7/oled.ino.elf"
Sketch uses 7360 bytes (122%) of program storage space. Maximum is 6012 bytes.
Sketch too big; see https://support.arduino.cc/hc/en-us/articles/360013825179 for tips on reducing it.
Global variables use 346 bytes of dynamic memory.
text section exceeds available space in board

Compilation error: text section exceeds available space in board

Which board (or processor) are your compiling for? Your problem is that the code is too big for the processor that you're using.

You have a very small processor for such a project. If it weren't for a special library for the OLED, you would have no chance of running it at all, except by choosing a different board.

In any case, you need to make sure that the code takes up as little space as possible.

Using a float math bloats the code a lot. You need to get rid of float variables and any functions that use them.
The same applies to the String class

I am using ATtiny88 board

The board storage space could be increased up to 8192 bytes, If you will get rid a bootloader.

Can you tell what can i do to increase storage space

If you are using Spence Konde's ATTinyCore you can select the processor with no bootloader.

You will need a programmer to program the board over SPI (ICSP).

Upload the code using a ICSP programmer rather than USB port.
https://docs.arduino.cc/retired/boards/arduino-isp/

But I recommend you try to edit the code first, it is most probable you wont need to play with bootloader after removing the floats from the code.

My job here is reading temperature value and voltage value through ADC and display it on lcd but for now i am assigning value for temperature and voltage but i don't have ntc sensor and voltage pot for practical demo so how i can change my code can you help in that?

If you need a float with a fixed number of decimal places, you can easily replace the floats with integers.
Let's say you need values with two decimal places. Then you can easily use integers instead by multiplying your values by one hundred:

27.55 = > 2755

Use the integers anywhere in your code. And when you need to print this value, you will print the integer and the fractional part separately:

// printing x= 2755 as 27.55
Serial.print(x/100);
Serial.print(".");
Serial.println(x % 100);

If I remember correct, I already suggested this method to you when you asked about float output to OLED

I am trying to do like above method and then also it is acquiring more space

@revajd123 - YouTube channel @upir_upir has some ATtiny85/OLED videos. He speaks very fast, so use ClosedCaption and PAUSE when watching his videos.

When I compiled Post #1 for ATtiny88 I had 90% usage (not 122%, as you did)... and an error about the escape sequence.

C:\Users\user\AppData\Local\Temp\.arduinoIDE-unsaved2024427-8044-b4kua5.pmvfe\sketch_may27a\sketch_may27a.ino: In function 'void loop()':
C:\Users\user\AppData\Local\Temp\.arduinoIDE-unsaved2024427-8044-b4kua5.pmvfe\sketch_may27a\sketch_may27a.ino:26:16: warning: hex escape sequence out of range
   strcat(temp, "\xB0C");             // Append "°C" to the temperature string
                ^~~~~~~
Sketch uses 6102 bytes (90%) of program storage space. Maximum is 6780 bytes.
Global variables use 258 bytes (50%) of dynamic memory, leaving 254 bytes for local variables. Maximum is 512 bytes.

If oled.print() inherits with all the power of the .print class, which it appears to do - I tested on a wokwi example. Then just...

float test = 128.6401;

oled.print(test,4);

Bit-mapped displays are small microcontrollers are not a good combination.
I'm sure your program would work fine with a character mode display.

#include <Tiny4kOLED.h>

/* Standard ASCII 8x16 proportional font */
const uint8_t My_font8x16 [] PROGMEM = {
  0x00,0x00,
  0x30,0x30, // . 14
  0xE0,0x10,0x08,0x08,0x10,0xE0,
  0x0F,0x10,0x20,0x20,0x10,0x0F, // 0 16

  0x10,0x10,0xF8,0x00,0x00,
  0x20,0x20,0x3F,0x20,0x20, // 1 17

  0x70,0x08,0x08,0x08,0x88,0x70,
  0x30,0x28,0x24,0x22,0x21,0x30, // 2 18

  0x30,0x08,0x88,0x88,0x48,0x30,
  0x18,0x20,0x20,0x20,0x11,0x0E, // 3 19

  0x00,0xC0,0x20,0x10,0xF8,0x00,
  0x07,0x04,0x24,0x24,0x3F,0x24, // 4 20

  0xF8,0x08,0x88,0x88,0x08,0x08,
  0x19,0x21,0x20,0x20,0x11,0x0E, // 5 21

  0xE0,0x10,0x88,0x88,0x18,0x00,
  0x0F,0x11,0x20,0x20,0x11,0x0E, // 6 22

  0x38,0x08,0x08,0xC8,0x38,0x08,
  0x00,0x00,0x3F,0x00,0x00,0x00, // 7 23

  0x70,0x88,0x08,0x08,0x88,0x70,
  0x1C,0x22,0x21,0x21,0x22,0x1C, // 8 24

  0xE0,0x10,0x08,0x08,0x10,0xE0,
  0x00,0x31,0x22,0x22,0x11,0x0F, // 9 25


  0x18,0x08,0x08,0xF8,0x08,0x08,0x18,
  0x00,0x00,0x20,0x3F,0x20,0x00,0x00, // T 52


  0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,
  0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00, // V 54

};

const uint8_t My_font8x16_widths [] PROGMEM = {
 2,6,5,6,6,6,6,6,6,6,6,7,8
};

const uint16_t My_font8x16_widths_16s [] PROGMEM = {
 2+6+5+6+6+6+6+6+6+6+6+7+8
  };

const DCfont Myfont8x16 = {
  (uint8_t *)My_font8x16,
  0, // character width in pixels
  2, // character height in pages (8 pixels)
  32,126, // ASCII extents
  (uint16_t *)My_font8x16_widths_16s,
  (uint8_t *)My_font8x16_widths,
  1 // spacing
  };

// for backwards compatibility
#define MYFONT (&Myfont8x16)
const DCfont *currentFont = MYFONT;
extern "C" void __cxa_pure_virtual() { while (1); }
void setup() {
  oled.begin(128, 64, sizeof(tiny4koled_init_128x64br), tiny4koled_init_128x64br);
  oled.clear();
  oled.on();
}


void loop() {
   // Read the voltage from ADC (example: analog pin A0)
 // int adcValue = analogRead(A0);
  // Convert ADC value to voltage (assuming 10-bit ADC and 5V reference voltage)
  float voltage = 23.5;
  // Convert voltage to string 
  //dtostrf(voltage, 4, 2, vtg);  // Convert float to string with 2 decimal places
  // Read temperature from TMP36 sensor and convert to string with "°C"
  float temperature = 56;
  //dtostrf(temperature, 4, 2, temp);       // Convert temperature to string with 2 decimal places
    oled.setFont(currentFont);   
  // Update the display with the new values
  oled.setCursor(10, 1);
  oled.print(" V = "); // Clear previous value (adjust length as needed)
  oled.print(voltage, 6); // Print the float value with 6 decimal places
  oled.print(" T =   "); // Clear previous value (adjust length as needed)
   oled.print(temperature, 6); // Print the float value with 6 decimal places
  delay(1000); // Update every second (adjust as needed)
}

To reduce size i have created my own font in that i am using 0-9 numbers and printing float but facing same issue
Sketch too big; see https://support.arduino.cc/hc/en-us/articles/360013825179 for tips on reducing it. Sketch uses 6084 bytes (101%) of program storage space. Maximum is 6012 bytes. Global variables use 324 bytes of dynamic memory. text section exceeds available space in board

You have to save 72 bytes more. Seeing that you're using PROGMEM, you can consider to move some of that to RAM.

Why is this an array? You only store the sum of a couple of numbers.


Why don't you get rid of the bootloader and program over ICSP. It will make life a lot easier :wink: