Menu

SSD1306 ASCII character symbols

Haroen
2022-12-07
2023-01-18
<< < 1 2 3 4 > >> (Page 3 of 4)
  • Anobium

    Anobium - 2023-01-02

    I tinkered with the code in that new demo.

    I may have restored the ability to show characters and have the XOR graphics. Do try to see if characters now display.

    I think the code can be optimised. So, please do adapt for performance. 〰️

     
  • Anobium

    Anobium - 2023-01-02

    Here is the source for the new page for Fonts and Characters = https://github.com/GreatCowBASIC/Help/blob/main/source/fontsandcharacters.adoc

    Please update as you wish in GitHub. I can then 'update' to create the new Help.

    The image does not shown in the GitHub source but it is shown in the attached CHM file. You will have to UNBLOCK the CHM if you download from this post.

     
  • stan cartwright

    stan cartwright - 2023-01-02

    How to change the Xscale (µs) in code easily?
    Er... it's not a "real" oscilloscope :)
    ptr2=ptr2+4 ;x position for start and end line x positions
    This is the code I wrote for "oscilloscope". It is not the synwrite demo which just plots, this joins the dots.
    I'll wire up a ssd1306 to a 328 and test this but I thought it was easy to redefine a char set anyway but never tried.
    I never learnt how to use Github or download anything.
    my xor scope video https://www.youtube.com/watch?v=AamRBAAmaZA

    'oled XOR pixel scope. copy/rename PSet_SSD1306 to xorPSet_SSD1306
    #chip mega328p,16
    #option explicit
    #include <UNO_mega328p.h>
    #include <glcd.h>
    #define HI2C_BAUD_RATE 400
    #define HI2C_DATA
    HI2CMode Master
    #define GLCD_TYPE GLCD_TYPE_SSD1306
    #define GLCD_I2C_Address 0x78
    '#define ADSpeed LowSpeed
    
    'Defines for a 7 pin SPI module
    'RES pin is pulsed low in glcd_SSD1306.h for proper startup
    '#define MOSI_SSD1306 PortB.1
    '#define SCK_SSD1306 PortB.2
    '#define DC_SSD1306 PortB.3
    '#define CS_SSD1306 PortB.4
    '#define RES_SSD1306 PortB.5
    '; ----- Define GLCD Hardware settings
    '#define GLCD_TYPE GLCD_TYPE_SSD1306
    '#define S4Wire_DATA
    
    dir portc.0 in
    dim volt as byte
    dim ptr1 as Byte
    dim ptr2 as byte
    dim buffer1 (32)
    dim buffer2 (32)
    dim xpos_new as byte
    dim ypos_new as byte
    dim xpos_old as byte
    dim ypos_old as byte
    dim xpos1_new as byte
    dim ypos1_new as byte
    dim xpos1_old as byte
    dim ypos1_old as byte
    ;
    for ptr1=0 to 31 ;read 32 samples
      volt = READAD (an0)
      buffer1 (ptr1)=volt/4
      buffer2 (ptr1)=buffer1 (ptr1)
    next ptr1
    ;
    GLCDCLS
    do
    ptr1=0
    ptr2=0
    do until ptr1>30
    ypos_old=buffer2 (ptr1) ;old data
    ypos_new=buffer2 (ptr1+1)
    xpos_new=ptr2+4
    ;
    ypos1_old=buffer1 (ptr1) ;new data
    ypos1_new=buffer1 (ptr1+1)
    xpos1_new=ptr2+4
    ;
    line ptr2,ypos_old,xpos_new,ypos_new,0 ;erase last data
    line ptr2,ypos1_old,xpos1_new,ypos1_new,1 ;draw new data
    ;
    ptr1=ptr1+1 ;data pointer
    ptr2=ptr2+4 ;x position for start and end line x positions
    loop
    ;
    for ptr1=0 to 31 ;get new samples
      volt = READAD (an0)
      repeat 2 ;scale 256 bit sample to 64 pixels ie divide by 4
        set c off
        rotate volt right
      End Repeat
      buffer2 (ptr1)=buffer1 (ptr1) ;new data to old data
      buffer1 (ptr1)=volt ;update new data
    next ptr1
    ;
    loop
    ;
    '#define PSet_SSD1306 xorPSet_SSD1306
    'dim GLCDDATATEMP as word
    'dim GLCDBITNO as byte
    'dim GLCDCHANGE as byte
    ';
    'dir portc.0 in
    'dim volt as byte
    'dim xpos as byte
    'dim buffer1 (128)
    'dim buffer2 (128)
    ';
    'for xpos=0 to 127 ;init read 128 samplesc 1st time
    '  volt = READAD (an0)
    '  buffer1 (xpos)=volt/4
    '  buffer2 (xpos)=volt/4
    'next xpos
    ';
    'glcdcls
    ';draw grid
    'line 0,31,128,32
    'line 63,0,63,63
    ';
    'for xpos=0 to 127
    '  pset xpos,buffer1(xpos),1 ;plot data 1st time for xor
    'next xpos
    ';
    ';start
    'do
    'for xpos=0 to 127
    '  pset xpos,buffer1(xpos),1 ;erase old data
    '  pset xpos,buffer2(xpos),1 ;plot new data
    'next xpos
    ';
    'for xpos=0 to 127
    '  buffer1 (xpos)=buffer2 (xpos) ;copy new data to old data
    '  volt = READAD (an0)
    '  Repeat 2
    '    set c off
    '    rotate volt right
    '  End Repeat
    ' buffer2 (xpos)=volt ;save new data
    'next xpos
    ';
    'loop
    '; end of main
    ';
    '; renamed glcd library function
    ''''Draws a pixel on the GLCD
    ''''@param GLCDX X coordinate of pixel
    ''''@param GLCDY Y coordinate of pixel
    ''''@param GLCDColour State of pixel ( GLCDBackground | GLCDForeground )
    'Sub xorPSet_SSD1306(In GLCDX, In GLCDY, In GLCDColour As Word)
    '    'Set pixel at X, Y on LCD to State
    '    'X is 0 to 127
    '    'Y is 0 to 63
    '    'Origin in top left
    '  #if GLCD_TYPE = GLCD_TYPE_SSD1306
    '          'SSD1306_BufferLocationCalc = ( GLCDY / 8 )* GLCD_WIDTH
    '          'faster than /8
    '          SSD1306_BufferLocationCalc = GLCDY
    '          Repeat 3
    '            Set C Off
    '            Rotate SSD1306_BufferLocationCalc Right
    '          End Repeat
    '          SSD1306_BufferLocationCalc = SSD1306_BufferLocationCalc * GLCD_WIDTH
    '
    '          SSD1306_BufferLocationCalc = GLCDX + SSD1306_BufferLocationCalc+1
    '          GLCDDataTemp = SSD1306_BufferAlias(SSD1306_BufferLocationCalc)
    '
    '          'Change data to set/clear pixel
    '          GLCDBitNo = GLCDY And 7
    '          If GLCDColour.0 = 0 Then
    '            GLCDChange = 254
    '            Set C On
    '          Else
    '            GLCDChange = 1
    '            Set C Off
    '          End If
    '          Repeat GLCDBitNo
    '            Rotate GLCDChange Left
    '          End Repeat
    '
    '          If GLCDColour.0 = 0 Then
    '             GLCDDataTemp = GLCDDataTemp And GLCDChange
    '          Else
    '             GLCDDataTemp = GLCDDataTemp xOr GLCDChange
    '          End If
    '
    '          SSD1306_BufferAlias(SSD1306_BufferLocationCalc) = GLCDDataTemp
    '          Cursor_Position_SSD1306 ( GLCDX, GLCDY )
    '          Write_Data_SSD1306 ( GLCDDataTemp )
    '
    '  #endif
    '
    'End Sub
    
     

    Last edit: stan cartwright 2023-01-02
  • Haroen

    Haroen - 2023-01-03

    While I was tinkering with the code to try your changes I am learning more and more how GCB works. Sometimes text was even up-side-down and mirrored :)

    I may have restored the ability to show characters and have the XOR graphics. Do try to see if characters now display.

    I could replicate the issue and think this is still a character problem:
    If I use "#Define GLCD_PROTECTOVERRUN" in the oscilloscope code and then stop the oscilloscope graphic and then try to display some text all is up-side-down and mirrored?

    ptr2=ptr2+4 ;x position for start and end line x positions

    How could the Xscale multiplied by 2 or divided by 2?

    I never learnt how to use Github

    Me neither, but I can supply Evan with the info for now.

     

    Last edit: Haroen 2023-01-03
  • stan cartwright

    stan cartwright - 2023-01-04

    This sets xor and print and erases "test" although it's set to foreground
    ie glcdprint (0,0,"test",1).
    This must be dated code by Anobium.
    I have not used ssd1306 on gcb for years.

    do
    GLCDPrint (0,0,"test",1)
    wait 1 s
    GLCDPrint (0,0,"test",0)
    wait 1 s
    loop
    

    inverts the text to black on white

    GLCDPrintLargeFont 0,0, "HELLO"
    do
    GLCDPrint (0,0,"test",1)
    wait 1 s
    GLCDPrint (0,0,"test",1)
    wait 1 s
    loop
    

    This does not restore the large "hello".

    'oled XOR pixel flashing "test"
    #chip mega328p,16
    #option explicit
    #include <UNO_mega328p.h>
    #include <glcd.h>
    #define HI2C_BAUD_RATE 400
    #define HI2C_DATA
    HI2CMode Master
    #define GLCD_TYPE GLCD_TYPE_SSD1306
    #define GLCD_I2C_Address 0x78
    ;
    #define PSet_SSD1306 xorPSet_SSD1306
    
    dim GLCDDATATEMP as word
    dim GLCDBITNO as byte
    dim GLCDCHANGE as byte
    
    ;-- start
    glcdcls
    do
    GLCDPrint (0,0,"test",1)
    wait 1 s
    GLCDPrint (0,0,"test",1)
    wait 1 s
    loop
    ;--- end
    
    ; renamed glcd library function
    '''Draws a pixel on the GLCD
    '''@param GLCDX X coordinate of pixel
    '''@param GLCDY Y coordinate of pixel
    '''@param GLCDColour State of pixel ( GLCDBackground | GLCDForeground )
    Sub xorPSet_SSD1306(In GLCDX, In GLCDY, In GLCDColour As Word)
        'Set pixel at X, Y on LCD to State
        'X is 0 to 127
        'Y is 0 to 63
        'Origin in top left
      #if GLCD_TYPE = GLCD_TYPE_SSD1306
              'SSD1306_BufferLocationCalc = ( GLCDY / 8 )* GLCD_WIDTH
              'faster than /8
              SSD1306_BufferLocationCalc = GLCDY
              Repeat 3
                Set C Off
                Rotate SSD1306_BufferLocationCalc Right
              End Repeat
              SSD1306_BufferLocationCalc = SSD1306_BufferLocationCalc * GLCD_WIDTH
    
              SSD1306_BufferLocationCalc = GLCDX + SSD1306_BufferLocationCalc+1
              GLCDDataTemp = SSD1306_BufferAlias(SSD1306_BufferLocationCalc)
    
              'Change data to set/clear pixel
              GLCDBitNo = GLCDY And 7
              If GLCDColour.0 = 0 Then
                GLCDChange = 254
                Set C On
              Else
                GLCDChange = 1
                Set C Off
              End If
              Repeat GLCDBitNo
                Rotate GLCDChange Left
              End Repeat
    
              If GLCDColour.0 = 0 Then
                 GLCDDataTemp = GLCDDataTemp And GLCDChange
              Else
                 GLCDDataTemp = GLCDDataTemp xOr GLCDChange
              End If
    if SSD1306_BufferAlias(SSD1306_BufferLocationCalc)<> GLCDDataTemp then
              SSD1306_BufferAlias(SSD1306_BufferLocationCalc) = GLCDDataTemp
              Cursor_Position_SSD1306 ( GLCDX, GLCDY )
              Write_Data_SSD1306 ( GLCDDataTemp )
    end if
      #endif
    
    End Sub
    
     

    Last edit: stan cartwright 2023-01-04
  • Haroen

    Haroen - 2023-01-06

    I tried the above code.
    Thanks Stan, that makes sense.

     
  • stan cartwright

    stan cartwright - 2023-01-06

    Anobium- I found a bread board wired for ssd1306 and 3K9R pullups and 328 nano but it had a lgt328 on the board and it did not work.
    I then remembered lgt328 is 3.3V logic and can not remember if it ever worked. Code was changed to #chip lgt328.
    Changing to 328p nano, same pinout and it worked?
    Does it need a logic level converter like ili9341 does with arduino 328p nano as ili9341 is 3.3V logic but the other way around that ssd1306 is 5V logic and lgt328 is 3.3V logic... if you follow my drift?

     
    • Anobium

      Anobium - 2023-01-07

      I dont know the answer. The max operating voltage of the GLCD Is the constraint. The operating of the micro-controller needs to match the operating voltage of the GLCD.

       
  • stan cartwright

    stan cartwright - 2023-01-06

    Why does this not restore large hello?
    GLCDPrintLargeFont 0,0, "HELLO"
    do
    GLCDPrint (0,0,"test",1)
    wait 1 s
    GLCDPrint (0,0,"test",1)
    wait 1 s

    It doesn't restore a line
    line 0,4,48,4,1
    do
    GLCDPrint (0,0,"test",1)
    wait 1 s
    GLCDPrint (0,0,"test",1)
    wait 1 s

     
    • Anobium

      Anobium - 2023-01-07

      Does the program use XOR or stock PSET?

       
      • stan cartwright

        stan cartwright - 2023-01-07

        My above code xor flashing "test".
        do
        GLCDPrint (0,0,"test",1)
        wait 1 s
        GLCDPrint (0,0,"test",1)
        wait 1 s
        loop

        This prints and erases "test" so xor works with chars.
        I think it is because it writes the char rows but even with your guides and glcd is written in basic, it can be difficult for me to understand.
        My code for ssd1306 is dated 2017.
        It seems that xor changes the pset to xor and chars are plotted but seems they are not.
        Clueless, stan
        ssd1306 works with picomite which is 3.3V logic and no pullup resistors as it uses hard ware pin pull ups.

         
        • Anobium

          Anobium - 2023-01-07

          Attach, don't insert/post, your code. I wouldbe guessing without the code.

           
  • stan cartwright

    stan cartwright - 2023-01-07

    This the above code you could have copied/pasted.
    This just an observation from Haroen's posts mentioning xor.
    I never tried xoring chars before.

     
    • Anobium

      Anobium - 2023-01-07

      You program xor_texttest.gcb is different from the code above.

      Why? In the demo have restored PSET and then call the XORPSET to draw the graphics. This way the glcdtext is displayed as expected and the graphics from the scope are XOR'd.

      The updated demo - can you download this version as a new baseline.

      https://github.com/GreatCowBASIC/Demonstration_Sources/tree/main/GLCD_Solutions/GLCD_Simple_Oscilloscope

       
  • stan cartwright

    stan cartwright - 2023-01-07

    OK, copy/pasted from link
    commented
    'Footer
    '© 2023 GitHub, Inc.
    'Footer navigation
    'Ter
    and it worked although very different to my scope I posted as thank you for writing xor code.
    You do the code and I try to show examples/videos.
    If this is a base line can it be stripped to just text for testing?

    'Draw the grid
    line 0,GLCD_HEIGHT/2,128,GLCD_HEIGHT/2
    line 63,0,63,63
    do
    glcdprint 60,20,"Test,1"
    wait 1 s
    glcdprint 60,20,"Test,1"
    wait 1 s
    loop
    Does not xor chars

    copy/pasted to synwrite as didn't know how to open new file and paste in gcstudio.

     
  • Haroen

    Haroen - 2023-01-08

    @anobium

    Here is the source for the new page for Fonts and Characters = https://github.com/GreatCowBASIC/Help/blob/main/source/fontsandcharacters.adoc

    Please update as you wish in GitHub. I can then 'update' to create the new Help.

    The image does not shown in the GitHub source but it is shown in the attached CHM file. You will have to UNBLOCK the CHM if you download from this post.

    Could you please point out a previous GCB example page how and what I have to fill in?
    I think (Stan and) I could use an introduction on GCB-Github pages modification.

     
    • Anobium

      Anobium - 2023-01-08

      @haroen

      Fair questions.

      An example page is https://github.com/GreatCowBASIC/Help/blob/main/source/glcdoverview.adoc

      But, I will create a quick video to show the process of editing. I will assume you do not have a GitHub account and you want to edit locally ( on your PC ) and send back to the Forum for uploading to GitHub.

       
      • Anobium

        Anobium - 2023-01-08

        Here is a video to help understand the process. I am now using GC Code as the editor - it is by far the easiest method.

        https://youtu.be/KTVXqQFbm64

        Thank you so much for helping.

        Evan

         
        • stan cartwright

          stan cartwright - 2023-01-08

          People's opinion of easy are different but thanks for your time and effort.

           
          👍
          1
          • Haroen

            Haroen - 2023-01-10

            Hey Stan, your post font type is set to very small :-)
            But you are right that it will take me some time to achieve the "easy" level,
            yet I will certainly try.
            I think Anobium meant it's relative easy compared to other methods.

             
  • Haroen

    Haroen - 2023-01-08

    @Stan
    I'm not sure on your bread board setup with a lgt328 (LGT8F328P?) or a 328p nano?
    And if I understand right the last modification Evan made in the PSET, XOR(PSET ) was not backwards compatible with previous written programs? I have none yet but working through most of the examples codes supplied to learn GCB in comparison with previous picaxe, pbp, mplab.

     
    • stan cartwright

      stan cartwright - 2023-01-08

      @Haroen
      LGT328 DID work, it is the adc voltage is 0V to 3.3V, so the graph is a line at the bottom of the screen until I touch the adc pin. Pin compatible with arduino nano 328.
      I have not tried ssd1306 since 2017 from my file dates. Anobium has updated and I gave up with github. If I want a head ache I drink wine the night before :)

       
      👍
      1
  • Haroen

    Haroen - 2023-01-08

    @Anobium

    But, I will create a quick video to show the process of editing.

    Looking forward to it :-)

    I will assume you do not have a GitHub account and you want to edit locally ( on your PC ) and send back to the Forum for uploading to GitHub.

    I used Github once in the past to only download code from someone else about a mechanical engineering study. So I do have a Github account and could learn how to use it for GCB.
    In the earlier post here in this thread I was logged in Github to do this: https://sourceforge.net/p/gcbasic/discussion/579125/thread/0f10731cc9/?page=1#13eb

     

    Last edit: Haroen 2023-01-08
  • stan cartwright

    stan cartwright - 2023-01-08

    Out of interest-your base line xor on lgt328. 0V, 3.3V, 5V.
    Tried running ssd1306 from 3.3V , works the same as 5V supply.
    Not the same floating graph as arduino 328.

     

    Last edit: stan cartwright 2023-01-08
    • Anobium

      Anobium - 2023-01-08

      I wonder why? The speed of the processor?

       
<< < 1 2 3 4 > >> (Page 3 of 4)

Log in to post a comment.