Problem displaying temperature sensor on128x32 OLED

I am trying to print temperature value and voltage value on oled but i observed weird behavior on display when i am just printing letter v and t it is printing correctly on oled but when i want to print value along with that it is not printing properly . Below i am attaching both images


#include <Tiny4kOLED.h>
const DCfont *currentFont = FONT8X16P;
const float R1 = 10000.0;
const float A = 2.108508173e-03, B = 0.7979204727e-04, C = 6.535076315e-07;

uint8_t width = 128;
uint8_t height = 32;

float calculateTemperature(uint16_t value)
{
  float R2 = R1 * (1023.0 / (float)value - 1.0);
  float logR2 = log(R2);
  float T = (1.0 / (A + B * logR2 + C * logR2 * logR2 * logR2));
  T = T - 273.15;
  return T;
}

void setup()
{
  oled.begin(width, height, sizeof(tiny4koled_init_128x64br), tiny4koled_init_128x64br);

  oled.on();
  oled.setFont(currentFont);
  oled.clear();
}

void loop()
{

  // Read and convert the voltage
  int raw_value = analogRead(A0);
  float voltage = (raw_value * 5.0) / 1023.0;
  // Read and convert the temperature
  uint16_t raw_value1 = analogRead(A1);
  float temperature = calculateTemperature(raw_value1);

  // Update the display with the new values
  oled.setCursor(5, 1);
  oled.print(" V = ");
  oled.print(voltage, 4);

  oled.setCursor(5, 4);
  oled.println(" T = ");
  oled.print(temperature, 2);

  delay(1000);
}

Is this a continuation of Text section exceeds available space in board

I have solved that issue that, this is something different

  oled.println(" T = ");

Change this to print instead of println.

Incidentally, you had your custom font incorrect in your other discussion:

/* Standard ASCII 8x16 proportional font */
const uint8_t My_font8x16 [] PROGMEM = {
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // <space>  0

  0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // - 13

  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

  0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
  0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, // = 29

  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  = {
  7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 2, 0, //  0 - 15
  6, 5, 6, 6, 6, 6, 6, 6, 6, 6, 0, 0, 0, 7, 0, 0, // 16 - 31
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 32 - 47
  0, 0, 0, 0, 7, 0, 8,             // 48 - 54
};

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

const DCfont Myfont8x16 = {
  (uint8_t *)My_font8x16,
  0, // character width in pixels
  2, // character height in pages (8 pixels)
  ' ', 'V', // ASCII extents
  (uint16_t *)My_font8x16_widths_16s,
  (uint8_t *)My_font8x16_widths,
  1 // spacing
};
#define MYFONT (&Myfont8x16)

const DCfont *currentFont = MYFONT;

In that i kept only letters which i think are necessary according to my project

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.