Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

2.42inch 128x64dot OLED display (SSD1309) library.
Goto page 1, 2  Next
 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Share your working BASCOM-AVR code here
View previous topic :: View next topic  
Author Message
O-Family

Bascom Expert



Joined: 23 May 2010
Posts: 338
Location: Japan

japan.gif
PostPosted: Sat Jul 02, 2022 3:03 am    Post subject: 2.42inch 128x64dot OLED display (SSD1309) library. Reply with quote

I have created a library for SPI and I2C for SSD1309 controller.

In the module used, the power supply voltage in SPI mode is only 3.3V.
(If the level of the SPI signal is converted, it can be used even at 5V)
Drawing speed is much faster than I2C.

In I2C mode, it can be used with a power supply of 3.3V to 5V.
The drawing speed will be slower.


The following functions have been added.

1. Added option to rotate display 180 degrees.
Const Ssd1309_rotate = 0 ' Screen rotation. (Connecting cable left side = [0], right side = [1])

2. Control byte added to the "GLCDCMD" instruction.
Normal/Inverse Display [A6:Normal , A7:Inverse]
Display ON/OFF [AE:OFF(sleep mode) , AF:ON(normal mode)]

3. Contrast can be changed.
_contrast = 0 : Glcdcmd &H81 'Change contrast of the OLED [0:dark - 255:bright]

4. Underline option added to the "LCDAT" instruction. [2:Solid , 3:dotted]

5. In I2C mode, you can select the slave address of SSD1309.
Const Ssd1309_sa0 = 0 ' Slave address of SSD1309. (0:SA0=[L] 78H , 1:SA0=[H] 7AH)


circuit diagram
https://drive.google.com/file/d/1iMEbRs7ApRQhKz6E4rEWaUtnJ7SHWXql/view?usp=sharing

Code:

$programmer = 22                                            ' ARDUINO (using stk500v1 protocol)

   '
   '  ***************************************
   '  *  2.42 inch 128x64 dot OLED display  *
   '  *       (SSD1309) Test program        *
   '  *            O-Family   2022. 6.30    *
   '  ***************************************
   '

$regfile = "m328pdef.dat"
$crystal = 16000000
   '
$hwstack = 64
$swstack = 10
$framesize = 24

   '
   '  * OLED controller [SSD1309] settings *
   '
   Const Interface_selection = 1                            ' Interface selection. (0:SPI , 1:I2C,TWI)

'--------------------------------------------------------------------------------------------------
#if Interface_selection = 0
   '
   '  * When connecting with [SPI] *
   '
   Dim _contrast As Byte                                    ' OLED contrast setting value. [0-255]
   Const Ssd1309_rotate = 0                                 ' Screen rotation. (Connecting cable left side = [0], right side = [1])
   $lib "glcdSSD1309-SPI_V2.lib"                            ' Incorporate a library of SSD1309-SPI with additional functionality.
   '  Set the connection port for OLED. Cs1 = [CS], A0 = [DC], Rst = [RES], Si = [SDA], Sclk = [SCLK]
   Config Graphlcd = 128 * 64eadogm , Cs1 = Portc.1 , A0 = Portc.2 , Rst = Portc.3 , Si = Portc.4 , Sclk = Portc.5

#else
   '
   '  * When connecting with [I2C, TWI] *
   '
   Const I2c_select = 1                                     ' I2C interface selection. (0:Software I2C , 1:Hardware TWI)
   '
   #if I2c_select = 0                                       ' For software I2C.
      Config Scl = Portc.5                                  ' Set the port pin to connect the SCL line of the I2C bus. (Any port)
      Config Sda = Portc.4                                  ' Set the port pin to connect the SDA line of the I2C bus. (Any port)
      Config I2cdelay = 1                                   ' Set the SCL clock speed for software I2C.
      I2cinit                                               ' Initialize the I2C bus.
   #else                                                    ' For hardware TWI.
      $lib "i2c_TWI.LBX"                                    ' Incorporate the hardware TWI library.
      Config Scl = Portc.5                                  ' Set the port pin to connect the SCL line of the I2C bus.
      Config Sda = Portc.4                                  ' Set the port pin to connect the SDA line of the I2C bus.
      Config Twi = 400000                                   ' TWI clock speed. (400KHz)
      I2cinit                                               ' Initialize the I2C bus.
   #endif
   '
   Dim _contrast As Byte                                    ' OLED contrast setting value. [0-255]
   Reset Portc.3                                            ' Set the [RES] pin of the OLED (SSD1309) to [L]. (Any port)
   Config Portc.3 = Output                                  ' Set the connection port of the [RES] pin of the OLED (SSD1309) to the output.
   Waitms 1                                                 ' The [L] period of the OLED reset pulse.
   Config Portc.3 = Input                                   ' Set the connection port of the [RES] pin of the OLED (SSD1309) to the input. (Open drain)
   Waitms 10                                                ' OLED boot wait time.
   '
   Const Ssd1309_sa0 = 0                                    ' Slave address of SSD1309. (0:SA0=[L] 78H , 1:SA0=[H] 7AH)
   Const Ssd1309_rotate = 0                                 ' Screen rotation. (Connecting cable left side = [0] , right side = [1])
   $lib "glcdSSD1309-I2C_V2.lib"                            ' Incorporate a library of SSD1309-I2C with additional functionality.
   Config Graphlcd = Custom , Cols = 128 , Rows = 64 , Lcdname = "SSD1309"       'OLED settings.

