SSD1306 OLED (72x40) I2C display from scratch


+ Reply to Thread
Results 1 to 40 of 74

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 OLED (42x40) I2C display from scratch

    ...credits are all for Richard
    Roger

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 OLED (42x40) I2C display from scratch

    something to consider about fonts
    it looks like you want 40x22 size font
    a pic16 has a flash word size of 14 bits therefore a font that size
    will take if encoded horizontally by row take 2x40 words per chr
    it will take 3x22 words if encoded vertically by column a reasonable saving.

    one of the benefits of the ssd1306 controller is that it can address its graphics ram either way with ease
    Name:  fonts.jpg
Views: 13100
Size:  197.5 KB
    Warning I'm not a teacher

  3. #3
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Default SSD1306 OLED (72x40) I2C display from scratch

    Richard,

    I'm still trying to understand your previous post but just for now, there's a question burning my mind: how do I address the display pixel by pixel?
    Roger

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 OLED (42x40) I2C display from scratch

    you cannot, the smallest element is 1 byte ie one column[page] of 8 rows
    Warning I'm not a teacher

  5. #5
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Default SSD1306 OLED (72x40) I2C display from scratch

    you cannot
    Right, so you are talking about using data in a more efficient way using the vertical display mode as described in figure 10-4, correct?

    Name:  2023-12-03 19_48_22-SSD1306 COMMAND reference.pdf - [SSD1780] - SumatraPDF.png
Views: 6753
Size:  153.0 KB
    Roger

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 OLED (42x40) I2C display from scratch

    yes , aligning the font data packing with the ssd1306's memory page layout is more efficient usage of the 14 bit width of the flash memory
    while it will still need some clever manipulation to unpack it into a 8 bit data stream

    Name:  fonts.jpg
Views: 6779
Size:  209.4 KB
    Warning I'm not a teacher

  7. #7
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Default SSD1306 OLED (72x40) I2C display from scratch

    Okay, found!

    Name:  VerticalAddressingMode.png
