Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

SSD1306 & SH1106 SPI Oled bgf picture display
Goto page 1, 2  Next
 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
Pzx

Bascom Member



Joined: 05 May 2015
Posts: 39

poland.gif
PostPosted: Sat Feb 25, 2017 1:11 am    Post subject: SSD1306 & SH1106 SPI Oled bgf picture display Reply with quote

Hello,

I would like to display included bgf pictures using the hkipniks Oled SPI code. The code works fine with SSD1306 and SH1106 SPI displays but doesnt support bgf pictures.
link:
http://bascomforum.de/index.php?thread/120-ssd1306-oled-display-1-3-i2c-spi/

I tryied use the code from Stefan, but I was not able to open included bgf file.
link:
http://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=8283&highlight=bgf+format

Can anyone help me with that? How to open included bgf file (open for binary)? Do I need AVR-DOS library?

Thanks,
Pzx

(BASCOM-AVR version : 2.0.7.8 )


Last edited by Pzx on Thu Mar 02, 2017 11:12 am; edited 1 time in total
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 1133

poland.gif
PostPosted: Sat Feb 25, 2017 2:00 pm    Post subject: Reply with quote

Hey. What about using forum searchengine with inquiry "SSD1306"
You will find already maked optimised asm library for this display maded by Mrshilov Very Happy

This link take you there Wink

About writing this in Basic you dont need to use AVR-DOS and BGF can be stored in uC flash memory with easy.
BGF is encoded RLE for less code binary file.
So all what is needed is to use Restore Some_example_label and then use Read sequentially bytes till picture end.
In two first bytes header in BGF picture height and width is stored.
Back to top
View user's profile Visit poster's website
Pzx

Bascom Member



Joined: 05 May 2015
Posts: 39

poland.gif
PostPosted: Sat Feb 25, 2017 2:35 pm    Post subject: Reply with quote

Thanks for your fast replay, as usuall EDC Smile

You are right, that would be the best way, but unfortunately Mrshilov SSD1306 SPI-4 and SPI-3 library does not work with my display. The screen remains black. Maybe firstly I should deeper investigate that.
Link to the display:

http://www.waveshare.com/1.3inch-oled-b.htm

I tryied with Mrshilov bas and libs SPI-4 from the link:

http://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=13550&highlight=ssd1306

and after changindg display config into SPI-3:

http://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=13641&highlight=ssd1306

My Oled does not work with the above codes, but works well with hkipniks Oled SPI code (link in my first post)
Port config of my ATMEGA 2560 is as follow:

'Config for hkipniks code:
Config Portb.0 = Output 'DISPLAY_SS CS
Config Portk.5 = Output 'DISPLAY_RS D/C
Config Portb.2 = Output 'Spi_mosi D1
Config Portb.1 = Output 'SPI_SCK D0
Config Portk.6 = Output 'DISPLAY_Reset

'Config for Mrshilov SPI-4 code:
$lib "glcdSSD1306-SPI.lib"
Config Graphlcd = 128x64sed , A0 = Portk.5 , Si = Portb.2 , Sclk = Portb.1 , Cs1 = Portb.0 , Rst = Portk.6

'Config for Mrshilov SPI-3 code:
$lib "glcdSSD1306-SPI-3.lib"
Config Graphlcd = 128x64sed , Si = Portb.2 , Sclk = Portb.1
Reset = +5V
CS= Disconected
D/C = 0V

Can anyone help with finding why it does not work?


Last edited by Pzx on Sat Feb 25, 2017 8:53 pm; edited 2 times in total
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 1133

poland.gif
PostPosted: Sat Feb 25, 2017 4:19 pm    Post subject: Reply with quote

Unfortunately I dont have this display so this is my first dealing with this.
But after quick look at the code I`m thinking that it is some kind of software SPI and any uC pins can be used.
So not only hardware ISP and question is do you set those choosen control pins as outputs?
Please try it without initiate hardware SPI (if used) and set pins as outputs.

Also note this, that in two wire mode CS should be grounded not disconnected.
Back to top
View user's profile Visit poster's website
Pzx

Bascom Member



Joined: 05 May 2015
Posts: 39

poland.gif
PostPosted: Sat Feb 25, 2017 8:28 pm    Post subject: Reply with quote

I bought another Oled SPI-4 SSD1306 display (this model is without CS pin):

https://telmal.com/pl/p/Wyswietlacz-OLED-0%2C96-SPI-3-5V-SSD1306-niebieski-/408

The result is exactly the same - works well with hkipniks code (I tested with sw SPI and hw SPI) but still does not work with Mrshilov code.
I tried also to initialize hw SPI and to set ports as outputs in Mrshilov code - no result.

EDC, if you want to play a little with this display I can send you one Smile
Back to top
View user's profile
kimmi

Moderator



Joined: 24 Feb 2006
Posts: 1922
Location: Denmark

denmark.gif
PostPosted: Sun Feb 26, 2017 5:03 am    Post subject: Reply with quote

Pzx,
your lcd only have DI pin not DO (NC)

lib use this pin ,
my 1.3" sh1106 have the DO pin and works fine with
Mrshilov SSD1306 SPI-4 & hkipniks Oled SPI code


_________________
/ Kim
Back to top
View user's profile Visit poster's website MSN Messenger
Pzx

Bascom Member



Joined: 05 May 2015
Posts: 39

poland.gif
PostPosted: Sun Feb 26, 2017 9:18 am    Post subject: Reply with quote

Kimmi, thanks for your answer and a nice foto.
I think there are different names of the same pins of different Oleds producers.
One direction SPI-3 interface needs at list CLK (SCLK) and DATA that is sent from uP to Oled (MOSI). When we use SPI-4 the interface needs additionaly D/C signal (SS) for Command/Data identification.
In my oppinion in case of your display D0 and D1 are used as CLK and DATA signals (or the opposite).
The remaining pins are:
RST - Reset
DC - D/C (SS)
CS - Chip Select
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 1133

poland.gif
PostPosted: Sun Feb 26, 2017 1:15 pm    Post subject: Reply with quote

I download Hkipniks code to look for differences.
Libs are not mystery and can be edited by users if they know what to do Very Happy
Maybe someone find this fun, like me Very Happy
Lib is like TXT file.

First difference is duration of reset and wait after reset.
In Hkipniks code this is 100ms
Code:
Lcd_rst = 0
   Waitms 100                                               'Reset Display
   Lcd_rst = 1
   Waitms 100

In lib you have 10ms
Code:
*cbi _GLCD_PORT_RST,_glcd_rst        ; Hardware reset (if exist)
    ldi r24,10     '<------------------------------------------------ change it into 100 for test
    clr r25
    *Call _Waitms
    *sbi _GLCD_PORT_RST,_glcd_rst
    ldi r24,10     '<------------------------------------------------ change it into 100 for test
    clr r25
    *Call _Waitms


Next difference is sequence/values of initialisation bytes:

Code:
AE D5 80 A8 3F D3 00 8D 14 20 00 A1 C8 DA 12 81 55 D9 F1 DB A4 A6 AF  ' basic
AE A1 C8 20 00 D5 F0 A8 3F D3 00 40 DA 12 81 FF D9 F1 A4 A6 8D 14 AF  ' lib


So maybe change it in next step if longest reset duration dont take effect.
Have fun Very Happy
Back to top
View user's profile Visit poster's website
Pzx

Bascom Member



Joined: 05 May 2015
Posts: 39

poland.gif
PostPosted: Mon Feb 27, 2017 11:30 pm    Post subject: Reply with quote

After some tests I found out that port k of ATMEGA2560 can not be used as D/C pin in Mrshilov SPI code (can be used in hkipniks code).
With that assuption samaller (0,96') display that has SSD1306 controller started to work well.
Changing Reset time and Initialization sequence in the lib had no impact - still works well.

Example of good pin configuration:

$lib "glcdSSD1306-SPI.lib"
Config Graphlcd = 128x64sed , Si = Portb.2 , Sclk = Portb.1 , A0 = Portb.0 , Rst = Portb.3

Si->SDA
Sclk->SCL
A0->D/C
Rst->RST

Unfortunately bigger display (1,3') with SH1106 controller (very similar to SSD1306) still does not work with Mrshilov SPI code (works with hkipniks code)
Changing Reset time and Initialization sequence in the lib did not help.

My pin configuration:

$lib "glcdSSD1306-SPI.lib"
Config Graphlcd = 128x64sed , Cs1 = Portb.7 , Si = Portb.2 , Sclk = Portb.1 , A0 = Portb.0 , Rst = Portb.3

Cs1->CS
Si->DIN
Sclk->CLK
A0->D/C
Rst->RES
Back to top
View user's profile
kimmi

Moderator



Joined: 24 Feb 2006
Posts: 1922
Location: Denmark

denmark.gif
PostPosted: Mon Feb 27, 2017 11:36 pm    Post subject: Reply with quote

Quote:
Unfortunately bigger display (1,3') with SH1106 controller (very similar to SSD1306) still does not work with Mrshilov SPI code (works with hkipniks code)

i dont get it mine lcd is a Sh1106 controller 1.3" and dont have problems with Mrshilov code its muts faster than hkipniks code

here is my code and pin setup (M328P) and works fine

Quote:
Pin description
GND: power ground
VCC: 3.3V or 5V power supply
D0: CLK clock
D1: MOSI data
RST: reset
DC: data / command
CS: chip select signal


Code:
'-------------------------------------------------------------------------------
'                              SSD1306
'                      BASCOM-AVR - Mrshilov 2016
'===============================================================================
$regfile = "m328Pdef.dat"
$crystal = 8000000
$hwstack = 64
$swstack = 64
$framesize = 64
Config Clockdiv = 1
Mcucr.7 = 1                                                 'Turn OFF JTAG
Mcucr.7 = 1
'-------------------------------- Display --------------------------------------
$lib "glcdSSD1306-SPI.lib"
Config Graphlcd = 128x64sed , A0 = Portb.4 , Si = Portb.3 , Sclk = Portb.2 , Cs1 = Portb.5 , Rst = Portb.1
Const Lcd_remap = 1                                         ' Default remap = 1, for some models = 2
'DC PB.4
'DI PB.3
'DO PB.2                                    '
'CS PB.5
'RES PB.1
'gnd  gnd                                 '
'vcc +3.3v
Dim I As Byte , N As Byte
'-------------------------------- Program --------------------------------------
Cls
Setfont Font12x16
Do
   Lcdat 0 , 30 , "SH1106"
   Wait 1
   Lcdat 2 , 30 , "4-WIRE" , 1                                 ' inverse text
   Wait 1
   Showpic 0 , 0 , Pic
   Wait 1
   Lcdat 4 , 20 , "CONTRAST" , 0                               ' inverse text
   For N = 255 To 0 Step - 1                                  'down contrast
      Lcdcontrast N
      Lcdat 6 , 52 , N ; "  "
      Waitms 2
   Next N
   Wait 1
   For N = 1 To 255                                           'up contrast
      Lcdcontrast N
      Lcdat 6 , 52 , N ; "  "
      Waitms 2
   Next N
   Wait 1
   Cls
Loop
End
'===============================================================================
$include "font12x16.font"
Pic:
   $bgf "picture.bgf"
 

then code is almost same for SSD1306 & Sh1106
set charge pump enable & external VCC are diffrent you can try to set it in this 2 ways (both work for me)
for ssd1306 its AD 8B
for SH1116 its 8D 14

in glcdSSD1306-SPI.lib : (\MCS Electronics\BASCOM-AVR\LIB\)

Code:
If SH1106
_lcd_init_data:
.db $AE, $A1, $C8, $20, $00, $D5, $F0, $A8, $3F, $D3, $00
.db $40, $DA, $12, $81, $FF, $D9, $F1, $A4, $A6, $8D, $14, $AF

If SSD1306
_lcd_init_data:
.db $AE, $A1, $C8, $20, $00, $D5, $F0, $A8, $3F, $D3, $00
.db $40, $DA, $12, $81, $FF, $D9, $F1, $A4, $A6, $AD, $8B, $AF

_________________
/ Kim
Back to top
View user's profile Visit poster's website MSN Messenger
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 1133

poland.gif
PostPosted: Tue Feb 28, 2017 12:16 am    Post subject: Reply with quote

I also take a look into basic code again and today I saw:
Code:
Const Driver_typ = 0                                        'SSD1306 =1   SH1106 =0

and below in code for example:
Code:
#if Driver_typ = 1
      Call Lcd_comm_out(&H00)                               'column address lower 4 bits + 0x00    H02 for SH1106
   #else
      Call Lcd_comm_out(&H02)
   #endif

So these differences should be taken into account.

About PORTK is a extended IO but one from PORTA to PORTG should work fine Very Happy
Back to top
View user's profile Visit poster's website
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 1133

poland.gif
PostPosted: Tue Feb 28, 2017 7:27 pm    Post subject: Reply with quote

I should do something else but I could not resist Very Happy
I take code from Arduino section and I mood one routine.
Yo can grab example how BGF can be decoded in basic.
Code and BGF file from this screens attached Very Happy
This can be adapted for testing new displays where libs are not available yet.
Normally columns and rows are counted but here I countdown bytes to write for simplicity.

[EDIT] I forgot about situation when AA should be shown Very Happy

Code:
'we start reading from point that "Restore Gif"  set

  Read Height                                               'sholud be divide by 8 because 8 byte bits
  Read Width                                                'number of colums

  Sum = 1024                                                'can be calculated from the above

  Startpoint1:                                              'if we  do some repeats then we back here for new
   Read Value                                               'read first value
  Startpoint2:
   Read Rle                                                 'read second                                             '
 'check if we must repeat somethig (AA means that if next byte <>0
  If Rle <> &HAA Then                                       'no, we must show this byte and read new
   I2cwbyte Value
    Value = Rle                                             'save readed value because nex byte can be AA
   Decr Sum : If Sum = 0 Then Goto Exit_this
    Goto Startpoint2                                        'back for one byte only
  Else
   'RLE=AA so we must know how many bytes repeat
   Read Repeats
   For Y = 1 To Repeats
    I2cwbyte Value
     Decr Sum
   Next
   If Sum = 0 Then Goto Exit_this
    Goto Startpoint1                                        'back to top for two new values and skip used AA
  End If

  Exit_this:
Back to top
View user's profile Visit poster's website
Pzx

Bascom Member



Joined: 05 May 2015
Posts: 39

poland.gif
PostPosted: Thu Mar 02, 2017 11:08 am    Post subject: Reply with quote

I reconfigured jumpers and tested my 1,3' SH1106 display with I2C interfece using this lib:

http://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=13013&highlight=sh1106

It works fine with software and also hardware I2C (much faster)
Maybe there is an easy way to change the interface from I2C to SPI (preferably hardware SPI) inside this lib?
Back to top
View user's profile
Pzx

Bascom Member



Joined: 05 May 2015
Posts: 39

poland.gif
PostPosted: Tue Mar 21, 2017 6:48 pm    Post subject: Reply with quote

After several days of tests I give up because I still can not effectively work with SH 1106 1,3' oled display using SPI interface. Hkipniks code works fine but offers limited functionality (no bgf and TT fonts) and its relatively slow. This display is very popular because its easy to buy, cheap (10$) and 30% bigger than SSD1306.
Maybe I could have a question or suggestion for Mark and/or Mrshilov to write a Bascom driver for SH 1106 using SPI interface (SW and HW options would be great). I would buy with pleasure a new version of Bascom with that feature included. For sure not only me.
Back to top
View user's profile
Hkipnik

Bascom Member



Joined: 03 May 2010
Posts: 20

PostPosted: Fri Mar 24, 2017 11:05 am    Post subject: Reply with quote

Hello,

For the SH1106-SPI Display you can use this LIB
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR 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