Andrei IRL
Senior Member
Hello.
I am trying to learn on how to use OLED SSD1306 Screen 128x32 pixels.
I have loaded the code into PICAXE Editor but upon Checking of the code i get an error (see attachment)
Any idea what i might be doing wrong?
I am using chip and not 40M
The code i am trying to use was taken from this thread here
I am trying to learn on how to use OLED SSD1306 Screen 128x32 pixels.
I have loaded the code into PICAXE Editor but upon Checking of the code i get an error (see attachment)
Any idea what i might be doing wrong?
I am using chip and not 40M
The code i am trying to use was taken from this thread here
Code:
#picaxe 08m2
setfreq m8
'Constants
Symbol I2CSpeed = i2cfast_8
'I/O pins, C.3&C.4 reserved for I2C
Symbol UpBtnPin = pinB.0
Symbol DnBtnPin = pinB.1
Symbol SelBtnPin = pinB.2
'I2C addresses
Symbol Memory = %10100000
Symbol Display = $3C << 1 '[$78]
'Display command constants
Symbol TWI_BUFFER_LENGTH = 32
Symbol LCDWIDTH = 128
Symbol LCDHEIGHT = 64
Symbol SETCONTRAST =0x81
Symbol DISPLAYALLON_RESUME =0xA4
Symbol DISPLAYALLON =0xA5
Symbol NORMALDISPLAY =0xA6
Symbol INVERTDISPLAY =0xA7
Symbol DISPLAYOFF =0xAE
Symbol DISPLAYON =0xAF
Symbol SETDISPLAYOFFSET =0xD3
Symbol SETCOMPINS =0xDA
Symbol SETVCOMDETECT =0xDB
Symbol SETDISPLAYCLOCKDIV =0xD5
Symbol SETPRECHARGE =0xD9
Symbol SETMULTIPLEX =0xA8
Symbol SETLOWCOLUMN =0x00
Symbol SETHIGHCOLUMN =0x10
Symbol SETSTARTLINE =0x40
Symbol MEMORYMODE =0x20
Symbol COLUMNADDR =0x21
Symbol PAGEADDR =0x22
Symbol COMSCANINC =0xC0
Symbol COMSCANDEC =0xC8
Symbol SEGREMAP =0xA0 | 1
Symbol CHARGEPUMP =0x8D
Symbol EXTERNALVCC =0x1
Symbol SWITCHCAPVCC =0x2
'Display scrolling commands
Symbol ACTIVATE_SCROLL =0x2F
Symbol DEACTIVATE_SCROLL =0x2E
Symbol SET_VERTICAL_SCROLL_AREA =0xA3
Symbol HORIZONTAL_SCROLL_RIGHT =0x26
Symbol HORIZONTAL_SCROLL_LEFT =0x27
Symbol VERT_AND_RIGHT_HORIZONTAL =0x29
Symbol VERT_AND_LEFT_HORIZONTAL =0x2A
'Byte variables
Symbol row = b6
Symbol col = b7
init:
b0 = 0
b1 = 0
b2 = 0
pause 500
hi2csetup i2cmaster, Display, I2CSpeed, I2cbyte
hi2cout (0, DISPLAYOFF)
hi2cout (0, SETDISPLAYCLOCKDIV)
hi2cout (0, 0x80)
hi2cout (0, SETMULTIPLEX)
hi2cout (0, 0x3F)
hi2cout (0, SETDISPLAYOFFSET)
hi2cout (0, 0x0)
hi2cout (0, SETSTARTLINE)
hi2cout (0, CHARGEPUMP)
hi2cout (0, 0x14)
hi2cout (0, MEMORYMODE)
hi2cout (0, 0x00)
hi2cout (0, SEGREMAP)
hi2cout (0, COMSCANDEC)
hi2cout (0, SETCOMPINS)
hi2cout (0, 0x12)
hi2cout (0, SETCONTRAST)
hi2cout (0, 0xCF)
hi2cout (0, SETPRECHARGE)
hi2cout (0, 0xF1)
hi2cout (0, SETVCOMDETECT)
hi2cout (0, 0x40)
hi2cout (0, DISPLAYALLON_RESUME)
hi2cout (0, DISPLAYON)
pause 500
main:
'say something. anything.
gosub ClearDisplay
row = 4
col = 30
gosub SetPosition
hi2cout (0x40, 0x7F, 0x08, 0x08, 0x08, 0x7F, 0x00) 'H with extra pixel added for char spacing (8x6 font here)
hi2cout (0x40, 0x7F, 0x49, 0x49, 0x49, 0x41, 0x00) 'E
hi2cout (0x40, 0x7F, 0x40, 0x40, 0x40, 0x40, 0x00) 'L
hi2cout (0x40, 0x7F, 0x40, 0x40, 0x40, 0x40, 0x00) 'L
hi2cout (0x40, 0x3E, 0x41, 0x41, 0x41, 0x3E, 0x00) 'O
hi2cout (0x40, 0x00, 0x00, 0x00, 0x00, 0x00) 'space
hi2cout (0x40, 0x3F, 0x40, 0x38, 0x40, 0x3F, 0x00) 'W
hi2cout (0x40, 0x3E, 0x41, 0x41, 0x41, 0x3E, 0x00) 'O
hi2cout (0x40, 0x7F, 0x09, 0x19, 0x29, 0x46, 0x00) 'R
hi2cout (0x40, 0x7F, 0x40, 0x40, 0x40, 0x40, 0x00) 'L
hi2cout (0x40, 0x7F, 0x41, 0x41, 0x41, 0x3E, 0x00) 'D
hi2cout (0x40, 0x00, 0x5F, 0x00, 0x00, 0x00) '! with the first col removed, looks better
pause 10000
goto main
SetPosition:
hi2cout (0, PAGEADDR)
hi2cout (0, row)
hi2cout (0, 7)
hi2cout (0, COLUMNADDR)
; col = col * 5 'columns per character - !!! NB not sure what this does or does not !!!
hi2cout (0, col)
hi2cout (0, 127)
return
ClearDisplay:
for b2 = 0 to LCDWIDTH
hi2cout (0x40,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
next b2
hi2cout (0, COLUMNADDR)
hi2cout (0, 0)
hi2cout (0, 127)
hi2cout (0, PAGEADDR)
hi2cout (0, 0)
hi2cout (0, 7)
return
' STANDARD FONT
'table (0x00, 0x00, 0x00, 0x00, 0x00) ' Space
'table (0x00, 0x00, 0x5F, 0x00, 0x00) ' !
'table (0x00, 0x07, 0x00, 0x07, 0x00) ' "
'table (0x14, 0x7F, 0x14, 0x7F, 0x14) ' #
'table (0x24, 0x2A, 0x7F, 0x2A, 0x12) ' $
'table (0x23, 0x13, 0x08, 0x64, 0x62) ' %
'table (0x36, 0x49, 0x56, 0x20, 0x50) ' &
'table (0x00, 0x08, 0x07, 0x03, 0x00) ' '
table (0x00, 0x1C, 0x22, 0x41, 0x00) ' (
table (0x00, 0x41, 0x22, 0x1C, 0x00) ' )
table (0x2A, 0x1C, 0x7F, 0x1C, 0x2A) ' *
table (0x08, 0x08, 0x3E, 0x08, 0x08) ' +
table (0x00, 0x80, 0x70, 0x30, 0x00) ' ,
table (0x08, 0x08, 0x08, 0x08, 0x08) ' -
table (0x00, 0x00, 0x5F, 0x00, 0x0) ' .
table (0x20, 0x10, 0x08, 0x04, 0x02) ' /
table (0x3E, 0x51, 0x49, 0x45, 0x3E) ;9 : pos40
table (0x00, 0x42, 0x7F, 0x40, 0x00) ; 1
table (0x72, 0x49, 0x49, 0x49, 0x46)
table (0x21, 0x41, 0x49, 0x4D, 0x33)
table (0x18, 0x14, 0x12, 0x7F, 0x10)
table (0x27, 0x45, 0x45, 0x45, 0x39)
table (0x3C, 0x4A, 0x49, 0x49, 0x31)
table (0x41, 0x21, 0x11, 0x09, 0x07)
table (0x36, 0x49, 0x49, 0x49, 0x36)
table (0x46, 0x49, 0x49, 0x29, 0x1E)
table (0x00, 0x00, 0x14, 0x00, 0x00)
table (0x00, 0x40, 0x34, 0x00, 0x00)
table (0x00, 0x08, 0x14, 0x22, 0x41)
table (0x14, 0x14, 0x14, 0x14, 0x14)
table (0x00, 0x41, 0x22, 0x14, 0x08)
table (0x02, 0x01, 0x59, 0x09, 0x06)
table (0x3E, 0x41, 0x5D, 0x59, 0x4E)
table (0x7C, 0x12, 0x11, 0x12, 0x7C) ;A most likely and extra blank pixel would need to be added
table (0x7F, 0x49, 0x49, 0x49, 0x36) ;B
table (0x3E, 0x41, 0x41, 0x41, 0x22) ;C
table (0x7F, 0x41, 0x41, 0x41, 0x3E) ;D
table (0x7F, 0x49, 0x49, 0x49, 0x41) ;E
table (0x7F, 0x09, 0x09, 0x09, 0x01) ;F
table (0x3E, 0x41, 0x41, 0x51, 0x73) ;G
table (0x7F, 0x08, 0x08, 0x08, 0x7F) ;H
table (0x00, 0x41, 0x7F, 0x41, 0x00) ;I
table (0x20, 0x40, 0x41, 0x3F, 0x01) ;J
table (0x7F, 0x08, 0x14, 0x22, 0x41) ;K
table (0x7F, 0x40, 0x40, 0x40, 0x40) ;L
table (0x7F, 0x02, 0x1C, 0x02, 0x7F) ;M
table (0x7F, 0x04, 0x08, 0x10, 0x7F) ;N
table (0x3E, 0x41, 0x41, 0x41, 0x3E) ;O
table (0x7F, 0x09, 0x09, 0x09, 0x06) ;P
table (0x3E, 0x41, 0x51, 0x21, 0x5E) ;Q
table (0x7F, 0x09, 0x19, 0x29, 0x46) ;R
table (0x26, 0x49, 0x49, 0x49, 0x32) ;S
table (0x03, 0x01, 0x7F, 0x01, 0x03) ;T
table (0x3F, 0x40, 0x40, 0x40, 0x3F) ;U
table (0x1F, 0x20, 0x40, 0x20, 0x1F) ;V
table (0x3F, 0x40, 0x38, 0x40, 0x3F) ;W
table (0x63, 0x14, 0x08, 0x14, 0x63) ;X
table (0x03, 0x04, 0x78, 0x04, 0x03) ;Y
table (0x61, 0x59, 0x49, 0x4D, 0x43) ;Z