Clear display ssd1306

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
wurst
 
Posts: 3
Joined: Sun Apr 01, 2018 2:26 pm

Clear display ssd1306

Post by wurst »

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!

User avatar
rpiloverbd
 
Posts: 198
Joined: Mon Nov 29, 2021 8:13 am

Re: Clear display ssd1306

Post by rpiloverbd »

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.

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: Clear display ssd1306

Post by adafruit_support_carter »

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?

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

Re: Clear display ssd1306

Post by Old_novice »

Code: Select all

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

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

Re: Clear display ssd1306

Post by Old_novice »

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

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
added [code] tags
added [code] tags
SSD1306.jpg (214.02 KiB) Viewed 121 times

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

Return to “Adafruit CircuitPython”