OLED Display
Intro

OLED and I2C Words

oled-emit works like the standard word emit. It blocks the calling thread, as long as the character is not written to the OLED display (less than 300 us for a 6x8 character and 400 kHz I2C). Horizontal (x) position is in pixel (0 to 127), vertical position (y) is in lines, a line consists of 8 pixels. Larger fonts takes more than one line.

oled-emit    ( Char -- )        Emits a character (writes a character to the OLED display)
oled-emit?   ( -- Flag )        OLED ready to get a character (I2C not busy)

hook-emit    ( -- a-addr )      Hooks for redirecting terminal IO on the fly
hook-emit?   ( -- a-addr )    

oledpos!     ( x y -- )         Set OLED cursor position, 
                                x horizontal position, for 6x8 font max. (128 / 6) -1, depends on the font's x size 
                                y vertical position (a line consists of 8 pixels), max. 3 for 128x32 or 7 for 128x64 displays.
oledpos@     (  -- x y )        Get the current OLED cursor position
oledcmd      ( c-addr -- )      Send command to the OLED controller SSD1306. First byte contains the length of the command.
oledclr      (  --  )           Clears the OLED display, sets the cursor to 0, 0
oledfont     ( u --  )          Select the font, u: 0 6x8, 1 8x8, 2 8X16 , 3 12X16

I2Cdev       ( u -- )           Sets the 7-bit I2C address
I2CTx        ( c-addr u -- )    c-addr buffer address for the message with lengh u to send
I2CRx        ( c-addr u -- )    c-addr buffer address for the message to receive
I2CTxRx      ( a1 u1 a2 u2 -- ) a1 buffer address for the message to send, a2 buffer address for the message to receive

Usage

It is easy to redirect the terminal output to the OLED display, to use the string formatting words.

: oled-hallo (  -- )
  hook-emit @              \ save emit hook
  ['] oled-emit hook-emit ! \ redirect terminal to oled-emit
  ." Hallo Velo! " cr
  ." ciao"
  hook-emit !         \ restore old hook
;

: clock (  -- )
  oledclr
  hook-emit @              \ save emit hook
  ['] oled-emit hook-emit ! \ redirect terminal to oled-emit
  -1 -1 -1 alarm!
  begin
    wait-alarm  \ wait a second
    .time
    0 0 oledpos!
  key? until
  key drop 
  hook-emit !         \ restore old hook
;

-- Peter Schmid - 2020-12-29

Topic attachments
I Attachment History Action Size Date Who Comment
PNGpng Codepage-850.png r1 manage 2.4 K 2021-01-05 - 21:21 PeterSchmid  
JPEGjpg oled-mecrisp-cube-header.jpg r1 manage 66.2 K 2021-01-02 - 22:14 PeterSchmid  
JPEGJPG oled-mecrisp-cube.JPG r1 manage 5100.2 K 2021-01-02 - 22:14 PeterSchmid  
Edit | Attach | Watch | Print version | History: r14 < r13 < r12 < r11 < r10 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r14 - 2021-01-16 - PeterSchmid
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2021 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback