SSD1306 OLED (72x40) I2C display from scratch


+ Reply to Thread
Results 1 to 40 of 61

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default SSD1306 OLED (72x40) I2C display from scratch

    Thanks Richard.

    This it looks now, with your code ni post #26.


    https://drive.google.com/file/d/1Ud4...usp=drive_link
    Roger

  2. #2
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    913


    Did you find this post helpful? Yes | No

    Default SSD1306 OLED (72x40) I2C display from scratch

    These few changes will fill the whole screen in white.

    Code:
    ' ====== CLEAR LCD ================================================== ===============================
    CLEAR_LCD:
    COM = $21 : GOSUB SEND_COMMAND
    COM = 28 : GOSUB SEND_COMMAND
    COM = 99 : GOSUB SEND_COMMAND '91
    COM = $22 : GOSUB SEND_COMMAND
    COM = 0 : GOSUB SEND_COMMAND
    COM = 4 : GOSUB SEND_COMMAND
    LCD_DATA = $ff
    FOR J = 0 TO 4
    FOR I = 28 TO 99
    I2CWrite SDA,SCL,I2CDevice,[$40,LCD_DATA]
    NEXT I
    NEXT J
    RETURN
    Last edited by flotulopex; - 24th November 2023 at 22:19.

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,457


    Did you find this post helpful? Yes | No

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

    ok, then this should be pretty close

    Code:
    #CONFIG  __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOD_ON & _IESO_ON & _FCMEN_ON
    #ENDCONFIG
    define OSC 8
    OSCCON = %01110000 'Internal RC set to 8MHZ
    ' ====== VARIABLES ================================================== ===============================
    I2CDevice var byte
    SDA VAR PORTB.6 ' I2C Data
    SCL VAR PORTB.4 ' I2C Clock
    LCD_DATA VAR BYTE
    COM VAR BYTE ' COMMAND
    I VAR BYTE
    J VAR BYTE
    X VAR BYTE 'LCD POSITION X(0 TO 127)
    Y VAR BYTE 'LCD POSITION Y(0 TO 7)
    hshift con 28
    ' ====== INITIALIZE VARIABLES ================================================== ====================
    I2CDevice = $78
    '======= SSD1306 I2C OLED initialization ================================================== =========
    COM = $AE : GOSUB SEND_COMMAND ' turn off oled panel
    COM = $D5 : GOSUB SEND_COMMAND ' set display clock divide ratio/oscillator frequency
    COM = $80 : GOSUB SEND_COMMAND ' set divide ratio
    COM = $A8 : GOSUB SEND_COMMAND ' set multiplex ratio
    COM = $3F : GOSUB SEND_COMMAND ' 1/40 duty
    COM = $D3 : GOSUB SEND_COMMAND ' set display offset
    COM = $0 : GOSUB SEND_COMMAND
    COM = $20 : GOSUB SEND_COMMAND
    COM = $0 : GOSUB SEND_COMMAND
    COM = $AD : GOSUB SEND_COMMAND ' Internal IREF Setting
    COM = $30 : GOSUB SEND_COMMAND ' --
    COM = $8D : GOSUB SEND_COMMAND ' set Charge Pump enable/disable
    COM = $14 : GOSUB SEND_COMMAND ' set(0x10) disable
    COM = $68 : GOSUB SEND_COMMAND ' set start line address
    COM = $A6 : GOSUB SEND_COMMAND ' set normal display
    COM = $A4 : GOSUB SEND_COMMAND ' Disable Entire Display On
    COM = $A1 : GOSUB SEND_COMMAND ' set segment re-map 128 to 0
    COM = $C8 : GOSUB SEND_COMMAND ' Set COM Output Scan Direction 64 to 0
    COM = $DA : GOSUB SEND_COMMAND ' set com pins hardware configuration
    COM = $12 : GOSUB SEND_COMMAND '
    COM = $81 : GOSUB SEND_COMMAND ' set contrast control register
    COM = $7F : GOSUB SEND_COMMAND '
    COM = $D9 : GOSUB SEND_COMMAND ' set pre-charge period
    COM = $22 : GOSUB SEND_COMMAND '
    COM = $DB : GOSUB SEND_COMMAND ' set vcomh
    COM = $40 : GOSUB SEND_COMMAND '
    COM = $AF : GOSUB SEND_COMMAND ' turn on oled panel
    
    
    ' ====== PROGRAM ================================================== =================================
    
    
    GOSUB CLEAR_LCD
    MAIN:
    ;7x5 "A"
    X = 15 : Y = 0 : GOSUB SET_7
    I2CWrite SDA,SCL,I2CDevice,[$40,$fc,$12,$12,$12,$fc]
    ;14x10 "A"
    X = 15 : Y = 2 : GOSUB SET_14
    I2CWrite SDA,SCL,I2CDevice,[$40,$f0,$f8,12,12,14,14,12,12,$f8,$f0_
    ,$ff,$ff,6,6,6,6,6,6,$ff,$ff]
    PAUSE 1000
    GOTO MAIN
    END
    ' ====== CLEAR LCD ================================================== ===============================
    CLEAR_LCD:
    COM = $21 : GOSUB SEND_COMMAND
    COM = hshift : GOSUB SEND_COMMAND
    COM = 71 + hshift : GOSUB SEND_COMMAND
    COM = $22 : GOSUB SEND_COMMAND
    COM = 0 : GOSUB SEND_COMMAND
    COM = 4 : GOSUB SEND_COMMAND
    LCD_DATA = 0
    FOR J = 0 TO 4
    FOR I = 0 TO 71
    I2CWrite SDA,SCL,I2CDevice,[$40,LCD_DATA]
    NEXT I
    NEXT J
    RETURN
    ' ====== SEND COMMAND ================================================== ============================
    SEND_COMMAND:
    I2CWrite SDA,SCL,I2CDevice,[0,COM]
    RETURN
    '======= SET_XY ================================================== ==================================
    SET_7: '7x5
    COM = $21 : GOSUB SEND_COMMAND
    COM = X+hshift : GOSUB SEND_COMMAND
    COM = x+hshift+4 : GOSUB SEND_COMMAND
    COM = $22 : GOSUB SEND_COMMAND
    COM = Y : GOSUB SEND_COMMAND
    COM = y : GOSUB SEND_COMMAND
    RETURN
    SET_14: ;14x10
    COM = $21 : GOSUB SEND_COMMAND
    COM = X+hshift: GOSUB SEND_COMMAND
    COM = x+hshift+9 : GOSUB SEND_COMMAND
    COM = $22 : GOSUB SEND_COMMAND
    COM = Y : GOSUB SEND_COMMAND
    COM = y+1 : GOSUB SEND_COMMAND
    RETURN
    Warning I'm not a teacher

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


    Did you find this post helpful? Yes | No

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

    the google drive link is a dud
    Warning I'm not a teacher

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


    Did you find this post helpful? Yes | No

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

    the google drive link is a dud
    Sorry for that.

    How do I post a small video then?
    Roger

  6. #6
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    913


    Did you find this post helpful? Yes | No

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

    Roger

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


    Did you find this post helpful? Yes | No

    Default SSD1306 OLED (72x40) I2C display from scratch

    I also adjusted your code as:
    Code:
    ' ====== PROGRAM ================================================== =================================
    GOSUB CLEAR_LCD
    
    MAIN:
        '7x5 "A"
        X = 28 : Y = 0 : GOSUB SET_7
        I2CWrite SDA,SCL,I2CDevice,[$40,$fc,$12,$12,$12,$fc]
        
        '14x10 "A"
        X = 28 : Y = 2 : GOSUB SET_14
        I2CWrite SDA,SCL,I2CDevice,[$40,$f0,$f8,12,12,14,14,12,12,$f8,$f0_
        ,$ff,$ff,6,6,6,6,6,6,$ff,$ff]
        PAUSE 1000
        GOTO MAIN
    END
    Name:  WhatsApp Image 2023-11-24 at 23.38.15.jpeg
Views: 2071
Size:  72.6 KB
    Roger

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 : 28

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