Help with I2C interface to 2066 OLED controller using 20X2

RSanger

New Member
Can't get Newhaven NHD-216CW-AY3 OLED display up and running using I2C. Finally got it with SPI so I know my initialization sequence is OK. I think the problem is getting the right I2COUT command format! I've tried several, including hi2cout $00,(Out_Byte1) and hi2cout [$7A],$00,(Out_Byte1) and what is shown below, but nothing seems to work!
what next
I'm using a 20X2
the manual for the 2066 controller (inside this OLED module) is http://www.newhavendisplay.com/app_notes/US2066.pdf page 10 addresses I2C. The "c0" bit is a little confusing, but I think it is used if multiple bytes of data/commands are being sent and tells the controller that the flow is going to change from data to commands or visa versa. but anyway, I am not sending data strings, and decided on my control bytes (which hold c0) as
"$00" for commnads and $40 for data - these come from an example I found here: http://www.newhavendisplay.com/NHD_forum/index.php/topic,914.msg1904.html#msg1904

here's the i2c part of my code:
setfreq M8
hi2csetup i2cmaster, $7A, i2cslow_8, i2cbyte

Send_Command:
hi2cout ($00,Out_byte1) '
pause 20
return

Send_Data:
hi2cout $40,(Out_Byte1) '
pause 20
return

THANKS for any help!!!
 

AllyCat

Senior Member
Hi,

Have you tried Slave Address $78 (or tested to confirm it definitely is $7A), since it appears to be configurable?

Cheers, Alan.
 

RSanger

New Member
Just tested, no joy. I've got A0 tied high. What is the difference in I2C output between these commands?
hi2cout $00,(Out_Byte1)
hi2cout [$7A],$00,(Out_Byte1)
hi2cout ($00,Out_Byte1)
?
 

AllyCat

Senior Member
Hi,

I'm not a PICaxe Basic syntax expert so I left it to others. But perhaps they think you should RTFM (or see Manual 2). ;)

Have you managed to communicate anything with the I2C chip?

Cheers, Alan.
 

RSanger

New Member
thanks alan. I've poured over this, and actually analyzed the logic diagrams in the manual. docs pretty skimpy, but I've submitted quesiton to tech staff addressing asking this question:
Given I'm using an 20X2 device, and issued a hi2csetup using address $7A, is there any difference in output from the commands below ... I'll let you know their answer. Also, since my SPI interface is also non-functional... I'm suspicious that I shorted out my display.... so I'm ordering a new one and will try this again once confirming functionality with SPI.
Also not clear if the picaxe cares about the ACK signal from i2c device...
hi2cout $00,(Out_Byte1)
hi2cout [$7A],$00,(Out_Byte1)
hi2cout ($00,Out_Byte1)
 

hippy

Ex-Staff (retired)
Just tested, no joy. I've got A0 tied high. What is the difference in I2C output between these commands?
hi2cout $00,(Out_Byte1)
hi2cout [$7A],$00,(Out_Byte1)
hi2cout ($00,Out_Byte1)
?
As far as I am aware there should be none.
 

RSanger

New Member
the equivalency of the statements below has been confirmed by the technical staff via private email.
hi2cout $00,(Out_Byte1)
hi2cout [$7A],$00,(Out_Byte1)
hi2cout ($00,Out_Byte1)

Also, I was able to get my display working.... after buying a new one (guess I blew up the first one!!). I used the initialization sequence recommended in the 2066 tech sheet, and the following to send "commands" and "data." the function of the "co" bit is a little unclear, but I THINK it is used when sending more than 1 byte of data and it tells the 2066 if there is a change from data to command or command to data.

hi2csetup i2cmaster, %01111010, i2cslow_8, i2cbyte ' address $7A with A0 high 'i2cfast_8 crashes the chip

Send_Command:
hi2cout ($00,Out_byte1) '
return

Send_Data:
hi2cout ($40,Out_Byte1)'
return

the hardware setup is as follows
Hardware setup

I²C Interface: Pin No. Symbol External Connection Function Description
1 VSS 0 V Ground
2 VDD 5V Supply Voltage for OLED and Logic VDD=2.8V for 2.8V operation, VDD=5V for 5V operation
3 REGVDD 5V Internal 5V I/O Regulator select signal REGVDD=0V for 2.8V operation, REGVDD=5V for 5V operation
4 SA0 5V Slave Address select signal. makes part address $7A
5-6 NC 0 v No Connect. Tie to Ground
7 SCL MPU (yel) and 10k pullup Serial Clock signal
8 SDAIN Pin 13 of axe And 10k pullup Serial Data Input.
9 SDAOUT Pin 13 of axe (blue) Serial Data Output. Tie together with SDAIN (pin 8)
10-15 NC 0v Tie to Ground
16 /RES 5v Active LOW Reset signal
17 BS0 0v For i2c
18 BS1 5v For i2c
19 BS2 0v For i2c
20 VSS 0 v Ground
 
Last edited:

RSanger

New Member
here's some code that I've labeled "works" but haven't tested since I wrote it a year ago.

Code:
#no_data

    setfreq M8

    Symbol TempByte1 = B1
    Symbol TempByte2 = B2
    Symbol Out_Byte1= B3
    Symbol Out_Byte2 = b4
    symbol n = b4


    pause 100 ' 1 ms in example  

    hi2csetup i2cmaster, %01111010, i2cslow_8, i2cbyte  ' address  7a with A0 high
    
Init_OLED:

'  initialization based on datasheet, 



    Out_Byte1 = $2A        ' set RE to 1 (use extended commands)
    gosub Send_Command
    Out_Byte1 = $71        '  enable internal 5V regulator
    gosub Send_Command
    Out_Byte1 = $5C        '  changed from 00 to 5C 
    gosub Send_Data
    
    Out_Byte1 = $28        ' RE off to exit extended commands
    gosub Send_Command
    Out_Byte1 = $08         ' display OFF, cursor off, blink off
    gosub Send_Command
    
    
    Out_Byte1 = $2A        'set RE to 1 (use extended commands)
    gosub Send_Command
    Out_Byte1 = $79        ' go to OLED command set (SD=1)
    gosub Send_Command
    

    Out_Byte1 = $D5        ' set clock divide ratio (these are default values)
    gosub Send_Command
    Out_Byte1 = $70        ' divide ratio 1, freq 7
    gosub Send_Command
    Out_Byte1 = $78        ' exit from OLED command set
    gosub Send_Command
    Out_Byte1 = $08        ' Extended function set (RE=1): 5-dot font, B/W inverting disabled (def. val.), 2 line
    gosub Send_Command
    Out_Byte1 = $06        ' com seg direction (orientation of letters)
    gosub Send_Command
    Out_Byte1 = $72        ' function select B
    gosub Send_Data
    Out_Byte1 = $00        ' CGRam selection
    gosub Send_Data
    
'    Out_Byte1 = $2A        ' not sure why this included, web example has it left out
'    gosub Send_Command
    Out_Byte1 = $79        ' go to OLED command set (SD=1)
    gosub Send_Command
    Out_Byte1 = $DA        ' Set SEG pins hardware configuration:
    gosub Send_Command
    Out_Byte1 = $10        ' alternative odd/even SEG pin, disable SEG left/right remap (default values)
    gosub Send_Command
    Out_Byte1 = $DC        'Function selection C
    gosub Send_Command
    Out_Byte1 = $00        '  internal VSL, GPIO input disable
    gosub Send_Command
    
    Out_Byte1 = $81        'Set contrast control:
    gosub Send_Command
    Out_Byte1 = $7F        'contrast=127 (default value)
    gosub Send_Command
    Out_Byte1 = $D9        'Set phase length:
    gosub Send_Command
    Out_Byte1 = $F1        'phase2=15, phase1=1 (default: 0x78)
    gosub Send_Command
    Out_Byte1 = $DB        ' Set VCOMH deselect level:
    gosub Send_Command
    Out_Byte1 = $40        'VCOMH deselect level=1 x Vcc (default: 0x20=0,77 x Vcc)
    gosub Send_Command
    
    Out_Byte1 = $78        'OLED command set disabled (SD=0) (exit from OLED command set)
    gosub Send_Command
    Out_Byte1 = $28        '(RE=0) (exit from extended command set), lines #
    gosub Send_Command
    Out_Byte1 = $01        'Clear display
    gosub Send_Command
    
    pause 5             '  After a clear display, a minimum pause of 1-2 ms is required as per web example
    
    Out_Byte1 = $80        '  Set DDRAM address 0x00 in address counter (cursor home) (default value)
    gosub Send_Command
    Out_Byte1 = $0F        ' changed:  from 08 to 0F to produce blinking cursor, Display ON
    gosub Send_Command


pause 250


Main:
    
    gosub Display_Something
    

goto main



Display_Something:
        Out_Byte1 = $01  ' clear display, reset pointers
        gosub Send_Command
        Out_Byte1 = $02
        gosub Send_Command
        pause 30
        for n = 15 to 90
            Out_Byte1 = n' display something
            gosub Send_Data
            
        next n
                
        pause 1000

return




' for I2C interface   =======================================
Send_Command:
'    hi2csetup i2cmaster, $7A, i2cslow, i2cbyte  ' address
'    hi2cout ($80,Out_Byte1) ' control byte, databyte   c0=0
'    hi2cout ($C0,Out_Byte1)
'    hi2cout $C0,(Out_Byte1)  ' use this if next byte is data (for command)
'    hi2cout $80,(Out_Byte1)  ' use this if next byte is command
'    hi2cout $00,(Out_Byte1)  ' single command follows
    hi2cout ($00,Out_byte1)  ' **** web example uses $00
'    hi2cout [$7a],($00,Out_Byte1)
'    writei2c ($00,Out_byte1) 

return



Send_Data:
'    hi2csetup i2cmaster, $7A, i2cslow, i2cbyte  ' address
'    hi2cout ($00,Out_Byte1) ' control byte, databyte  ??????????? what should c0 be?
'    hi2cout $40,(Out_Byte1)  ' single data follows
    hi2cout ($40,Out_Byte1)' ***web example uses $40
'    hi2cout $40,(Out_Byte1)   
'    hi2cout [$7a],($40,Out_byte1)
'    writei2c ($40,Out_Byte1)
    
return

'
 
Last edited by a moderator:
Top