#endif
   Cls                                                      ' Erase all OLED display.
'--------------------------------------------------------------------------------------------------

   '
   '  * OLED display test program *
   '
   Do
      Setfont Font8x8tt                                     ' Select font.
      Lcdat 1 , 1 , "SSD1309 2.42{034} OLED"
      Lcdat 2 , 8 , "128x64dots SPI,I2C"
      Lcdat 6 , 1 , " ABCDefg012345678 " , 2                ' Optional solid underline.
      Lcdat 8 , 1 , " ABCDefg012345678 " , 3                ' Optional dotted underline.
      Setfont Font8x8                                       ' Select font.
      Lcdat 4 , 1 , "[BASCOM-AVR MCS]" , 1                  ' Optional invert.
      Wait 3

      Glcdcmd &HA7                                          ' Normal/Inverse Display. [A7:Inverse]
      Wait 3
      Glcdcmd &HA6                                          ' Normal/Inverse Display. [A6:Normal]
      Wait 3

      _contrast = 0 : Glcdcmd &H81                          ' Change contrast of the OLED. [0:dark - 255:bright]
      Wait 3
      _contrast = 255 : Glcdcmd &H81                        ' Change contrast of the OLED. [0:dark - 255:bright]
      Wait 3

      Glcdcmd &HAE                                          ' Display ON/OFF [AE:OFF(sleep mode) , AF:ON(normal mode)]
      Wait 3
      Glcdcmd &HAF                                          ' Display ON/OFF [AE:OFF(sleep mode) , AF:ON(normal mode)]
      Wait 3

      Showpic 0 , 0 , Plaatje                               ' Draw a BGF file. (BMP compressed image).
      Wait 3
      Cls
   Loop

   End

   '
   '  * Font data *
   '
$include "font8x8TT.font"                                   ' This is a true type font with variable spacing.
$include "font8x8.font"
   '
   '  * BGF file data *
   '
Plaatje:
   $bgf "ks108.bgf"                                         ' Include the picture data.


Last edited by O-Family on Sat Jul 09, 2022 9:57 am; edited 5 times in total
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 6198
Location: Holland

blank.gif
PostPosted: Sat Jul 02, 2022 8:58 pm    Post subject: Reply with quote

Hello O-Family,

Excellent, you saved me a lot of work Very Happy since i needed this and did not had time yet. My display is slightly different but has the same graphic chip.
Thank you for sharing this.
As usual it is very good documented. Well done!
I will use it with DB series.

_________________
Mark
Back to top
View user's profile Visit poster's website
O-Family

Bascom Expert



Joined: 23 May 2010
Posts: 338
Location: Japan

japan.gif
PostPosted: Sun Jul 03, 2022 8:58 am    Post subject: Reply with quote

Next is an example of connecting multiple SSD1309 OLEDs in SPI mode.

By adjusting the pull-up resistors connected to RES, SDA, and SCLK in the module, theoretically any number can be connected.

circuit diagram
https://drive.google.com/file/d/1bAFIv0Stu9nIzHoMp_dj7jqPrzW3O64O/view?usp=sharing

Code:

$programmer = 22                                            ' ARDUINO (using stk500v1 protocol)

   '
   '  *****************************************
   '  *  2.42 inch 128x64 dot OLED (SSD1309)  *
   '  *   Connect multiple units with [SPI]   *
   '  *            O-Family   2022. 7. 3      *
   '  *****************************************
   '

$regfile = "m328pdef.dat"
$crystal = 16000000
   '
$hwstack = 64
$swstack = 10
$framesize = 24

   '
   '  OLED controller [SSD1309] settings (Connect multiple units with [SPI]) *
   '
   Dim _contrast As Byte                                    ' OLED contrast setting value. [0-255]
   Const Ssd1309_rotate = 0                                 ' Screen rotation. (Connecting cable left side = [0], right side = [1])
   $lib "glcdSSD1309-SPI_V2.lib"                            ' Incorporate a library of SSD1309-SPI with additional functionality.
   '
   Ssd1309_cs1 Alias Portc.0                                ' Set the port to connect the [CS] pin of the first OLED (SSD1309).
   Config Ssd1309_cs1 = Output                              ' Set the connection port of the first [CS] pin to output.
   Reset Ssd1309_cs1                                        ' Set the first [CS] pin to [L].
   Ssd1309_cs2 Alias Portc.1                                ' Set the port to connect the [CS] pin of the second OLED (SSD1309).
   Config Ssd1309_cs2 = Output                              ' Set the connection port of the second [CS] pin to output.
   Reset Ssd1309_cs2                                        ' Set the second [CS] pin to [L].
   '
   '  Set the connection port for OLED. A0 = [DC], Rst = [RES], Si = [SDA], Sclk = [SCLK]
   Config Graphlcd = 128 * 64eadogm , A0 = Portc.2 , Rst = Portc.3 , Si = Portc.4 , Sclk = Portc.5
   Cls                                                      ' Erase all OLED display.
   Set Ssd1309_cs1                                          ' Set the first [CS] pin to [H].
   Set Ssd1309_cs2                                          ' Set the second [CS] pin to [H].

'--------------------------------------------------------------------------------------------------

   '
   '  * OLED display test program *
   '

   Setfont Font8x8tt                                        ' Select font.
   '
   '  * Display of the first unit *
   '
   Reset Ssd1309_cs1                                        ' Set the first [CS] pin to [L].
   Lcdat 1 , 1 , "SSD1309 2.42{034} OLED"
   Lcdat 2 , 8 , "128x64dots SPI,I2C"
   Lcdat 4 , 2 , "Multiple Connections" , 1                 ' Optional invert.
   Lcdat 6 , 9 , " < SPI Unit 1 > " , 2                     ' Optional solid underline.
   Lcdat 8 , 1 , " 1 1 1 1 1 1 1 1 1 " , 3                  ' Optional dotted underline.
   Set Ssd1309_cs1                                          ' Set the first [CS] pin to [H].

   '
   '  * Display of the second unit *
   '
   Reset Ssd1309_cs2                                        ' Set the second [CS] pin to [L].
   Lcdat 1 , 1 , "SSD1309 2.42{034} OLED"
   Lcdat 2 , 8 , "128x64dots SPI,I2C"
   Lcdat 4 , 2 , "Multiple Connections" , 1                 ' Optional invert.
   Lcdat 6 , 9 , " < SPI Unit 2 > " , 2                     ' Optional solid underline.
   Lcdat 8 , 1 , " 2 2 2 2 2 2 2 2 " , 3                    ' Optional dotted underline.
   Set Ssd1309_cs2                                          ' Set the second [CS] pin to [H].

   End

   '
   '  * Font data *
   '
$include "font8x8TT.font"                                   ' This is a true type font with variable spacing.
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 6198
Location: Holland

blank.gif
PostPosted: Sun Jul 03, 2022 8:41 pm    Post subject: Reply with quote

wow, that is super ! thanks for this very useful addition.
Well done!

_________________
Mark
Back to top
View user's profile Visit poster's website
O-Family

Bascom Expert



Joined: 23 May 2010
Posts: 338
Location: Japan

japan.gif
PostPosted: Mon Jul 04, 2022 2:38 am    Post subject: Reply with quote

Finally, there is an example of connecting two SSD1309 OLEDs in I2C mode.

Please note that the library will change.

circuit diagram
https://drive.google.com/file/d/17EdeeU-bO0unP9Yt2ZNF_Ht6ubYkvuQn/view?usp=sharing

Code:

$programmer = 22                                            'ARDUINO (using stk500v1 protocol)

   '
   '  *****************************************
   '  *  2.42 inch 128x64 dot OLED (SSD1309)  *
   '  *       Connect 2 units with [I2C]      *
   '  *            O-Family   2022. 7. 4      *
   '  *****************************************
   '

$regfile = "m328pdef.dat"
$crystal = 16000000
   '
$hwstack = 64
$swstack = 10
$framesize = 24

   '
   '  OLED controller [SSD1309] settings (Connect 2 units with [I2C]) *
   '
   Const I2c_select = 1                                     ' I2C interface selection. (0:Software I2C , 1:Hardware TWI)
   '
#if I2c_select = 0                                          ' For software I2C.
   Config Scl = Portc.5                                     ' Set the port pin to connect the SCL line of the I2C bus. (Any port)
   Config Sda = Portc.4                                     ' Set the port pin to connect the SDA line of the I2C bus. (Any port)
   Config I2cdelay = 1                                      ' Set the SCL clock speed for software I2C.
   I2cinit                                                  ' Initialize the I2C bus.
#else                                                       ' For hardware TWI.
   $lib "i2c_TWI.LBX"                                       ' Incorporate the hardware TWI library.
   Config Scl = Portc.5                                     ' Set the port pin to connect the SCL line of the I2C bus.
   Config Sda = Portc.4                                     ' Set the port pin to connect the SDA line of the I2C bus.
   Config Twi = 400000                                      ' TWI clock speed. (400KHz)
   I2cinit                                                  ' Initialize the I2C bus.
#endif
   '
   Dim _contrast As Byte                                    ' OLED contrast setting value. [0-255]
   Dim I2c_addr As Byte                                     ' I2C slave address selection. [&H78 or &H7A]
   Reset Portc.3                                            ' Set the [RES] pin of the OLED (SSD1309) to [L]. (Any port)
   Config Portc.3 = Output                                  ' Set the connection port of the [RES] pin of the OLED (SSD1309) to the output.
   Waitms 1                                                 ' The [L] period of the OLED reset pulse.
   Config Portc.3 = Input                                   ' Set the connection port of the [RES] pin of the OLED (SSD1309) to the input. (Open drain)
   Waitms 10                                                ' OLED boot wait time.
   '
   Const Ssd1309_rotate = 0                                 ' Screen rotation. (Connecting cable left side = [0] , right side = [1])
   $lib "glcdSSD1309-I2C_V2x2.lib"                          ' Incorporate a function-added version library for two SSD1309-I2C units.
   Config Graphlcd = Custom , Cols = 128 , Rows = 64 , Lcdname = "SSD1309"       'OLED settings.
   '
   I2c_addr = &H78                                          ' Select the first OLED.
   Cls                                                      ' Erase all OLED display.
   I2c_addr = &H7A                                          ' Select the second OLED.
   Cls                                                      ' Erase all OLED display.

'--------------------------------------------------------------------------------------------------

   '
   '  * OLED display test program *
   '

   Setfont Font8x8tt                                        ' Select font.
   '
   '  * Display of the first unit *
   '
   I2c_addr = &H78                                          ' Select the first OLED.
   Lcdat 1 , 1 , "SSD1309 2.42{034} OLED"
   Lcdat 2 , 8 , "128x64dots SPI,I2C"
   Lcdat 4 , 2 , "Multiple Connections" , 1                 ' Optional invert.
   Lcdat 6 , 9 , " < I2C Unit 1 > " , 2                     ' Optional solid underline.
   Lcdat 8 , 1 , "  Address = [78]  " , 3                   ' Optional dotted underline.

   '
   '  * Display of the second unit *
   '
   I2c_addr = &H7A                                          ' Select the second OLED.
   Lcdat 1 , 1 , "SSD1309 2.42{034} OLED"
   Lcdat 2 , 8 , "128x64dots SPI,I2C"
   Lcdat 4 , 2 , "Multiple Connections" , 1                 ' Optional invert.
   Lcdat 6 , 9 , " < I2C Unit 2 > " , 2                     ' Optional solid underline.
   Lcdat 8 , 1 , "  Address = [7A]  " , 3                   ' Optional dotted underline.

   End

   '
   '  * Font data *
   '
$include "font8x8TT.font"                                   ' This is a true type font with variable spacing.
 


Last edited by O-Family on Sat Jul 09, 2022 2:10 am; edited 2 times in total
Back to top
View user's profile Visit poster's website
O-Family

Bascom Expert



Joined: 23 May 2010
Posts: 338
Location: Japan

japan.gif
PostPosted: Wed Jul 06, 2022 7:19 am    Post subject: Reply with quote

The new I2C routines for XMega have changed to use R23, so this library has also been modified.
When using XMega, reload [Revision 002] of the I2C library.

Code:

$programmer = 16                                            'USBprog Programmer/ AVR ISP mkII (Atmel)

   '
   '  *****************************************
   '  *  2.42 inch 128x64 dot OLED display    *
   '  *   (SSD1309) Test program  (For XMEGA) *
   '  *            O-Family   2022. 7. 6      *
   '  *****************************************
   '

$regfile = "xm128a1def.dat"
$crystal = 32000000
   '
$hwstack = 64
$swstack = 40
$framesize = 40

   Config Osc = Enabled , 32mhzosc = Enabled
   Config Sysclock = 32mhz , Prescalea = 1 , Prescalebc = 1_1

   '
   '  OLED controller [SSD1309] settings *
   '
   Const Interface_selection = 1                            ' Interface selection. (0:SPI , 1:I2C,TWI)

'--------------------------------------------------------------------------------------------------
#if Interface_selection = 0
   '
   '  * When connecting with [SPI] (For XMEGA) *
   '
   Dim _contrast As Byte                                    ' OLED contrast setting value. [0-255]
   Const Ssd1309_rotate = 0                                 ' Screen rotation. (Connecting cable left side = [0], right side = [1])
   $lib "glcdSSD1309-SPI_V2.lib"                            ' Incorporate a library of SSD1309-SPI with additional functionality.
   Config Vport0 = C                                        ' Set the virtual port.
   '  Set the connection port for OLED. Cs1 = [CS], A0 = [DC], Rst = [RES], Si = [SDA], Sclk = [SCLK]
   Config Graphlcd = 128 * 64eadogm , Cs1 = Port0.7 , A0 = Port0.6 , Rst = Port0.5 , Si = Port0.4 , Sclk = Port0.3

#else
   '
   '  * When connecting with [I2C, TWI] (For XMEGA) *
   '
   Const I2c_select = 1                                     ' I2C interface selection. (0:Software I2C , 1:Hardware TWI)
   '
   #if I2c_select = 0                                       ' For software I2C.
      Const Twi_adr = 0 : Const Twi_ch = 0                  ' [Dummy in library]
      $forcesofti2c                                         ' Force use of software I2C/TWI library.
      $lib "i2c.lbx"                                        ' Overwrite the library for software I2C.
      Config I2cdelay = 1                                   ' SCL clock frequency = approx 280KHz. (At AVR clock 20MHz) (* Maximum 400KHz)
      Config Scl = Portc.6                                  ' Set the port pin to connect the SCL line of the I2C bus.
      Config Sda = Portc.5                                  ' Set the port pin to connect the SDA line of the I2C bus.
      I2cinit                                               ' Initialize the I2C bus.
   #else                                                    ' For hardware TWI.
      Dim Twi_start As Byte                                 ' Variables used in the TWI library.
      Const Twi_adr = Twic_ctrl                             ' TWI port. TWI_ADR = TWIC_CTRL:(TWIC), TWID_CTRL:(TWID), TWIE_CTRL:(TWIE), TWIF_CTRL:(TWIF)
      Const Twi_ch = 1                                      ' TWI channel. TWI_CH = 1:(TWIC), 2:(TWID), 4:(TWIE), 8:(TWIF)
      Config Twic = 400000                                  ' Clock frequency of the TWI port [TWIC, TWID, TWIE, TWIF]. (* Maximum 400KHz)
      I2cinit                                               ' Initialize the TWI bus.
   #endif
   '
   Dim _contrast As Byte                                    ' OLED contrast setting value. [0-255]
   Reset Portc.7                                            ' Set the [RES] pin of the OLED (SSD1309) to [L]. (Any port)
   Config Portc.7 = Output                                  ' Set the connection port of the [RES] pin of the OLED (SSD1309) to the output.
   Waitms 1                                                 ' The [L] period of the OLED reset pulse.
   Config Portc.7 = Input                                   ' Set the connection port of the [RES] pin of the OLED (SSD1309) to the input. (Open drain)
   Waitms 10                                                ' OLED boot wait time.
   '
   Const Ssd1309_sa0 = 0                                    ' Slave address of SSD1309. (0:SA0=[L] 78H , 1:SA0=[H] 7AH)
   Const Ssd1309_rotate = 0                                 ' Screen rotation. (Connecting cable left side = [0] , right side = [1])
   $lib "glcdSSD1309-I2C_V2.lib"                            ' Incorporate a library of SSD1309-I2C with additional functionality.
   Config Graphlcd = Custom , Cols = 128 , Rows = 64 , Lcdname = "SSD1309"       'OLED settings.

#endif
   Cls                                                      ' Erase all OLED display.
'--------------------------------------------------------------------------------------------------

   '
   '  * OLED display test program *
   '
   Do
      Setfont Font8x8tt                                     ' Select font.
      Lcdat 1 , 1 , "SSD1309 2.42{034} OLED"
      Lcdat 2 , 8 , "128x64dots SPI,I2C"
      Lcdat 6 , 1 , " ABCDefg012345678 " , 2                ' Optional solid underline.
      Lcdat 8 , 1 , " ABCDefg012345678 " , 3                ' Optional dotted underline.
      Setfont Font8x8                                       ' Select font.
      Lcdat 4 , 1 , "[BASCOM-AVR MCS]" , 1                  ' Optional invert.
      Wait 3

      Glcdcmd &HA7                                          ' Normal/Inverse Display. [A7:Inverse]
      Wait 3
      Glcdcmd &HA6                                          ' Normal/Inverse Display. [A6:Normal]
      Wait 3

      _contrast = 0 : Glcdcmd &H81                          ' Change contrast of the OLED. [0:dark - 255:bright]
      Wait 3
      _contrast = 255 : Glcdcmd &H81                        ' Change contrast of the OLED. [0:dark - 255:bright]
      Wait 3

      Glcdcmd &HAE                                          ' Display ON/OFF [AE:OFF(sleep mode) , AF:ON(normal mode)]
      Wait 3
      Glcdcmd &HAF                                          ' Display ON/OFF [AE:OFF(sleep mode) , AF:ON(normal mode)]
      Wait 3

      Showpic 0 , 0 , Plaatje                               ' Draw a BGF file. (BMP compressed image).
      Wait 3
      Cls
   Loop

   End

   '
   '  * Font data *
   '
$include "font8x8TT.font"                                   ' This is a true type font with variable spacing.
$include "font8x8.font"
   '
   '  * BGF file data *
   '
Plaatje:
   $bgf "ks108.bgf"                                         ' Include the picture data.
 
Back to top
View user's profile Visit poster's website
O-Family

Bascom Expert



Joined: 23 May 2010
Posts: 338
Location: Japan

japan.gif
PostPosted: Wed Jul 06, 2022 7:26 am    Post subject: Reply with quote

This is an example using XTINY [ATmega4809].

Code:

$programmer = 26                                            'MCS UPDI programmer

   '
   '  *****************************************
   '  *  2.42 inch 128x64 dot OLED display    *
   '  *   (SSD1309) Test program  (For XTINY) *
   '  *            O-Family   2022. 7. 6      *
   '  *****************************************
   '

$regfile = "mx4809.dat"
$crystal = 20000000
   '
$hwstack = 64
$swstack = 10
$framesize = 24

   Config Sysclock = 20mhz , Prescale = 1                   ' System clock settings.

   '
   '  OLED controller [SSD1309] settings *
   '
   Const Interface_selection = 1                            ' Interface selection. (0:SPI , 1:I2C,TWI)

'--------------------------------------------------------------------------------------------------
#if Interface_selection = 0
   '
   '  * When connecting with [SPI] *
   '
   Dim _contrast As Byte                                    ' OLED contrast setting value. [0-255]
   Const Ssd1309_rotate = 0                                 ' Screen rotation. (Connecting cable left side = [0], right side = [1])
   $lib "glcdSSD1309-SPI_V2.lib"                            ' Incorporate a library of SSD1309-SPI with additional functionality.
   '  Set the connection port for OLED. Cs1 = [CS], A0 = [DC], Rst = [RES], Si = [SDA], Sclk = [SCLK]
   Config Graphlcd = 128 * 64eadogm , Cs1 = Porta.7 , A0 = Porta.6 , Rst = Porta.5 , Si = Porta.4 , Sclk = Porta.3

#else
   '
   '  * When connecting with [I2C, TWI] (For XTINY) *
   '
   Const I2c_select = 1                                     ' I2C interface selection. (0:Software I2C , 1:Hardware TWI)
   '
   #if I2c_select = 0                                       ' For software I2C.
      Const Twi_adr = Twi0_ctrla : Const Twi_ch = 1         ' [Dummy in library]
      $forcesofti2c                                         ' Force use of software I2C/TWI library.
      $lib "i2c.lbx"                                        ' Overwrite the library for software I2C.
      Config I2cdelay = 1                                   ' SCL clock frequency = approx 260KHz. (At AVR clock 20MHz) (* Maximum 400KHz)
      Config Scl = Porta.5                                  ' Set the port pin to connect the SCL line of the I2C bus.
      Config Sda = Porta.6                                  ' Set the port pin to connect the SDA line of the I2C bus.
      I2cinit                                               ' Initialize the I2C bus.
   #else                                                    ' For hardware TWI.
      Dim Twi_start As Byte                                 ' Variables used in the TWI library.
      Const Twi_adr = Twi0_ctrla                            ' TWI port. TWI_ADR = TWI0_CTRLA:(TWI0)
      Const Twi_ch = 1                                      ' TWI channel. TWI_CH = 1:(TWI0), 2:(TWI1)
      Config Twi0 = 400000                                  ' TWI clock frequency. (400KHz) (* Maximum 400KHz)
      I2cinit                                               ' Initialize the TWI bus.
   #endif
   '
   Dim _contrast As Byte                                    ' OLED contrast setting value. [0-255]
   Reset Porta.7                                            ' Set the [RES] pin of the OLED (SSD1309) to [L]. (Any port)
   Config Porta.7 = Output                                  ' Set the connection port of the [RES] pin of the OLED (SSD1309) to the output.
   Waitms 1                                                 ' The [L] period of the OLED reset pulse.
   Config Porta.7 = Input                                   ' Set the connection port of the [RES] pin of the OLED (SSD1309) to the input. (Open drain)
   Waitms 10                                                ' OLED boot wait time.
   '
   Const Ssd1309_sa0 = 0                                    ' Slave address of SSD1309. (0:SA0=[L] 78H , 1:SA0=[H] 7AH)
   Const Ssd1309_rotate = 0                                 ' Screen rotation. (Connecting cable left side = [0] , right side = [1])
   $lib "glcdSSD1309-I2C_V2.lib"                            ' Incorporate a library of SSD1309-I2C with additional functionality.
   Config Graphlcd = Custom , Cols = 128 , Rows = 64 , Lcdname = "SSD1309"       'OLED settings.

#endif
   Cls                                                      ' Erase all OLED display.
'--------------------------------------------------------------------------------------------------

   '
   '  * OLED display test program *
   '
   Do
      Setfont Font8x8tt                                     ' Select font.
      Lcdat 1 , 1 , "SSD1309 2.42{034} OLED"
      Lcdat 2 , 8 , "128x64dots SPI,I2C"
      Lcdat 6 , 1 , " ABCDefg012345678 " , 2                ' Optional solid underline.
      Lcdat 8 , 1 , " ABCDefg012345678 " , 3                ' Optional dotted underline.
      Setfont Font8x8                                       ' Select font.
      Lcdat 4 , 1 , "[BASCOM-AVR MCS]" , 1                  ' Optional invert.
      Wait 3

      Glcdcmd &HA7                                          ' Normal/Inverse Display. [A7:Inverse]
      Wait 3
      Glcdcmd &HA6                                          ' Normal/Inverse Display. [A6:Normal]
      Wait 3

      _contrast = 0 : Glcdcmd &H81                          ' Change contrast of the OLED. [0:dark - 255:bright]
      Wait 3
      _contrast = 255 : Glcdcmd &H81                        ' Change contrast of the OLED. [0:dark - 255:bright]
      Wait 3

      Glcdcmd &HAE                                          ' Display ON/OFF [AE:OFF(sleep mode) , AF:ON(normal mode)]
      Wait 3
      Glcdcmd &HAF                                          ' Display ON/OFF [AE:OFF(sleep mode) , AF:ON(normal mode)]
      Wait 3

      Showpic 0 , 0 , Plaatje                               ' Draw a BGF file. (BMP compressed image).
      Wait 3
      Cls
   Loop

   End

   '
   '  * Font data *
   '
