SSD1306 OLED (72x40) I2C display from scratch - Page 2


+ Reply to Thread
Page 2 of 2 FirstFirst 12
Results 41 to 61 of 61
  1. #41
    Join Date
    May 2013
    Location
    australia
    Posts
    2,392


    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

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


    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: 260
Size:  153.0 KB
    Roger

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


    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: 257
Size:  209.4 KB
    Warning I'm not a teacher

  4. #44
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891


    Did you find this post helpful? Yes | No

    Default SSD1306 OLED (72x40) I2C display from scratch

    Okay, found!

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

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


    Did you find this post helpful? Yes | No

    Default SSD1306 OLED (72x40) I2C display from scratch

    Here is a simple code to get started with this 72x40 display.

    I also include the SSD1306 command and display's datasheets.

    Since I use EXCEL to design characters, here's the sheet you may want to have a look at.

    And again, lots of thanks to Richard

    Name:  Display example.png
Views: 212
Size:  513.8 KB
    Attached Images Attached Images
    Attached Files Attached Files
    Roger

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


    Did you find this post helpful? Yes | No

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

    You seem to have the communication to the controller well under control
    next step is to try to store a font economically, you have probably discovered a large font on a very resource limited chip
    like a 690 stored as a series of code structures like
    I2CWrite SDA,SCL,I2CDevice,_
    [$40,192,224,240,248,252,126,63,63,63,63,63,63,63,6 3,126,252,248,240,224,192,_
    255,255,255,255,128,128,128,128,128,128,128,128,12 8,128,128,128,255,255,255,255,_
    255,255,255,255,15,15,15,15,15,15,15,15,15,15,15,1 5,255,255,255,255,_
    255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,255,255,25 5,255]
    will by the time you have 10 digits covered will have blown 75% of the chips flash.
    fonts can be stored in much better ways, even expanded out as the are read back
    Warning I'm not a teacher

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


    Did you find this post helpful? Yes | No

    Default SSD1306 OLED (72x40) I2C display from scratch

    fonts can be stored in much better ways
    Richard, can you point me the direction to do this?

    Should I use some kind of algorithm where repetitive numbers could be stored differently or find a way to make better use of the 14 bits word size of the 16F690?
    Roger

  8. #48
    Join Date
    May 2013
    Location
    australia
    Posts
    2,392


    Did you find this post helpful? Yes | No

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

    the font is just a simple block of data
    this one is for digits 0 to 9 + "." + "%" its 14 bits high and 10 bits wide [to match chip flash]
    so total size is 120 words
    for convenience lets locate it a the end of flash - 120 words ie. 0xf88
    note this is only partially "filled" in and not very carefully at that

    Code:
    asm       ;incomplete and very rough font 14x10
     org 0xf88
     dw    0x1ffc,0x3ffe,0x3006,0x3006,0x3006,0x3006,0x3006,0x3006,0x3ffe,0x1ffc ;"0"
     dw    0,0x300C,0x300E,0x300F,0x3ffF,0x3ffF,0x3ffF,0x3000,0x3000,0
     dw    0x3806,0x3C07,0x3E03,0x3703,0x3383,0x31E3,0x30F3,0x307F,0x303E,0
     dw    0x3018,0x3006,0x3186,0x3186,0x3186,0x3186,0x3186,0x3006,0x3cf8,0x1ffc  ;"3"
     dw    0,0x3ffe,0,0x3ffe,0,0x3ffe,0,0x3ffe,0,0
     dw    0,0x3ffe,0,0x3ffe,0x3ffe,0x3ffe,0,0x3ffe,0,0
     dw    0x3ffe,0x3ffe,0x3ffe,0,0,0,0,0x3ffe,0x3ffe,0x3ffe
     dw    0x3ffe,0x3ffe,0x3ffe,0,0,0x3ffe,0,0x3ffe,0x3ffe,0x3ffe
     dw    0x1ffc,0x3ffe,0x3186,0x3186,0x3186,0x3186,0x3186,0x3186,0x3ffe,0x1ffc  ;"8"
     dw    0,0x3ffe,0x3ffe,0x3ffe,0x3ffe,0x3ffe,0x3ffe,0x3ffe,0x3ffe,0x3ffe
     dw    0,0,0,0xE00,0x1F00,0x1F00,0xE00,0,0,0    ;"."
     dw    0x181f,0xC11,0x611,0x31f,0x1C0,0x60,0x1F38,0x110c,0x1106,0x1F02  ;"%"
    endasm
    normally i would make the font an include and give it a label rather than manually locate it like this
    dt's macro as found in dt-ints is ideal to find and numerate the font address
    GetAddress macro Label, Wout
    CHK?RP Wout
    movlw low Label ; get low byte
    movwf Wout
    movlw High Label ; get high byte
    movwf Wout + 1
    endm
    when the fonts address is known its simple to use readcode command to retrieve font data
    Last edited by lester; - 8th December 2023 at 08:44. Reason: Changed Thread Title
    Warning I'm not a teacher

  9. #49
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891


    Did you find this post helpful? Yes | No

    Default SSD1306 OLED (72x40) I2C display from scratch - scrolling text

    Just for fun, scrolling text example

    Name:  ScrollingText.png
