Menu

Confused on Adding new fonts

Help
Chris S
2018-01-06
2018-01-07
  • Chris S

    Chris S - 2018-01-06

    I am using an SSD1306 display and I want to display the degree (ascii 248) symbol. Ive read and looked at this tutorial on how to add in my own font, but Im still a little confused.
    https://sourceforge.net/p/gcbasic/blog/2017/09/create-your-own-oled-characters-on-your-glcd-noreplyinsfnet/

    It displays "mu" just fine. I found a SSD1306 font converter so I used that.
    http://oleddisplay.squix.ch/#/home
    Is one I found. I tried comparing it with the acii symbol for "mu", which is ascii 238. According to the converter, mu should be "0xFF, 0xFF, 0x00, 0x04", which does not match what was in the tutorial here. In fact it makes the display freak out and scroll through everything. So needless to say, Im a little bit lost and scratching my head.

    Code is included just in case.

    '''A demonstration program for GCGB and GCB.
    '''--------------------------------------------------------------------------------------------------------------------------------
    '''This program
    '''
    '''
    '''@author
    '''@licence GPL
    '''@version
    '''@date    01.11.2015
    '''********************************************************************************
    
    ; ----- Configuration
      #chip 18f13k22, 16
      #config LVP = Off
      #config MCLRE = OFF
      #config WDTEN= OFF
      #option Explicit
    
      #include <glcd.h>
    ; ----- Define Hardware settings
        ' Define I2C settings - CHANGE PORTS if required for your specific device.
    
      #define HI2C_BAUD_RATE 400
      #define HI2C_DATA PORTb.0
      #define HI2C_CLOCK PORTb.1
      ;I2C pins need to be input for SSP module when used on Microchip PIC device
      Dir HI2C_DATA in
      Dir HI2C_CLOCK in
      #define OLEDFont1Data myOLEDFont1Data
    ; ----- Define GLCD Hardware settings
      #define GLCD_TYPE GLCD_TYPE_SSD1306
      #define GLCD_I2C_Address 0x78
      #define AD_Delay 1000 us
       #define GLCD_OLED_FONT 
    Table myOLEDFont1Data
    
        1, 0x00                   ' Space
        1, 0x5E                   ' !
        3, 0x06, 0x00, 0x06     ' "
        5, 0x40, 0x3e, 0x20, 0x20, 0x1e    ' mu
        5, 0x24, 0x2A, 0x7F, 0x2A, 0x10 ' $
        3, 0x62, 0x18, 0x46     ' %
        5, 0x30, 0x4C, 0x5A, 0x24, 0x50 ' &
        1, 0x06                   ' '
        2, 0x3C, 0x42              ' (
        2, 0x42, 0x3C              ' )
        5, 0x28, 0x10, 0x7C, 0x10, 0x28 ' *
        3, 0x10, 0x38, 0x10     ' +
        1, 0xC0                   ' ,
        3, 0x10, 0x10, 0x10     ' -
        1, 0x40                   ' .
        3, 0x60, 0x18, 0x06     ' /
        4, 0x3C, 0x42, 0x42, 0x3C   ' 0
        3, 0x44, 0x7E, 0x40     ' 1
        4, 0x44, 0x62, 0x52, 0x4C   ' 2
        3, 0x4A, 0x4A, 0x34     ' 3
        4, 0x1E, 0x10, 0x7C, 0x10   ' 4
        3, 0x4E, 0x4A, 0x32     ' 5
        4, 0x3C, 0x4A, 0x4A, 0x30   ' 6
        3, 0x62, 0x12, 0x0E     ' 7
        4, 0x34, 0x4A, 0x4A, 0x34   ' 8
        4, 0x0C, 0x52, 0x52, 0x3C   ' 9
        1, 0x48                   ' :
        2, 0x80, 0x68              ' ;
        3, 0x10, 0x28, 0x44     ' <
        3, 0x28, 0x28, 0x28     ' =
        3, 0x44, 0x28, 0x10     ' >
        3, 0x02, 0x52, 0x0C     ' ?
        5, 0x38, 0x44, 0x54, 0x54, 0x58 ' @
        4, 0x7C, 0x12, 0x12, 0x7C   ' A
        4, 0x7E, 0x4A, 0x4A, 0x34   ' B
        4, 0x3C, 0x42, 0x42, 0x24   ' C
        4, 0x7E, 0x42, 0x42, 0x3C   ' D
        3, 0x7E, 0x4A, 0x4A     ' E
        3, 0x7E, 0x0A, 0x0A     ' F
        4, 0x3C, 0x42, 0x52, 0x34   ' G
        4, 0x7E, 0x08, 0x08, 0x7E   ' H
        3, 0x42, 0x7E, 0x42     ' I
        3, 0x42, 0x42, 0x3E     ' J
        4, 0x7E, 0x08, 0x14, 0x62    ' K
        3, 0x7E, 0x40, 0x40     ' L
        5, 0x7E, 0x04, 0x08, 0x04, 0x7E ' M
        5, 0x7E, 0x04, 0x18, 0x20, 0x7E ' N
        4, 0x3C, 0x42, 0x42, 0x3C   ' O
        4, 0x7E, 0x12, 0x12, 0x0C   ' P
        4, 0x3C, 0x42, 0x42, 0xBC   ' Q
        4, 0x7E, 0x12, 0x12, 0x6C   ' R
        4, 0x44, 0x4A, 0x4A, 0x30   ' S
        3, 0x02, 0x7E, 0x02     ' T
        4, 0x3E, 0x40, 0x40, 0x3E   ' U
        5, 0x06, 0x18, 0x60, 0x18, 0x06 ' V
        5, 0x3E, 0x40, 0x3E, 0x40, 0x3E ' W
        5, 0x42, 0x24, 0x18, 0x24, 0x42 ' X
        4, 0x9E, 0xA0, 0xA0, 0x7E   ' Y
        4, 0x62, 0x52, 0x4A, 0x46   ' Z
        2, 0x7E, 0x42              ' [
        3, 0x06, 0x18, 0x60     ' Backslash
        2, 0x42, 0x7E              ' ]
        3, 0x20, 0x10, 0x20     ' ^
        4, 0x80, 0x80, 0x80, 0x80   ' _
        2, 0x04, 0x08              ' `
        4, 0x20, 0x54, 0x54, 0x78   ' a
        4, 0x7E, 0x44, 0x44, 0x38   ' b
        4, 0x38, 0x44, 0x44, 0x28   ' c
        4, 0x38, 0x44, 0x44, 0x7E   ' d
        4, 0x38, 0x54, 0x54, 0x58   ' e
        2, 0x7C, 0x0A              ' f
        4, 0x98, 0xA4, 0xA4, 0x7C   ' g
        4, 0x7E, 0x04, 0x04, 0x78   ' h
        1, 0x7A                   ' i
        2, 0x40, 0x3A              ' j
        4, 0x7E, 0x10, 0x28, 0x44   ' k
        1, 0x7E                   ' l
        5, 0x7C, 0x04, 0x78, 0x04, 0x78 ' m
        4, 0x7C, 0x04, 0x04, 0x78   ' n
        4, 0x38, 0x44, 0x44, 0x38   ' o
        4, 0xFC, 0x24, 0x24, 0x18   ' p
        4, 0x18, 0x24, 0x24, 0xFC   ' q
        2, 0x7C, 0x04              ' r
        4, 0x48, 0x54, 0x54, 0x20   ' s
        3, 0x04, 0x3E, 0x44     ' t
        4, 0x3C, 0x40, 0x40, 0x3C    ' u
        5, 0x0C, 0x30, 0x40, 0x30, 0x0C ' v
        5, 0x3C, 0x40, 0x3C, 0x40, 0x3C ' w
        5, 0x44, 0x28, 0x10, 0x28, 0x44 ' x
        4, 0x9C, 0xA0, 0xA0, 0x7C   ' y
        3, 0x64, 0x54, 0x4C     ' z
        3, 0x08, 0x36, 0x41     ' {
        1, 0xFF                   ' |
        3, 0x41, 0x36, 0x08         ' }
        4, 0x20, 0x10, 0x20, 0x10   '// ~
        1, 0x00                   ' 127th...
    End Table
      ; ----- Define variables
    GLCDCLS
    Do Forever
    
    
      GLCDfntDefaultSize = 1
      GLCDPrint (0, 0, "TEST STRING")
      GLCDPrint (0, 20, "#")
    
    
    Loop
    end
    
     

    Last edit: Chris S 2018-01-06
  • Anobium

    Anobium - 2018-01-06

    I am confused by the post.

    degree (ascii 248) symbol.
    - I think degree is 0xb0 or d176. Do not get hung up on this.

    It displays "mu" just fine. I found a SSD1306 font converter so I used that.
    - What is the baseline code for this working?

    with the acii symbol for "mu", which is ascii 238. According to the converter, mu should be "0xFF, 0xFF, 0x00, 0x04", which does not match what was in the tutorial here. In fact it makes the display freak out and scroll through everything. So needless to say, Im a little bit lost and scratching my head.
    - But, the format of the font generated from that tool may not be the same format format.

    Can I confirm that you just want to replace a character with the degree character?

     
    • Chris S

      Chris S - 2018-01-06

      Yes. That is what I am trying to do.

       
  • Anobium

    Anobium - 2018-01-06

    The type 1 OLED font set is a variable width px (specified by the first parameters of the character) by 8px height with 'column major' and 'little endian data sets'. See http://dotmatrixtool.com/#

    The code segment below.... I have only changed the 4th character of the fontset is 5, 0x06, 0x09, 0x06, 0x00, 0x00 a degree sign.

    1, 0x00                   ' Space
    1, 0x5E                   ' !
    3, 0x06, 0x00, 0x06     ' "
    5, 0x06, 0x09, 0x06, 0x00, 0x00   ' degree
    5, 0x24, 0x2A, 0x7F, 0x2A, 0x10 ' $
    3, 0x62, 0x18, 0x46     ' %
    5, 0x30, 0x4C, 0x5A, 0x24, 0x50 ' &
    .... the rest of the table.
    

    For GLCDPrint ( 2, 1, "35.00#") generates 35.00°. As the degree sign has replaced the # and is 5px wide.

    Full code is attached.

     

    Last edit: Anobium 2018-01-06
    • Chris S

      Chris S - 2018-01-06

      This works well. Did you just draw a degree character with that tool?

       
      • Anobium

        Anobium - 2018-01-07

        The resource for the fonts sets is https://github.com/PIC-Nico/StartPIC18/blob/master/OLED-Display/font.h When I got the StartPIC18 board I ported the projects to Great Cow BASIC finding these fonts are part of the project.

        These fonts sets uses two methods to define the character.

        1. Type 1 OLED font set is a variable width px (specified by the first parameters of the character) by 8px height with 'column major' and 'little endian data sets'.
        2. Type 2 OLED font is a fix width and fix height therefore a fixed proportional fixed with 20 bytes of data per character. This font is larger of 10px by 16 px.

        To create the degree? I opened up and existing demo I had with the character. :-) But, you can - you could move the degree character around to change.

        :-)

        P.S. I will look at using the http://oleddisplay.squix.ch/#/home fonts in the future - it is not hard to create a utility that uses the fonts defined on this site.

        P.P.S. I have added the demo code to GitHub. Do not want to loose the program. See here

         

        Last edit: Anobium 2018-01-07

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.