Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

sh1106-i2c

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
krolikbest

Bascom Member



Joined: 02 Jan 2017
Posts: 66

poland.gif
PostPosted: Wed Jan 01, 2020 7:03 pm    Post subject: sh1106-i2c Reply with quote

Hi

first of all- Happy New 2020 Smile and perhaps first question in 2020 Smile
have graphic lcd 1.3 inch with driver sh1106 i2c.It has 4 pins:
-vcc (3.3v to 5v) ->connected to 5v of arduino
-grnd ->connected to grnd of arduino
-sda -> connected to sda of arduino
-scl -> connected to scl of arduino
I got it run with arduino uno but noticed that when I use routine wait/waitms in loop lcd get blank screen and reset of arduino doesn't help.
Below my simply code i tested lcd with

Code:

$regfile = "m328pdef.dat"
$crystal = 16000000
$hwstack = 40
$swstack = 40
$framesize = 40

$lib "i2c_twi.lbx"              
$lib "glcdSH1106-I2C.lib"  

Config Twi = 400000        
Config Scl = Portc.5          
Config Sda = Portc.4
Config Portc.3 = Output

I2cinit

Lcd_reset Alias Portc.3
Lcd_reset = 0
Waitms 100
Lcd_reset = 1
Waitms 100

Config Graphlcd = Custom , Cols = 128 , Rows = 64 , Lcdname = "SSD1306"
cls
Do
  Setfont Font8x8tt            
  Lcdat 1 , 1 , "103"
  Lcdat 2 , 2 , "222"

  'wait 1 [b]<-that simply hang up...[/b]

  Lcdat 3 , 2 , "whatever" ; i
Loop
End
$include "Font8x8TT.font"  
 

It looks like "wait" cannot cooperate with some routines from glcdSH1106-I2C library... maybe..

Regards,
Martin

(BASCOM-AVR version : 2.0.8.0 , Latest : 2.0.8.2 )
Back to top
View user's profile
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 923
Location: France

france.gif
PostPosted: Thu Jan 02, 2020 10:15 am    Post subject: Reply with quote

did you see the help about GLCDdSSD1306-I2C ?

is it working for you ?

do you have pull up R 4.7k on line SDA SCL ?

Happy new year
Wink
jp

_________________
pleasure to learn, to teach, to create
Back to top
View user's profile Visit poster's website
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 923
Location: France

france.gif
PostPosted: Thu Jan 02, 2020 10:21 am    Post subject: Reply with quote

this small prog work for me i add only the first lines

Code:
'-----------Microcontroleur------------------------------------------------------------------------------------------------
$regfile = "attiny85.dat"
$crystal = 1000000
$hwstack = 40
$swstack = 40
$framesize = 40
'---- config------------------------------------------------------------------------------------------------------------------
Config Clockdiv = 8
Config Submode = New
 '-------------------------------- I2C bus  Tiny85--------------------------------------------------------------------------
Config Sda = Portb.0
Config Scl = Portb.2
I2cinit
Waitms 5
' -------les ports------------------------------------------------------------------------------------------------------------
Vote Alias Portb.1
Raz Alias Portb.3
Config Vote = Input
Config Raz = Input
Set Vote                                                    'activation des pull up
Set Raz
 'display---------------------------------------------------------------------------------------------------------------------
$lib "glcdSSD1306-I2C.lib"
Config Graphlcd = Custom , Cols = 128 , Rows = 64 , Lcdname = "SSD1306"
Dim Lcd_auto As Byte
Lcd_auto = 1
Enable Interrupts
'----var-----------------------------------------------------------------------------------------------------------------------
Dim Compteur As Integer
Dim Regb As Byte
Dim Memoire As Eram Integer
Dim Fxmem As Integer
Dim Stcomp As String * 3
Dim Flagzero As Byte
'---prog----------------------------------------------------------------------------------------------------------------------
Compteur = 0
Fxmem = Memoire                                             'lecture mémoire
If Fxmem => 0 Then Compteur = Memoire
Setfont Font12x16


   Cls
   Lcdat 4 , 1 , " LONGPONT"



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

Bascom Member



Joined: 02 Jan 2017
Posts: 66

poland.gif
PostPosted: Thu Jan 02, 2020 2:38 pm    Post subject: Reply with quote

Thank for your reply. Yes I've read about ssd1306-i2c but I use library for sh1106-i2c. basically it works but when it comes to execute "wait" statement then oled screen is blank and rest of the program seems to stop. Without "wait" i can even make animation and it looks very good.
There is no difference if I use or not 4.7K resisors. Actually i don't use, but using them the effect is the same- on "wait" statement program stops.

Regards,
Martin
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5013
Location: Holland

blank.gif
PostPosted: Thu Jan 02, 2020 2:53 pm    Post subject: Reply with quote

you should check this : $crystal = 16000000

Is the clock actual 16 Mhz ?
Instead of wait, use waitms and see how long it actually takes.
first try waitms 1
then 10, 100 and finally 1000

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

Bascom Member



Joined: 02 Jan 2017
Posts: 66

poland.gif
PostPosted: Thu Jan 02, 2020 5:36 pm    Post subject: Reply with quote

Hi Mark,
tested this code:
Code:

$regfile = "m328pdef.dat"
$crystal = 16000000
$hwstack = 40
$swstack = 40
$framesize = 40

$lib "i2c_twi.lbx"
$lib "glcdSH1106-I2C.lib"

Config Twi = 400000
Config Scl = Portc.5
Config Sda = Portc.4
Config Portc.3 = Output

I2cinit

Lcd_reset Alias Portc.3
Lcd_reset = 0
Waitms 100
Lcd_reset = 1
Waitms 100

Config Graphlcd = Custom , Cols = 128 , Rows = 64 , Lcdname = "SSD1306"

cls
Do
  waitms 1
  cls
  Setfont Font8x8tt
  Lcdat 8 , 5 , "test test"
Loop
End

$include "Font8x8TT.font"
 


it seems that there is no difference between 10 or 1000 ms. For waitms=1 ms or waitms=2 ms it seems to work, but higher values make screen blank. if "waitms" i commented it works.

Regards,
Martin
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5013
Location: Holland

blank.gif
PostPosted: Fri Jan 03, 2020 11:27 am    Post subject: Reply with quote

you best display a counter which you increase inside the loop.
this way you can detect a reset.

it really does not make any sense that waitms does not work so it is most likely some hardware problem. a reset for example.

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

Bascom Member



Joined: 22 Jun 2004
Posts: 923
Location: France

france.gif
PostPosted: Fri Jan 03, 2020 4:54 pm    Post subject: Reply with quote

in my little program I use wait


Code:

Do
   Regb = Liresw()
    If Regb = 1 And Compteur = 0 Then Cls
   Select Case Regb
      Case 1
         Compteur = Compteur + 1
         Stcomp = Str(compteur) : Stcomp = Format(stcomp , "000")
         Lcdat 1 , 50 , Stcomp
         Memoire = Compteur                                 'mise en EEprom
      Case 2                                                'raz
         Compteur = 0
         Cls
         Lcdat 1 , 1 , "RAZ:" ; Compteur
         Wait 1
         Cls
         Memoire = Compteur                                 'mise en EEprom
         Goto 0                                             'reinitialise le µp
   End Select
Loop


So as Mark I think is is not a Bascom problem

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

Bascom Member



Joined: 02 Jan 2017
Posts: 66

poland.gif
PostPosted: Fri Jan 03, 2020 9:03 pm    Post subject: Reply with quote

Hello,

actually i'm a bit confused. I lowered crystal to 8MHz (normally 16MHz) and then I could use waitms till 300 ms. if crystal is 16MHz i couldn't use waitms higher than 2ms.
I noticed that if in program now I use waitms > 300, e.g.
Code:

   cls
   Setfont Font8x8
   Lcdat 7 , 6 , "test test" , 0
   waitms 400
 

it can work normally but after some time the text is displayed in random positions instead x,y, sometimes presumably above an acceptable range (128x64), that is why screen is blank then. The higher waitms value the more often screen is blank. So it is not a "wait" problem, now it looks like the problem is really on the display side strictly speaking with data transfer through i2c service. Anyway I'll work around it. Thank you for helping me.

Regards,
Martin
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
Page 1 of 1

 
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