Views: 215
Size:  412.8 KB
    Attached Files Attached Files
    Roger

  10. #50
    Join Date
    May 2013
    Location
    australia
    Posts
    2,392


    Did you find this post helpful? Yes | No

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

    i'm not seeing a font , i had a look at a 40x18 font this morning with my new 72x40 that just arrived
    encoded this way seems the best compromise for easy of unpacking into a 18 x 5 byte stream to send to display

    Name:  fonts.jpg
Views: 213
Size:  273.3 KB
    Name:  40x18.jpg
Views: 212
Size:  52.2 KB







    i dont like most of you inital sfr settings
    i would replace the entire section with
    OSCCON = $70 ;% 01110000 'Internal RC set to 8MHZ


    for these reasons
    OPTION_REG = % 10000000 'PORT A&B Pull-Ups disabled (see WPUA & WPUB)
    Pull-Ups are set that way by default anyway . that does other things to that may later prove to be incorrect Like set int edge to falling, reassign and alter the prescaler, change timer 0 clock source

    OSCCON = % 11100000 'Internal RC set to 8MHZ
    no 'OSCCON = % 01110000 for 8mhz you have set it for 4 mhz


    ANSEL = % 00010100 'Select analog inputs Channels 0 to 7 (AN2 + AN4 selected)
    ok but you then go on to make those pins be digital outputs , not recommended except for smoke generation if used as analog inputs


    ADCON0 = % 10000000 'A/D Module (Bit5:2 select channels 0:11)
    ADCON1 = % 00000000 'A/D control register
    why ? makes no sense adc is off by default


    CM1CON0 = % 00000000 'Comparator1 Module is OFF
    CM2CON0 = % 00000000 'Comparator2 Module is OFF
    why ? Comparator 1 and 2 Modules are OFF by default


    INTCON = % 00000000 'INTerrupts CONtrol (TMR0 OFF)
    why serves no purpose ints are off by default


    TRISA = % 00000000 'Set Input/Output (0 to 5)
    bad call when an2
    TRISB = % 00000000 'Set Input/Output (4 to 7)
    bad call when 4,6 used for i2c
    TRISC = % 00000000 'Set Input/Output (0 to 7)
    bad call when an4


    why ? i2c pins can left as be inputs
    when breadboarding leave unused pins as inputs. fine set them as low outputs for the "production" version if a few microwatts of power dissipation makes a difference



    PORTB = % 00000000 'Ports High/Low (4 to 7)
    why ? i2c pins being set low is not useful
    Warning I'm not a teacher

  11. #51
    Join Date
    May 2013
    Location
    australia
    Posts
    2,392


    1 out of 1 members found this post helpful. Did you find this post helpful? Yes | No

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

    i have tried a 14x10 , a 14x10 doubled to 28x20
    a 13x7 doubled to 26x14 and tripled to 39x21
    they all work ok. imho by leaps and bounds a 40x18 full size font looks best and is only 540 words for ten digits

    Last edited by richard; - 9th December 2023 at 07:12.
    Warning I'm not a teacher

  12. #52
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891


    Did you find this post helpful? Yes | No

    Default SSD1306 OLED (72x40) I2C display from scratch

    Richard,

    You're absolutely right about the useless register settings I mention in my code.

    Most of them, if not all, just reflect their default state as per datasheet.

    This is because I use a pic specific template so they are there everytime I start a new project and ready to be deleted in case of no use

    BTW, your video looks great!!
    Roger

  13. #53
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891


    Did you find this post helpful? Yes | No

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

    Quote Originally Posted by Ioannis View Post
    These LCD's are difficult to use. Indeed there are too many parameters to set....
    Yes, I agree, this is definitively the hardest part to get it work.

    Richard, how did you come to this $68 value please? I can't figure it out

    Name:  2023-12-12 17_44_38-SSD1306 COMMAND reference.pdf - [SSD1780] - SumatraPDF.png
Views: 158
Size:  23.7 KB



    '======= 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 = $F0 : GOSUB SEND_COMMAND ' set divide ratio
    COM = $A8 : GOSUB SEND_COMMAND ' set multiplex ratio
    COM = $27 : GOSUB SEND_COMMAND ' 1/40 duty
    COM = $D3 : GOSUB SEND_COMMAND ' set display offset
    COM = $00 : GOSUB SEND_COMMAND
    COM = $40 : GOSUB SEND_COMMAND ' set display start line
    COM = $8D : GOSUB SEND_COMMAND ' set Charge Pump enable/disable
    COM = $14 : GOSUB SEND_COMMAND ' set(0x10) disable
    COM = $20 : GOSUB SEND_COMMAND ' Addressing Setting Command Table
    COM = $00 : GOSUB SEND_COMMAND ' Page Addressing Mode
    COM = $A1 : GOSUB SEND_COMMAND ' set segment re-map: column address 127 is mapped to SEG0
    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 ' Sequential COM pin configuration
    COM = $AD : GOSUB SEND_COMMAND ' Internal IREF Setting
    COM = $30 : GOSUB SEND_COMMAND ' --
    COM = $81 : GOSUB SEND_COMMAND ' set contrast control register
    COM = $2F : GOSUB SEND_COMMAND ' set contrast value 0..255
    COM = $D9 : GOSUB SEND_COMMAND ' set pre-charge period
    COM = $22 : GOSUB SEND_COMMAND ' set pre-charge value
    COM = $DB : GOSUB SEND_COMMAND ' set vcomh deselect level
    COM = $20 : GOSUB SEND_COMMAND ' set vcomh value
    COM = $A4 : GOSUB SEND_COMMAND ' Disable Entire Display On
    COM = $A6 : GOSUB SEND_COMMAND ' set normal display
    COM = $0C : GOSUB SEND_COMMAND ' set lower column address
    COM = $11 : GOSUB SEND_COMMAND ' set higher column address
    COM = $68 : GOSUB SEND_COMMAND ' set display start line register
    COM = $AF : GOSUB SEND_COMMAND ' turn on OLED panel
    Last edited by flotulopex; - 12th December 2023 at 17:02.
    Roger

  14. #54
    Join Date
    May 2013
    Location
    australia
    Posts
    2,392


    Did you find this post helpful? Yes | No

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

    Richard, how did you come to this $68 value please? I can't figure it out
    the info supplied with the display makes calculating the value somewhat difficult . in fact i cannot see the connection at all

    the command basically sets where the memory line representing page 0 bit 0 maps to the physical display top row pixels, it can be vertically offset by 0 to 63 pixels in a virtually identical way to the way the display scrolls horizontally

    it needed to be offset by -23 pixels to get the top row to align with page 0 bit 0

    command range = 0x40 to 0x7f , 0x7f - 23 = 0x68
    Last edited by richard; - 12th December 2023 at 21:23.
    Warning I'm not a teacher

  15. #55
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891


    Did you find this post helpful? Yes | No

    Default SSD1306 OLED (72x40) I2C display from scratch

    Well, I think I'm just gonna remember this settings "as is".

    Thanks for trying to make things more clear for me
    Roger

  16. #56
    Join Date
    Feb 2013
    Posts
    1,079


    Did you find this post helpful? Yes | No

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

    This is very interesting thread, giving me some hope that I will be able to use OLED screens with PBP one day, but I have a quesiton - 24C64 or something like that costs under $1. Why not use it for font storage?

  17. #57
    Join Date
    May 2013
    Location
    australia
    Posts
    2,392


    Did you find this post helpful? Yes | No

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

    I have a quesiton - 24C64 or something like that costs under $1. Why not use it for font storage

    because you can save your $1 and another one by buying a better pic to start with and :-

    not have a costlier more complex circuit board .
    use a standard font file generated by glcd font creator.
    its faster, uses hardware i2c and can do proper graphics too.

    as i said at the beginning if you want easy get a pic 18

    Name:  prices.jpg
Views: 136
Size:  173.6 KB
    Last edited by richard; - 16th December 2023 at 04:58.
    Warning I'm not a teacher

  18. #58
    Join Date
    Feb 2013
    Posts
    1,079


    Did you find this post helpful? Yes | No

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

    So expensive
    I'm buying 2nd hand 886 and 1829 for about 50 and 90 cents in China
    Since I'm not doing anything commercial, this is just fine for me.

  19. #59
    Join Date
    Feb 2013
    Posts
    1,079


    Did you find this post helpful? Yes | No

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

    And by the way, I don't see any reasons, why you can't write GLCD (which can't save file on windows 10-11) generated or any other software generated font into external EEPROM.

  20. #60
    Join Date
    May 2013
    Location
    australia
    Posts
    2,392


    Did you find this post helpful? Yes | No

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

    don't see any reasons, why you can't write GLCD generated or any other software generated font into external EEPROM.
    Nor do I , but I have never come anything to make a bin or hex file easily from the generated code




    (which can't save file on windows 10-11)
    mine works perfectly win 10 and 11 , make sure to add the .lcd extension to the file name when saving it otherwise it goes funny
    Warning I'm not a teacher

  21. #61
    Join Date
    Aug 2011
    Posts
    415


    Did you find this post helpful? Yes | No

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

    Why not use it for font storage?
    Because this thread will be followed with "how can I speed up my OLED display routines?".

    The choice is obviously yours, but the 18F27Q43 has 128K of flash, 8K of ram, and runs at 64MHz.
    The only downside is the hardware I2C peripheral isn't compatible with the old MSSP I2C, so you're stuck using PBP's software I2CWRITE/I2CREAD or rolling your own (which is not trivial for these new parts).

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

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