Due to high demand expect some shipping delays at this time, orders may not ship for 3-4 business days. On MLK Day no orders will be shipped.
0

Clear display ssd1306
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Clear display ssd1306

by wurst on Mon Nov 29, 2021 6:04 pm

Hello,

how can I clear the display so it only shows black again? I use the adafruit_displayio_ssd1306.SSD1306 lib.
When I use sleep and wake the last content is shown again. Also, fill(0) doesn't work.
Any tips on how to reset the content?

Thanks!

wurst
 
Posts: 3
Joined: Sun Apr 01, 2018 2:26 pm

Re: Clear display ssd1306

by rpiloverbd on Sun Dec 05, 2021 7:19 am

I used Adafruit_GFX.h and Adafruit_SSD1306.h whenever I worked with SSD1306 OLED display and arduino. I used the clearDisplay(); function to clear the display.

rpiloverbd
 
Posts: 90
Joined: Mon Nov 29, 2021 8:13 am

Re: Clear display ssd1306

by adafruit_support_carter on Mon Dec 06, 2021 2:10 pm

You'll need to do this via displayio. That are various ways and it depends on what you are trying to do. What is the current code you are using to drive the display?

adafruit_support_carter
 
Posts: 22281
Joined: Tue Nov 29, 2016 2:45 pm

Re: Clear display ssd1306

by Old_novice on Wed Dec 08, 2021 11:02 am

Code: Select all | TOGGLE FULL SIZE
void OLED_clear()
{
   OLED_send(SSD1306_SET_PAGE_ADDR);     // 0x22
        OLED_send(0);                                                  // start at row top
        OLED_send(7);     // end at the bottom row
      
      OLED_sendCommand(SSD1306_SET_COLUMN_ADDR);   // opcode:0x21
        OLED_sendCommand(0);     // start at left edge of screen
        OLED_sendCommand(127);   // end at right edge of screen

       
        for (uint16_t scrClearIndex=0; scrClearIndex<1024; scrClearIndex++)
         {  // (SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8)
            TWCR=((1<<TWINT)|(1<<TWSTA)|(1<<TWEN)); // send START
            while(!(TWCR & (1 << TWINT)));         // delay until TWINT set
            TWDR = OLED_SLA7 << 1;               // 8-bit SLAw = 0x78
            TWCR = ((1<<TWINT)|(1<<TWEN));
         while(!(TWCR & (1<<TWINT)));         // TX?done delay

            TWDR = 0x40;  // send D/C_sentinal byte for data stream
            TWCR = ((1<<TWINT)|(1<<TWEN));
         while(!(TWCR & (1<<TWINT)));

      for (uint8_t x=0; x<16; x++)
         {
            TWDR = 0x00;  // all eight pixels in the column are off.
            TWCR = ((1<<TWINT)|(1<<TWEN));
         while(!(TWCR & (1<<TWINT)));
            scrClearIndex++;  // 16 bytes per I2C transmission__64 transmissions per screen
            }
            scrClearIndex--;
            //TWCR = ( (1<<TWINT)|(1<<TWEN)|(1<<TWSTO) ); // I2C STOP
        }
Last edited by adafruit_support_carter on Wed Dec 08, 2021 11:21 am, edited 1 time in total.
Reason: add [code] tags

Old_novice
 
Posts: 2
Joined: Tue Nov 23, 2021 7:37 am

Re: Clear display ssd1306

by Old_novice on Wed Dec 08, 2021 11:49 am

Using the rhe C code below, I can clear row zero but the other rows remain. It's obviously my coding but I can't see why.

Code: Select all | TOGGLE FULL SIZE
void OLED_clear()
{
   OLED_send(SSD1306_SET_PAGE_ADDR);           // 0x22
        OLED_send(0);                                                         // start at row top
        OLED_send(7);                                                          // end at row bottom
   OLED_sendd(SSD1306_SET_COLUMN_ADDR);   // opcode:0x21
        OLED_send(0);                                                          // start at screen left edge
        OLED_send(127);                                                      // end at screen right edge
       
        for (uint16_t scrClearIndex=0; scrClearIndex<1024; scrClearIndex++)
      {  // (SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8)
            TWCR=((1<<TWINT)|(1<<TWSTA)|(1<<TWEN));    // send START
            while(!(TWCR & (1 << TWINT)));                  // wait for TWINT set
            TWDR = OLED_SLA7 << 1;             // 8-bit SL addr = 0x78
            TWCR = ((1<<TWINT)|(1<<TWEN));
       while(!(TWCR & (1<<TWINT)));                  // TX wait

            TWDR = 0x40;  // send D/C_sentinal byte for data stream
            TWCR = ((1<<TWINT)|(1<<TWEN));
       while(!(TWCR & (1<<TWINT)));

       for (uint8_t x=0; x<16; x++)
       {
            TWDR = 0x00;  // eight collumn pixels off
            TWCR = ((1<<TWINT)|(1<<TWEN));
       while(!(TWCR & (1<<TWINT)));
            scrClearIndex++;  // 16 bytes per I2C transmission x 64
            }
            scrClearIndex--;
            TWCR = ( (1<<TWINT)|(1<<TWEN)|(1<<TWSTO) ); // I2C STOP
        }
Attachments
SSD1306.jpg
added [code] tags
SSD1306.jpg (214.02 KiB) Viewed 78 times

Old_novice
 
Posts: 2
Joined: Tue Nov 23, 2021 7:37 am

Please be positive and constructive with your questions and comments.