Views: 6741
Size:  85.7 KB
    Roger

  8. #8
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Default SSD1306 OLED starts up 10 times out of 11 or so

    For any reason, my OLED module won't start up once out of ten or twenty times.

    I have no clue why.

    I change OLED modules (I have five and do all the same), changes breadboards, changed µC... I don't know what to try next.

    Any idea?

    Code:
    ' OLED-72x40_16F18446
    
    ' ====== FUSES =====================================================================================
    ' External oscillator
    #CONFIG
        __config _CONFIG1, _FCMEN_OFF & _CSWEN_OFF & _CLKOUTEN_OFF & _RSTOSC_EXT1X & _FEXTOSC_HS
        __config _CONFIG2, _MCLRE_OFF & _PWRTS_PWRT_64 & _LPBOREN_OFF & _BOREN_OFF & _BORV_LO & _ZCD_OFF & _PPS1WAY_OFF
        __config _CONFIG3, _WDTCPS_WDTCPS_31 & _WDTE_SWDTEN & _WDTCWS_WDTCWS_7 & _WDTCCS_LFINTOSC
        __config _CONFIG4, _BBSIZE_BB512 & _BBEN_OFF & _SAFEN_OFF & _WRTAPP_OFF & _WRTB_OFF & _WRTC_OFF & _WRTD_OFF & _WRTSAF_OFF & _LVP_OFF
        __config _CONFIG5, _CP_OFF
    #ENDCONFIG
    
    @ ERRORLEVEL -306
    @ ERRORLEVEL -202
    
    ' ====== REGISTERS =================================================================================
    ANSELB  = %00000000
    
    ' ====== DEFINES ===================================================================================
    DEFINE OSC 32
    DEFINE NO_CLRWDT 1   ' don't waste cycles clearing WDT  
    DEFINE HSER_CLOERR 1 ' automatic clear overrun error 
    DEFINE I2C_SLOW 1    ' if >8MHz
    
    ' ====== VARIABLES =================================================================================
    SDA         VAR PORTB.5 ' I2C Clock
    SCL         VAR PORTB.6 ' I2C Data
    
    ' SSD1306 OLED 72x40 module (has built-in 10k pull-up on SDA/SCL)
    I2CDevice   CON $78
    Page        VAR BYTE ' OLED's Pages 0..4
    
    ' ====== SSD1306 I2C OLED initialization ===========================================================
    PAUSE 500 ' let display settle
    
    ' Initializing command set
    I2CWrite SDA,SCL,I2CDevice,[$00,$AE,$D5,$80,$A8,$3F,$D3,$00,$20,$00,$AD,$30,$8D,$14,$68,$A6,$A4,_
        $A1,$C8,$DA,$12,$81,$7F,$D9,$22,$DB,$40,$2E,$AF]
    PAUSEUS 50    
    
    ' ====== PROGRAM STARTUP ===========================================================================
    STARTUP:
        Gosub CLEAR_DISPLAY_FULL
    
    ' ====== MAIN PROGRAM ==============================================================================
    MAIN:
        GOSUB SPLASH1
        PAUSE 2000
        GOSUB SPLASH2
        PAUSE 2000
        GOTO MAIN
    END
    
    ' ====== CLEAR FULL DISPLAY ROUTINE ================================================================
    CLEAR_DISPLAY_FULL:
        I2CWrite SDA,SCL,I2CDevice,[$00,$21,28,99,$22,0,4]
        FOR Page = 0 TO 4
            I2CWrite SDA,SCL,I2CDevice,[$40,_
                0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, _
                0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, _
                0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, _
                0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
        NEXT Page    
        RETURN
    
    ' ====== SPLASH SCREEN DISPLAY =====================================================================
    SPLASH1:
        I2CWrite SDA,SCL,I2CDevice,[$40,_
            0,0,252,252,252,60,28,28,28,56,248,248,240,192,0,0,0,252,252,252,0,0,0,0,192,240,248,120,60,28,28,28,28,60,248,248,240,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
        I2CWrite SDA,SCL,I2CDevice,[$40,_
            0,0,255,255,255,56,56,56,56,60,31,31,15,3,0,0,0,255,255,255,0,0,0,62,255,255,255,128,0,0,0,0,0,0,192,192,192,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
        I2CWrite SDA,SCL,I2CDevice,[$40,_
            0,0,15,15,15,0,0,0,0,0,0,0,0,0,0,0,0,15,15,15,0,0,0,0,1,3,7,15,14,14,12,14,14,15,15,7,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
        I2CWrite SDA,SCL,I2CDevice,[$40,_
            0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,240,252,252,140,140,204,252,120,0,0,0,96,96,32,32,224,224,0,0,192,224,224,32,32,96,64,0,0,192,236,108,0,128,192,224,96,32,96,96,64,0]
        I2CWrite SDA,SCL,I2CDevice,[$40,_
            0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,62,63,55,49,49,57,31,31,6,0,28,62,54,34,18,63,63,7,0,16,56,49,35,55,62,30,0,0,56,63,15,0,0,31,63,48,48,48,56,24,0,0]
        RETURN
        
    SPLASH2:
        I2CWrite SDA,SCL,I2CDevice,[$40,_
            0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
        I2CWrite SDA,SCL,I2CDevice,[$40,_
            0,0,128,128,192,192,0,0,0,0,128,192,192,192,192,192,128,0,0,192,192,192,192,192,192,0,0,128,128,192,192,0,0,0,0,128,192,64,192,128,0,0,0,0,0,0,0,192,192,192,0,0,0,0,0,0,0,192,192,192,0,0,0,128,192,192,192,192,192,128,0,0]
        I2CWrite SDA,SCL,I2CDevice,[$40,_
            0,0,1,129,255,255,128,0,0,0,255,255,136,12,140,249,249,0,0,255,255,12,12,12,12,0,0,1,129,255,255,128,0,0,99,255,32,8,156,255,99,0,0,96,120,124,103,99,255,255,96,0,0,96,120,124,103,99,255,255,96,0,0,255,255,136,12,140,249,249,0,0]
        I2CWrite SDA,SCL,I2CDevice,[$40,_
            0,0,1,1,1,1,1,1,0,0,0,1,1,1,1,1,0,0,0,1,1,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,1,1,1,0,0,0]
        I2CWrite SDA,SCL,I2CDevice,[$40,_
            0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
        RETURN
    Roger

  9. #9
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    699


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 OLED (72x40) I2C display from scratch

    Use a logical analyzer to see if the module responds to "Initializing command set" when it fails. If it doesn't respond you can try a longer pause "PAUSE 500 ' let display settle".

    Check that you don't have any noise in the power lines or control lines.
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  10. #10
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Default SSD1306 OLED (72x40) I2C display from scratch

    Quote Originally Posted by rsocor01 View Post
    Use a logical analyzer to see if the module responds to "Initializing command set" when it fails.
    How would I do this?

    BTW, I just noticed that the module won't start up again if the time between a shut off and switch on is below 2-3 secs. Anyway, it is strange.

    So, if I leave the module unpowered for more than 5 seconds, it'll always restart.

    Maybe this is something absolutely "normal".
    Roger

  11. #11
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    699


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 OLED (72x40) I2C display from scratch

    Connect a logical analyzer to tx and rx. They are not expensive. Digikey has one for $20. You can see the ones and zeroes going to the module and coming back to the pic. If you don't use a logic analyzer, it is like shooting in the dark.

    About that 2-3 seconds observation, it is very likely that it is a power issue. Maybe you have a large cap that is holding a charge.


    https://www.digikey.com/en/products/...DgGxgOwgF0BfIA
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  12. #12
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default Re: SSD1306 OLED starts up 10 times out of 11 or so

    For any reason, my OLED module won't start up once out of ten or twenty times.


    I have no clue why.
    Since the module you are using has no provision made for the user to be able to reset it you are totally dependent on how the on board POR circuitry applies the reset signal. The board will have a very definite absolute minimum off period and minimum on time before a successful reset will occur. If you don't adhere to those times then its matters not what you code is trying to do the chip won't necessarily be receptive. If your code still does not work reliably after suitable POR conditions have been met then you code is incorrect. Simply resetting your pic is not enough.

    The data sheet gives no clue re command execution time or even if i2c clock stretching is in play, anecdotally there is some support for a small delay after executing an $ae command being beneficial
    Last edited by richard; - 27th December 2024 at 02:58.
    Warning I'm not a teacher

Similar Threads

  1. big char oled display
    By mombasa in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 19th September 2020, 07:02
  2. SSD1306 start display problem
    By harryweb in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 14th December 2016, 19:16
  3. Cannot drive I2C Oled :(
    By elcrcp in forum mel PIC BASIC Pro
    Replies: 21
    Last Post: - 20th August 2016, 12:19
  4. OLED Display Noise problem
    By gunayburak in forum mel PIC BASIC Pro
    Replies: 24
    Last Post: - 5th July 2016, 10:15
  5. Help With OLED Display / 128X64 SSD1306
    By Denner in forum General
    Replies: 6
    Last Post: - 25th May 2013, 15:40

Members who have read this thread : 24

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts