Update only parts of the FeatherWing OLED - 128x64 display

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
rsagevik
 
Posts: 4
Joined: Sat Sep 15, 2012 10:33 am

Update only parts of the FeatherWing OLED - 128x64 display

Post by rsagevik »

Hi.
I'm working on an IOT temperature sensor where I would like to update the temperature shown on the display separate from a "statusline" that shows other information. If using the clearDisplay() function and then printing all information to the display, everything seems to work fine apart from the slightly annoying screen flicker observed when the screen updates.

I have tried separating temperature and status display in two separate functions, but without calling the clearDisplay() function it only seems to just add to the current info shown. I read a post on the arduino forum somewhere saying one could just overwrite parts of the display with spaces before writing new information to the display, but this doesn't seem to have the desired effect either.

The behaviour experienced before and after updating the display:
display.JPG
display.JPG (197.18 KiB) Viewed 52 times
And here are some 'dummy code' of the code used for displaying information on the display, since in the real
project files I have put all the code for using the display in its own c++ class.

Code: Select all

#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>

Adafruit_SH1107 display = Adafruit_SH1107(64, 128, &Wire);

int count = 1;
bool status = true;

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

    display.begin(0x3C, true);
    delay(250);
    display.clearDisplay();
    display.setRotation(1);
    display.setTextColor(SH110X_WHITE);
    display.setTextSize(1);
    display.setCursor(0, 0);
    display.display();
}

void displayTemperature(double t){
    display.setTextSize(1);
    display.setCursor(0, 0);
    display.print("Temperature:");
    display.setTextSize(2);
    display.setCursor(10, 20);
    display.print(t);
    display.display();
}

void displayStatus(bool s1, int s2){
    display.setTextSize(1);
    display.setCursor(0, 48);
    display.print("---------------------");
    display.print("WiFi: ");
    display.print(s1);
    display.print(" Sent:");
    display.print(s2);
    display.display();
}

void clearStatus(){
    display.setTextSize(1);
    display.setCursor(0, 48);
    display.print("---------------------");
    display.print("                     ");
    display.display();
}

void loop() {
    double temp = double(random(20));
    displayTemperature(temp);
    displayStatus(status, count);
    delay(1000);
    count++;
    status = !status;
    Serial.print("Count: "); Serial.println(count);
    Serial.print("Status: "); Serial.println(status);
    clearStatus();
    delay(1000);

    yield();
}
I have used the code sample from Adafruit to get started with this display. I might be doing some obvious
newbie errors, so I would really appreciate some experienced feedback on this.

Thanks in advance
Rune

User avatar
dastels
 
Posts: 15653
Joined: Tue Oct 20, 2015 3:22 pm

Re: Update only parts of the FeatherWing OLED - 128x64 display

Post by dastels »


User avatar
rsagevik
 
Posts: 4
Joined: Sat Sep 15, 2012 10:33 am

Re: Update only parts of the FeatherWing OLED - 128x64 display

Post by rsagevik »

I "solved" it using the fillRect() function, but I will definitely have a closer look at the link
you shared. Thanks a lot for your help Dave.

Rune

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”