Shop OBEX P1 Docs P2 Docs Learn Events
Fun with SX/B and an OLED — Parallax Forums

Fun with SX/B and an OLED

geekythinggeekything Posts: 53
edited 2006-12-31 19:44 in General Discussion
Hi all,

I've been playing with an OLED (Organic Light Emitting Diode) display and SX/B. Think of OLEDs as looking similar to micro-sized plasmas in terms of colour richness and black levels -- the organic compounds fluoresce directly without backlight.

The display I used was from Sparkfun. The code to initialize and drive the display to produce some pretty circle patterns is below.

Ping me with comments, suggestions, or questions! [noparse]:)[/noparse]

-marc

' =========================================================================
'
'   File...... OLED.SXB
'   Purpose... OLED Test Program
'   Author.... Marc Nicholas
'   E-mail.... geekything (at) gmail (dot) com
'   Started... 20-Aug-2006
'   Updated... 31-Dec-2006
'   Language.. SX/B 1.5
'
' =========================================================================

' -------------------------------------------------------------------------
' Program Description
' -------------------------------------------------------------------------
'
'   Simple program to init an SSD1399-base dOLED and display random patterns
'   See here for the actual device:
'   http://www.sparkfun.com/commerce/product_info.php?products_id=712
'  
'   This example drives the display in pseudo-SPI mode rather than bus mode.
'
'   Note: you could probably port this to a BASICStamp fairly easily.
'
' -------------------------------------------------------------------------
' Device Settings
' -------------------------------------------------------------------------

DEVICE          SX28, OSC4MHZ    ' Should work on any SX chip
FREQ            4_000_000    ' 4Mhz internal oscillator, baby!
ID              "OLEDTest"

' -------------------------------------------------------------------------
' IO Pins
' -------------------------------------------------------------------------
' 
' I'm using 5-bits of Port B.
' Don't try this with Port A pins unless you're familiar with open-drain
' outputs!

SCLK        VAR     RB.0        ' shift clock -- connect to D0
SOUT        VAR     RB.1        ' shift data -- connect to D1
CS        VAR     RB.2        ' chip select -- connect to CS
CMD        VAR    RB.3        ' [noparse][[/noparse]D]ata/[noparse][[/noparse]C]ommand select -- connect to D/C
RS        VAR    RB.4        ' Reset line -- connect to RES


' -------------------------------------------------------------------------
' Constants
' -------------------------------------------------------------------------

' -------------------------------------------------------------------------
' Variables
' -------------------------------------------------------------------------                               

cycle     VAR    BYTE    
params    VAR    BYTE
tmpB1    VAR    BYTE
tmpB2    VAR     BYTE
tmpB3    VAR    BYTE
tmpB4    VAR    BYTE
i    VAR     WORD
rand1    VAR     BYTE
rand2    VAR    BYTE
rand3    VAR    BYTE
rand4    VAR     BYTE
rand5    VAR    BYTE
rand6    VAR    BYTE


' =========================================================================
  PROGRAM Start
' =========================================================================


' -------------------------------------------------------------------------
' Subroutine Declarations
' -------------------------------------------------------------------------

Write_OLED    SUB    1,4
Write_C        SUB     1
Write_D        SUB    1

' -------------------------------------------------------------------------
' Program Code
' -------------------------------------------------------------------------

Start:

' Set Port B to be output
    TRIS_B = %00000000

' Wait 100ms for things to settle down! Probably not really necessary
    PAUSE 100             

' Toggle chip select so that first frame is interpreted    and reset the SSD1339
    CS = 0
    RS = 0
    PAUSE 25
    CS = 1
    RS = 1

' Now comes the OLED setup!

    Write_OLED 0xA0, 0x34          '  Set Re-map / Color Depth 0xb4; 262K 8bit R->G->B
    Write_OLED 0xE3            '  NOP (No OPeration) commands for padding
    
    Write_OLED 0xA1, 0x01        '  Set display start line
    Write_OLED 0xE3

    Write_OLED 0xA2, 0x01        '  Set display offset
    Write_OLED 0xE3
        
    Write_OLED 0xA6         '  Normal display
    Write_OLED 0xE3

    Write_OLED 0xAD, 0x8E          '  Set Master Configuration
    Write_OLED 0xE3

    Write_OLED 0xB0, 0x05          '  Power saving mode 
    Write_OLED 0xE3

    Write_OLED 0xB1, 0x11          '  Set pre & discharge
    Write_OLED 0xE3

    Write_OLED 0xB3, 0xf0          '  clock & frequency
    Write_OLED 0xE3

    Write_OLED 0xBB, 0x1C, 0x1C, 0x1C     '  Set pre-charge voltage of color A B C
    Write_OLED 0xE3

    Write_OLED 0xbe, 0x1f         '  Set VcomH
    Write_OLED 0xE3

    Write_OLED 0xc1, 0xaa, 0xb4, 0xc8    '  Set contrast current for A B C
    Write_OLED 0xE3
    
    Write_OLED 0xc7, 0x0f            '  Set master contrast
    Write_OLED 0xE3    

    Write_OLED 0xCA, 0x7f            '  Duty = 127
