SS1306 OLED Clear Issue

Hello there; I designed a simple project. I measure temperature with NTC thermistor and display it on OLED. I share the OLED link which I use in this project OLED Display

There is both temperature information and degree symbol on the OLED screen. I don't want to use the clearDisplay() command. Because the screen is flashing. Therefore, I use setTextColor(WHITE, BLACK) command. This solution worked and the screen is not flashing. But this solution doesn't work when I change the font. The display does not flash, but overwrites the previous value when the temperature value changes. Is there any other way I can solve this?

I created a font suitable for the AdafruitGFX library from the site I shared the link of and used it. Font GFX

In short, when I use the standard font of the Adafruit1306 library, I can solve the problem, but when I change the font, my solution does not work.

TRANS_OLED.setTextSize(5);
TRANS_OLED.setTextColor(WHITE);
TRANS_OLED.setCursor(15, 15);
TRANS_OLED.print(tempCelsiusDecimal);
TRANS_OLED.display();
TRANS_OLED.setTextSize(1);
TRANS_OLED.setTextColor(WHITE);
TRANS_OLED.setCursor(80, 10);
TRANS_OLED.print("o");
TRANS_OLED.display();
TRANS_OLED.setTextSize(5);
TRANS_OLED.setCursor(90, 15);
TRANS_OLED.print("C");
TRANS_OLED.display();
TRANS_OLED.setTextSize(5);
TRANS_OLED.setTextColor(WHITE, BLACK);
TRANS_OLED.setCursor(15, 15);
TRANS_OLED.print(tempCelsiusDecimal);
TRANS_OLED.display();

The code I shared above works fine with the default font.

TRANS_OLED.setFont(&DSEG7_Classic_Mini_Bold_40);
TRANS_OLED.setTextSize(0);
TRANS_OLED.setTextColor(WHITE);
TRANS_OLED.setCursor(30, 50);
TRANS_OLED.print(tempCelsiusDecimal);
TRANS_OLED.display();
TRANS_OLED.setFont(&Dialog_plain_12);
TRANS_OLED.setTextSize(0);
TRANS_OLED.setTextColor(WHITE);
TRANS_OLED.setCursor(100, 15);
TRANS_OLED.print("o");
TRANS_OLED.display();
TRANS_OLED.clearDisplay();

The code above is that I changed the font and it doesn't work properly. It works fine with the clearDisplay() command, but the degree symbol is blinking. As I said above, when I use the setTextColor(WHITE, BLACK) command, the new temperature value overwrites the old temperature value.

Can you help me to overcome this problem? Thank you in advance for your support.

Please post the entire code, formatted, and using code tags like You did.

Presumably you are using an Adafruit library, that is a known behavior when using a font other than the default.

Easy work-around is to save the previous value that was displayed, then when you want to overwrite that value, do the following sequence:

position cursor
set text color to background color
write previous value to display
reposition cursor
set text color to your normal text color
write new value to display
save the new value so it will be available next time

Here is my entire code;

#include <Arduino.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Fonts/DSEG7_Classic_Mini_Bold_40.h>
#include <Fonts/Dialog_plain_12.h>
#include <Fonts/DejaVu_Sans_Mono_9.h>

// 128x32 px OLED değişkenleri
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 32
#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C
#define THERMISTOR_PIN A0
// 128x64px OLED değişkenleri
#define TRANS_WIDTH 128
#define TRANS_HEIGHT 64
#define TRANS_OLED_MOSI 9
#define TRANS_OLED_CLK 10
#define TRANS_OLED_DC 11
#define TRANS_OLED_CS 12
#define TRANS_OLED_RESET 13



float thermistorResistance, tempKelvin, tempCelsius, flowRate;
const float beta = 3977.0;
const float tempRef = 298.15;
const float R0 = 10000.0;
const float R1 = 10000.02;
const int sampleNumber = 5;
float thermistorVolt[sampleNumber];
float averageThermistor;
int tempCelsiusDecimal;

void Temperature();
void TRANS_OLED_DISPLAY();

Adafruit_SSD1306 TRANS_OLED(TRANS_WIDTH, TRANS_HEIGHT, TRANS_OLED_MOSI, TRANS_OLED_CLK, TRANS_OLED_DC, TRANS_OLED_RESET, TRANS_OLED_CS);

void setup()
{
	Serial.begin(9600);

	analogReference(EXTERNAL);


	if (!TRANS_OLED.begin(SSD1306_SWITCHCAPVCC))
	{
		Serial.println(F("SSD1306 allocation failed"));
		for (;;)
			;
	}


	TRANS_OLED.clearDisplay();
	TRANS_OLED.dim(0);
}

void loop()
{
	Temperature();
	TRANS_OLED_DISPLAY();
}



void TRANS_OLED_DISPLAY()
{
		// Versiyon 1: Defult Font

		// TRANS_OLED.setTextSize(5);
		// TRANS_OLED.setTextColor(WHITE);
		// TRANS_OLED.setCursor(15, 15);
		// TRANS_OLED.print(tempCelsiusDecimal);
		// TRANS_OLED.display();
		// TRANS_OLED.setTextSize(1);
		// TRANS_OLED.setTextColor(WHITE);
		// TRANS_OLED.setCursor(80, 10);
		// TRANS_OLED.print("o");
		// TRANS_OLED.display();
		// TRANS_OLED.setTextSize(5);
		// TRANS_OLED.setCursor(90, 15);
		// TRANS_OLED.print("C");
		// TRANS_OLED.display();
		// TRANS_OLED.setTextSize(5);
		// TRANS_OLED.setTextColor(WHITE, BLACK);
		// TRANS_OLED.setCursor(15, 15);
		// TRANS_OLED.print(tempCelsiusDecimal);
		// TRANS_OLED.display();
	

		// Version 2: Different Font 

		TRANS_OLED.setFont(&DSEG7_Classic_Mini_Bold_40);
		TRANS_OLED.setTextSize(0);
		TRANS_OLED.setCursor(30, 50);
		TRANS_OLED.setTextColor(WHITE);
		TRANS_OLED.print(tempCelsiusDecimal);
		TRANS_OLED.display();

		TRANS_OLED.setFont(&Dialog_plain_12);
		TRANS_OLED.setTextSize(0);
		TRANS_OLED.setTextColor(WHITE);
		TRANS_OLED.setCursor(100, 15);
		TRANS_OLED.print("o");
		TRANS_OLED.display();
		TRANS_OLED.clearDisplay();
}

void Temperature()
{
	for (uint8_t i = 0; i < sampleNumber; i++)
	{
		thermistorVolt[i] = analogRead(THERMISTOR_PIN);
		delay(10);
	}
	averageThermistor = 0;
	for (uint8_t j = 0; j < sampleNumber; j++)
	{
		averageThermistor += thermistorVolt[j];
	}
	averageThermistor = averageThermistor / sampleNumber;
	thermistorResistance = R1 / (1023.0 / averageThermistor - 1.0);
	tempKelvin = (1.0 / tempRef) + (log(thermistorResistance / R0) / beta);
	tempKelvin = 1.0 / tempKelvin;
	tempCelsius = tempKelvin - 273.15;
	tempCelsiusDecimal = (int)tempCelsius;
}

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