Cannot drive I2C Oled :(


Closed Thread
Results 1 to 22 of 22

Hybrid View

  1. #1
    Join Date
    Oct 2011
    Posts
    54


    Did you find this post helpful? Yes | No

    Default Re: Cannot drive I2C Oled :(

    Here is some code. It fills the screen with 8 lines of vertical bars then clears it.
    If the screen does not start up correctly dissconnect and wait or discharge with a resistor and try again. Apparently this is normal.
    The 'INIT' routine was arrived at by trial and error, if you can improve on it let me know.
    The 'RESET' routine makes no difference and is included for you to experiment.
    Not an easy display to work with.

    Phil

    Code:
    '****************************************************************
    '*  Name    : CRIUS_OLED_Test.pbp                               *
    '*  Author  : Philtronix                                        *
    '*  Notice  : Copyright (c) 2015 Philtronix                     *
    '*          : All Rights Reserved                               *
    '*  Date    : 15/06/2015                                        *
    '*  Version : 1.0                                               *
    '*  Notes   : PIC18F2550 int osc @ 4mHz   3.3v                  *
    '*          : CRIUS OLED display   3.3v                         *
    '****************************************************************
    osccon = %01100010          'Int OSC @ 4mHz
    adcon1 = %00001111          'All ports digital
    ucon.3 = 0                  'Disable USB port
    ucfg.3 = 1                  'Digital in RC4 & RC5
    cmcon  = 7                  'Comparators off
    
    led     var LatC.0
    scl     var PortC.1
    sda     var PortC.2
    dat     var byte
    counter var word
    
    control con %01111000       'I2C slave address (write mode)
    
    trisb = %11000000
    PortB = %00000000
    pause 500
    
    trisc = %11111000           'PortC 0, 1, 2 outputs
    PortC = %00000110           'scl & sda high to start
    
        pause 2000
    '    gosub RESET:
        gosub init_oled:
        i2cwrite sda,scl,control,[$80,$AF]  'Display ON
        pause 10
    
    Start:
        led = 1                             'Code running
        i2cwrite sda,scl,control,[$80,$A7]  'Inverse Display 
        pause 500
        i2cwrite sda,scl,control,[$80,$A6]  'Normal Display
        pause 20
    '    i2cwrite sda,scl,control,[$80,$21,$00,$40] 'Set columns
        pause 20
    '    i2cwrite sda,scl,control,[$80,$22,$00,$04]  'Set pages
        pause 500     
        for counter = 0 to 1023
        i2cwrite sda,scl,control,[$40,$FF]
        next
        led = 0                             'Code running
        for counter = 0 to 1023
        i2cwrite sda,scl,control,[$40,$00]
        next
    GOTO Start:
    
    INIT_OLED:
        i2cwrite sda,scl,control,[$80,$AE]          'Display OFF               ****
        pause 1
        i2cwrite sda,scl,control,[$80,$2E]          'Deactivate scrolling
        pause 1
        i2cwrite sda,scl,control,[$80,$20,$10]      'Page addressing mode      ****
        pause 1
        i2cwrite sda,scl,control,[$80,$A0]          '                          ****
    '    i2cwrite sda,scl,control,[$80,$A1]          '                          ****
        pause 1
        i2cwrite sda,scl,control,[$80,$A6]          'WHITE chars BLACK backround
    '    i2cwrite sda,scl,control,[$80,$A7]         'BLACK chars WHITE backround
        pause 1
        i2cwrite sda,scl,control,[$80,$81,$7F]      'Setup contrast            XXXX
        pause 1
        i2cwrite sda,scl,control,[$80,$AF]          'Display on                **** 
        pause 1
        i2cwrite sda,scl,control,[$80,$40]
        pause 1
    '    i2cwrite sda,scl,control,[$80,$C0]          'Flip display vertically   ****
        i2cwrite sda,scl,control,[$80,$C8]          'Flip display vertically   ****
        pause 1
    '    i2cwrite sda,scl,control,[$80,$A0]          '                          ****
        i2cwrite sda,scl,control,[$80,$A1]          '                          ****
        pause 1
        i2cwrite sda,scl,control,[$80,$00,$80,$10]  'Set column start address  ****
        pause 1
        i2cwrite sda,scl,control,[$80,$B0]          'Set page start address    ****
        pause 1
        return
        
    RESET:
        i2cwrite sda,scl,control,[$80,$AE]          'Display OFF
        pause 10
        I2Cwrite sda,scl,control,[$80,$20,$02]      'Page addressing mode
        pause 10
        i2cwrite sda,scl,control,[$80,$B0]          'Page start address
        pause 10
        i2cwrite sda,scl,control,[$80,$00,$80,$10]  'Set column start address
        pause 10
        i2cwrite sda,scl,control,[$80,$A0]          'Address 0 mapped to SEG 0
        pause 10
     '   i2cwrite sda,scl,control,[$80,$A1]          'Address 0 mapped to SEG 127
        pause 10
        i2cwrite sda,scl,control,[$80,$D3,$00]      'Display offset
        pause 10
    
        pause 10
        i2cwrite sda,scl,control,[$80,$40]          'Display start line
        Pause 10
        i2cwrite sda,scl,control,[$80,$C0]          'Output scan direction
        pause 10
        i2cwrite sda,scl,control,[$80,$A6]          'WHITE chars BLACK backround
        pause 10
        i2cwrite sda,scl,control,[$80,$81,$7F]      'Contrast control
        pause 10
        i2cwrite sda,scl,control,[$80,$A4]          'Entire display OFF
        pause 10
        i2cwrite sda,scl,control,[$80,$A6]          'Normal display
        pause 10
        i2cwrite sda,scl,control,[$80,$A3,$00,$40]  'Set vertical scroll
        pause 10
        i2cwrite sda,scl,control,[$80,$20,$00]      'Horizontal addressing mode
    '    i2cwrite sda,scl,control,[$80,$20,$01]      'Vertical addressing mode
        RETURN
    Last edited by Demon; - 15th June 2015 at 14:13. Reason: Fixed tags

  2. #2
    Join Date
    Apr 2013
    Posts
    32


    Did you find this post helpful? Yes | No

    Default Re: Cannot drive I2C Oled :(

    Thank you so much, I'm able to drive the screen and light up any pixel I want on screen. I think I was misusing i2cwrite command on my code. Now its ok.
    Here is my trial code for blinking any line on the screen.
    Code:
       
    '==========================MCU SETUP============================================  
    Include "modedefs.bas"
    DEFINE OSC 16
    DEFINE I2C_SLOW 1 'Used to work with 100KHz devicez when using over 4MHz (my screen working without this too)
    DEFINE I2C_HOLD 1 'Holding Lines low when not sending data (not necessary)
    
    OPTION_REG=0
    ADCON0=0
    ADCON1=7
    TRISA=%00111111
    TRISB=%00000001
    TRISC=0
    PORTC=$FF
    
    '==============================Variables=======================================
    
    I2CDevice var byte
    SCL var PortC.3         ' I2C Clock  PortC.3
    SDA var PortC.4         ' I2C Data   PortC.4
    DC VAR byte' "DATA OR COMMAND", $40=DATA; $80=COMMAND
    LCD_DATA VAR BYTE
    COM VAR BYTE' COMMAND
    
    
    I VAR BYTE
    J VAR BYTE
    X VAR BYTE' LCD Column POSITION (0 TO 127)
    Y VAR BYTE'LCD Line POSITION FOR PAGE MODE(0 TO 7)
    CLEAR
    '=============================================================================
    I2CDevice = $78      ' Display = $78,
    PAUSE 20
    '=========================lcd initialization====================================
    INIT:
    I2CWrite SDA,SCL,I2CDevice,[DC,$AE]'Display Off
    pause 10
    I2CWrite SDA,SCL,I2CDevice,[DC,$20,$10]' Page adressing mode
    I2CWrite SDA,SCL,I2CDevice,[DC,$D3,$00]' Set offset to 0
    I2CWrite SDA,SCL,I2CDevice,[DC,$40]' Set display start line 0
    I2CWrite SDA,SCL,I2CDevice,[DC,$81,$FF]' Set contrast to full
    I2CWrite SDA,SCL,I2CDevice,[DC,$A4]' display on continue 
    I2CWrite SDA,SCL,I2CDevice,[DC,$A6]' $A6=NORMAL MODE;$A7=INVERSE MODE
    I2CWrite SDA,SCL,I2CDevice,[DC,$A1]' set column 127 as start
    i2cwrite sda,scl,I2CDevice,[DC,$C8]'Flip display vertically ****
    'above 2 lines for arranging screen direction, deleting them will
    'turn the display direction 180 degree
    I2CWrite SDA,SCL,I2CDevice,[DC,$AF]'Display On
    pause 10
    '===============================================================================
    GOSUB CLEAR_LCD
    pause 500
    GOSUB TITLE
    
    
    MAIN:
    
    'gosub FILL_LINE
    'pause 1000
    'gosub CLEAR_LCD
    'pause 1000
    
    GOTO MAIN
    
    '======================Send data===============================================
    SEND_DATA:
    DC=$40
    I2CWrite SDA,SCL,I2CDevice,[DC,LCD_DATA]
    RETURN
    '===============================================================================
    '======================Send Command=============================================
    SEND_COMMAND:
    DC=$80
    I2CWrite SDA,SCL,I2CDevice,[DC,COM]
    RETURN
    '===============================================================================
    
    '==============================clear lcd========================================
    CLEAR_LCD:
    X=0
    Y=0
    LCD_DATA=$00
    'Send 0 to every column in every line
    FOR Y=0 TO 7
        gosub SET_XY
        FOR I=0 TO 127
            GOSUB SEND_DATA
        NEXT I
    NEXT Y                             
    RETURN 
    
    '=============================FILL_LINE=========================================
    FILL_LINE:
    X=0
    Y=4  'I choose 4.th line to blink
    LCD_DATA=$FF ' Every line contains pixels $01 is bottom pixel, $80 is top pixel
        gosub SET_XY
        FOR I=0 TO 127
            GOSUB SEND_DATA
        NEXT I                         
    RETURN
    '===============================================================================
    
    '===========================================SET X AND Y=========================
    SET_XY:
    COM=$21:GOSUB SEND_COMMAND
    COM=X:GOSUB SEND_COMMAND
    COM=127:GOSUB SEND_COMMAND
    'Above 3 lines means; Column starts at X and End at 127
    COM=$22:GOSUB SEND_COMMAND
    COM=Y:GOSUB SEND_COMMAND
    COM=Y:GOSUB SEND_COMMAND
    'Above 3 lines means; Line starts at Y and end at Y, 
    'which means ; Only work on specified line!
    RETURN
    '===============================================================================
    END

Similar Threads

  1. OLED 128X96 cheap china lcd
    By starwick in forum Code Examples
    Replies: 10
    Last Post: - 19th June 2017, 06:23
  2. Help With OLED Display / 128X64 SSD1306
    By Denner in forum General
    Replies: 6
    Last Post: - 25th May 2013, 16:40
  3. SEROUT + SERIN, OLED + PICAXE coding help required
    By SeanHowson in forum mel PIC BASIC
    Replies: 4
    Last Post: - 15th October 2012, 17:11
  4. Master SPI interface to LCD/OLED??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 20th September 2009, 00:44
  5. OLED 128x128 color display
    By Ron Marcus in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 21st May 2007, 02:45

Members who have read this thread : 1

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

Tags for this Thread

Posting Permissions

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