'    Write_OLED 0xCA, 132            '  Duty = 132
    Write_OLED 0xE3

    Write_OLED 0xaf            '  Display on
    Write_OLED 0xE3

    PAUSE 120

Setup:
    Write_C 0x8E            ' Clear display. We're using commands with more than four byte now
    Write_D 0            ' and we have to change the way we talk to the OLED!
    Write_D 0
    Write_D 130
    Write_D 130

    Write_OLED 0xE3            ' NOP

    PAUSE 100

    Write_C 0x92
    Write_D 0x01

    Write_OLED 0xE3
    
    PAUSE 10

    rand1 = 123
    rand2 = 0
    rand3 = 255
    rand4 = 50
    rand5 = 150
    rand6 = 250

PAUSE 120

Main:
' Main code loop here. We're just going to clear the display and draw random filled circles

    Write_OLED 0x92, 0x01    ' Reset
    Write_OLED 0xE3

    Write_C 0x8E        ' Clear
    Write_D 0
    Write_D 0
    Write_D 132
    Write_D 132

    PAUSE 100

    FOR i = 0 to 2500
 
        RANDOM rand1
        RANDOM rand2
        RANDOM rand3
        RANDOM rand4
        RANDOM rand5
        RANDOM rand6

    rand1 = rand1 // 130
    rand2 = rand2 // 130    
    rand3 = rand3 // 64

    Write_C 0x86
    Write_D rand1
    Write_D rand2
    Write_D rand3

    Write_D rand4
    Write_D rand5
    Write_D rand6
    Write_D rand4
    
    PAUSE 10

    NEXT i



  GOTO Main


' -------------------------------------------------------------------------
' Subroutine Code
' -------------------------------------------------------------------------

Write_OLED:

    cycle = 1
    params = __PARAMCNT
    tmpB1 = __PARAM1                              ' save LSB of value
    tmpB2 = __PARAM2
    tmpB3 = __PARAM3
    tmpB4 = __PARAM4

    INC params

    DO WHILE cycle < params

        IF cycle = 1 THEN            
        
            CMD = 0
            CS = 0
        
             SHIFTOUT SOUT, SCLK, MSBFIRST, tmpB1,10      ' send the bits

            CS = 1

        ElSEIF cycle = 2 THEN            
        
            CMD = 1
            CS = 0
        
            SHIFTOUT SOUT, SCLK, MSBFIRST, tmpB2,10      ' send the bits

            CS = 1

        ElSEIF cycle = 3 THEN            
        
            CMD = 1
            CS = 0 
        
            SHIFTOUT SOUT, SCLK, MSBFIRST, tmpB3,10     ' send the bits
            
            CS = 1

        ElSEIF cycle = 4 THEN            
            
            CMD = 1
            CS = 0
        
            SHIFTOUT SOUT, SCLK, MSBFIRST, tmpB4,10      ' send the bits

            CS = 1

        ENDIF        


        INC cycle
            
    LOOP

    RETURN

Write_C:

    tmpB1 = __PARAM1      

    CMD = 0
    CS = 0

    SHIFTOUT SOUT, SCLK, MSBFIRST, tmpB1,10      ' send the bits

    CS = 1
    
RETURN

Write_D:

    tmpB1 = __PARAM1      

    CMD = 1
    CS = 0

    SHIFTOUT SOUT, SCLK, MSBFIRST, tmpB1,10      ' send the bits

    CS = 1
      
RETURN


Post Edited (geekything) : 12/31/2006 5:58:16 PM GMT

Comments

  • BeanBean Posts: 8,129
    edited 2006-12-31 19:15
    I was thinking about getting that display, but only 1" x 1" I was afraid it wouldn't be very useful.
    Have to tried displaying text on it ? If so, is it readable ?
    How much current does the display need ?
    Some pics would be great.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com
    Stuff I'm selling on ebay http://search.ebay.com/_W0QQsassZhittconsultingQQhtZ-1

    "USA Today has come out with a new survey - apparently, three out of every four people make up 75% of the population." - David Letterman
  • geekythinggeekything Posts: 53
    edited 2006-12-31 19:31
    Hi Bean,

    It's a bit-mapped display: there's no onboard text routines. Although there's hardware assisted graphics routines.

    That said, someone over on the Sparkfun BB built a 5*7 font for the thing...haven't ported that yet.

    The SX is not my final target application (Gumstix is; the SX was just an easy-to-use platform for getting the thing working properly.

    -marc

    P.S: I'll try and post some pics -- photos really don't do the display justice, however!

    P.P.S: You asked about current...I haven't measured yet, but I can tell you it's pretty low from what I've been told.
  • geekythinggeekything Posts: 53
    edited 2006-12-31 19:44
    According to my multimeter, about 130mA for the SX28 @ 4Mhz plus the OLED. Supply is 3.3vdc.

    -marc
Sign In or Register to comment.