$include "font8x8TT.font"                                   ' This is a true type font with variable spacing.
$include "font8x8.font"
   '
   '  * BGF file data *
   '
Plaatje:
   $bgf "ks108.bgf"                                         ' Include the picture data.
 
Back to top
View user's profile Visit poster's website
O-Family

Bascom Expert



Joined: 23 May 2010
Posts: 338
Location: Japan

japan.gif
PostPosted: Sun Jul 10, 2022 1:06 am    Post subject: Reply with quote

USI has also confirmed the operation.

Code:

$regfile = "ATtiny85.DAT"
$crystal = 1000000
   '
$hwstack = 64
$swstack = 10
$framesize = 24

   '
   '  When connecting with [I2C,USI] *
   '
   Const I2c_select = 1                                     ' I2C interface selection. (0:Software I2C , 1:Hardware USI)

#if I2c_select = 0                                          ' For software I2C.
   Config Scl = Portb.2                                     ' Set the port pin to connect the SCL line of the I2C bus. (Any port)
   Config Sda = Portb.0                                     ' Set the port pin to connect the SDA line of the I2C bus. (Any port)
   Config I2cdelay = 1                                      ' Set the SCL clock speed for software I2C.
   I2cinit                                                  ' Initialize the I2C bus.
#else                                                       ' For hardware USI.
   Config Usi = Twimaster , Mode = Fast                     ' USI master settings. I2C bus clock = 400KHz
   I2cinit                                                  ' Initialize the I2C bus.
#endif
 
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 6198
Location: Holland

blank.gif
PostPosted: Mon Jul 11, 2022 12:30 pm    Post subject: Reply with quote

hi O-Family,

Well what can i say? It is super how you support it with all the different modes and documentation.
With your permission i add it to bascom distribution too. I will also add a link to this project.
I soon receive the lcd so i can use it too Very Happy

_________________
Mark
Back to top
View user's profile Visit poster's website
O-Family

Bascom Expert



Joined: 23 May 2010
Posts: 338
Location: Japan

japan.gif
PostPosted: Mon Jul 11, 2022 2:01 pm    Post subject: Reply with quote

Hi Mark

I have also benefited a lot from the BASCOM you developed.
I hope this library helps you and other users!
Back to top
View user's profile Visit poster's website
Porelo

Bascom Member



Joined: 23 May 2005
Posts: 52
Location: Portugal

portugal.gif
PostPosted: Sat Jul 23, 2022 11:50 pm    Post subject: Reply with quote

This is a spirit of sharing and helping.

Miguel
Back to top
View user's profile Yahoo Messenger
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 6198
Location: Holland

blank.gif
PostPosted: Tue Aug 09, 2022 1:42 pm    Post subject: Reply with quote

thanks again, i just tested it and it works excellent with an EA-DOG. That display requires a separate 12V driver.
When this complete project is done i will share some images.

_________________
Mark
Back to top
View user's profile Visit poster's website
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1198
Location: France

france.gif
PostPosted: Thu Dec 08, 2022 7:43 pm    Post subject: Reply with quote

Hello,
I am a bit lazy, and before buying one, I would like to know if it is possible to draw (circle, line, square etc ) with this display or it is only CHR ?
Many thanks for your answers
Wink
JP

_________________
pleasure to learn, to teach, to create
Back to top
View user's profile Visit poster's website
O-Family

Bascom Expert



Joined: 23 May 2010
Posts: 338
Location: Japan

japan.gif
PostPosted: Fri Dec 09, 2022 9:35 am    Post subject: Reply with quote

This type of controller cannot read the display RAM in I2C or SPI serial mode.
Therefore, drawing instructions such as LINE cannot be used.
Back to top
View user's profile Visit poster's website
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1198
Location: France

france.gif
PostPosted: Fri Dec 09, 2022 9:54 am    Post subject: Reply with quote

O-Family
thank you very much, I will go for another graphic display. I am looking for a small 2 or 3" display with graphic capabilities and of course compatible Bascom. If you or someone has an idea ?
In addition, since we are at the end of the year, I would like to congratulate you for your contributions to the forum, always effective, relevant and nice.

This is an old man's opinion, but I am sure it is shared
Wink JP

_________________
pleasure to learn, to teach, to create
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Share your working BASCOM-AVR code here All times are GMT + 1 Hour
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum