Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Arduino Nano with I2c LCD and backlight
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-ARDUINO
View previous topic :: View next topic  
Author Message
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Sun Jul 03, 2016 8:48 am    Post subject: Reply with quote

I ordered another I2C LCD board and attached it to another LCD
they both work you can switch between them
This means you could have 8 LCDs on the bus all displaying different data
You only need to change the I2C address the code to display the data can be used for all displays
Now all we need is a library to drive the low cost 64 x 128 type LCDs via I2C using 2 PCF8574

Regards Paul
Back to top
View user's profile
bzijlstra

Bascom Ambassador



Joined: 30 Dec 2004
Posts: 1179
Location: Tilburg - Netherlands

netherlands.gif
PostPosted: Sun Jul 03, 2016 2:29 pm    Post subject: Busy... Reply with quote

Sorry Paul, promised to test, was a bit to busy with MQTT. Nice to hear it is working.

Have fun
Ben Zijlstra
Back to top
View user's profile Visit poster's website
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Mon Jul 04, 2016 10:28 am    Post subject: Reply with quote

That's ok Ben there are only so many hours in the day Very Happy

I have now tested the BIG character routines and they also work
still need the home though

Regards Paul
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Mon Sep 05, 2016 12:14 pm    Post subject: Reply with quote

I`ve test this because sometimes it will be helpful to attach LCD for debug to projects where no more pins available.
I found thing that is obvious for now but before that lines was wrong addressing for lcd`s that have more than two lines Very Happy
You must add Config Lcd = 20x4 and you have it proper Very Happy

BTW. I also want to run this with TWI ..and this also working but with 8MHz clock.
For 16MHz there must be done some tweak Very Happy
Code:
$regfile = "m16def.dat"
$crystal = 8000000
$hwstack = 64
$swstack = 64
$framesize = 128

$lib "i2c_twi.lib"

$lib "bl_Lcd_i2c.lib"                                       ' AN #118 library from Kent
                                                            ' with this addition
                                                            ' * lds r27,{backlight}
                                                            ' andi _temp2,&hf7
                                                            ' or _temp2,r27

Config Lcd = 20x4                                           ' important to have proper line addressing

Const Pcf_d4 = 4
Const Pcf_d5 = 5
Const Pcf_d6 = 6
Const Pcf_d7 = 7
Const Pcf_rs = 0
Const Pcf_rw = 1
Const Pcf_e1 = 2


Dim B As Byte
Dim A As Byte
Dim _lcd_e As Byte
Dim Backlight As Byte

Backlight_on Alias &H08
Backlight_off Alias &H00

Backlight = Backlight_on

_lcd_e = 128

Const Pcf8574_lcd = &H4E                                    'Defines the address of the I/O expander for LCD

Config Scl = Portc.0                                        'we need to provide the SCL pin name
Config Sda = Portc.1
I2cinit

Config Twi = 100000                                         ' wanted clock frequency

Wait 1 : Cls

Locate 3 , 8                                                ' If you miss "Config Lcd = 20x4"
 Lcd "test..."                                              ' then this will be printed in Fourth line

Locate 4 , 18 : Lcd "Tst"
End
 
Back to top
View user's profile Visit poster's website
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Mon Apr 03, 2017 1:36 pm    Post subject: Reply with quote

If someone think that LCD via I2C is lazy look this 30s video Very Happy

https://youtu.be/rKYEyugX9pA
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5917
Location: Holland

blank.gif
PostPosted: Mon Apr 03, 2017 2:43 pm    Post subject: Reply with quote

really amazing. Smart programming of the text LCD. I like it Very Happy
_________________
Mark
Back to top
View user's profile Visit poster's website
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Mon Apr 03, 2017 2:50 pm    Post subject: Reply with quote

In the truth the shag - poaching horse, is from Bascom application notes (one made by Radan) LINK

I only make this video to show someone else on polish forum that this is really easy to achieve Very Happy
And also post it here because used library is from this topic.

Finally i was think that show simple "Hello world" will not be interesting as this horse is I think hahaha Very Happy
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5917
Location: Holland

blank.gif
PostPosted: Mon Apr 03, 2017 3:06 pm    Post subject: Reply with quote

thanks for pointing that out. I knew about clever programming of LCD. But i forgot about this AN. I had no idea that it would look that good.
A video makes all the difference.

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

Bascom Member



Joined: 02 Oct 2010
Posts: 6

PostPosted: Tue Apr 11, 2017 6:35 pm    Post subject: Reply with quote

I am also out of pins and wanted to try the I2C LCD controller
I use this simple code

Code:

$regfile = "m328pdef.dat"
$crystal = 8000000
$baud = 57600
$hwstack = 100                                              ' default use 32 for the hardware stack
$swstack = 100                                              'default use 10 for the SW stack
$framesize = 100                                            'default use 40 for the frame space

Config I2cdelay = 40
$lib "bl_Lcd_i2c.lib"                                       ' AN #118 library from Kent

Backlight_on Alias &H08
Backlight_off Alias &H00

Const Pcf_d4 = 4
Const Pcf_d5 = 5
Const Pcf_d6 = 6
Const Pcf_d7 = 7
Const Pcf_rs = 0
Const Pcf_rw = 1
Const Pcf_e1 = 2


Dim B As Byte
Dim A As Byte
Dim _lcd_e As Byte
Dim Backlight As Byte

_lcd_e = 128
Const Pcf8574_lcd = &H7E                               'Defines the address of the I/O expander for LCD

Config Scl = Portd.3                                        'Is serial clock SCL
Config Sda = Portd.4

'=======================================
  'without this you get rubbish on LCD at power up
    Home
'=======================================
   Locate 1 , 1
   Lcd "Test Line 1"


   Locate 2 , 1
   Lcd "Test Line 2"

End
 


At compile time I get the following errors:

Error : 46 Line : 45 Assignment error, unknown variable (DIM) [LCD_BACKLIGHT: 0 1: 112]
Error : 5 Line : 45 No more space for BIT [LCD_BACKLIGHT]
Error : 320 Line : 45 [syntax error, token = '{']

The bl_Lcd_i2c.lib library is in the lib directory of Bascom

What am I doing wrong?
Back to top
View user's profile
bzijlstra

Bascom Ambassador



Joined: 30 Dec 2004
Posts: 1179
Location: Tilburg - Netherlands

netherlands.gif
PostPosted: Tue Apr 11, 2017 9:52 pm    Post subject: Some questions about i2c LCD Reply with quote

In the first item of this thread there is also an example with the atmega328p. On an Arduino Nano. Only the addrress on the I2c bus is different. &H4E instead of &H7E. I see, when I compare this example with your example that you mis a library.

I also see 172 downloads but don't see that many complaints.

So the example should work with perhaps some remarks of PaulVK.

How did you manage to get the i2c address of your lcd-module? Did you use the i2c scan option? Are the config statements for slk and sda correct?

The library is pure ASCII do you see any variable with the name LCD_BACKLIGHT? I am not on a PC right now.

Have fun
Ben Zijlstra
Back to top
View user's profile Visit poster's website
pippofranco

Bascom Member



Joined: 02 Oct 2010
Posts: 6

PostPosted: Tue Apr 11, 2017 11:22 pm    Post subject: Reply with quote

Hi bzijlstra, thank you for the answer.

I found the base address with an I2C scan.

There is the following LCD_BACKLIGHT variable in the library:

*Basic: lcd_backlight = 1

Just in case I stripped down the example code for Arduino nano but I get the same errors, I should be missing something trivial.


Code:

'I2c LCD on Arduino Nano 16x2 display with backlight

$regfile = "M328pdef.dat"                                   ' the used chip
$crystal = 8000000                                          ' frequency used
$baud = 9600                                                ' baud rate
Config I2cdelay = 10
$lib "bl_Lcd_i2c.lib"

Const Pcf_d4 = 4
Const Pcf_d5 = 5
Const Pcf_d6 = 6
Const Pcf_d7 = 7
Const Pcf_rs = 0
Const Pcf_rw = 1
Const Pcf_e1 = 2

Dim B As Byte
Dim A As Byte
Dim _lcd_e As Byte
Dim Backlight As Byte

Backlight_on Alias &H08
Backlight_off Alias &H00

Backlight = Backlight_on

_lcd_e = 128

Const Pcf8574_lcd = &H7E                                    'Defines the address of the I/O expander for LCD

Config Scl = Portd.3                                             'we need to provide the SCL pin name
Config Sda = Portd.4

I2cinit

Wait 2

Cls
Home
Lcd "i2c-display"                                           'display this at the top line
End
 


Error : 46 Line : 41 Assignment error, unknown variable (DIM) [LCD_BACKLIGHT: 0 1: 112]
Error : 5 Line : 41 No more space for BIT [LCD_BACKLIGHT]
Error : 320 Line : 41 [syntax error, token = '{']


Brick wall
Back to top
View user's profile
bzijlstra

Bascom Ambassador



Joined: 30 Dec 2004
Posts: 1179
Location: Tilburg - Netherlands

netherlands.gif
PostPosted: Tue Apr 11, 2017 11:42 pm    Post subject: Still missing a $lib Reply with quote

Still missing the second $lib call compared to the first example in the tread.

And what about $hwstack, $swstack and $framesize. You must be using an old Bascom-AVR version.

Have fun
Ben Zijlstra
Back to top
View user's profile Visit poster's website
pippofranco

Bascom Member



Joined: 02 Oct 2010
Posts: 6

PostPosted: Wed Apr 12, 2017 2:22 am    Post subject: Reply with quote

If you mean
$lib "i2c_twi.lib"
I use software TWI, I shouldn't need it
$hwstack, $swstack and $framesize: I haven't understood yet how to set them up but eventually I will learn Very Happy
I am using Bascom 2.0.7.8
Back to top
View user's profile
bzijlstra

Bascom Ambassador



Joined: 30 Dec 2004
Posts: 1179
Location: Tilburg - Netherlands

netherlands.gif
PostPosted: Wed Apr 12, 2017 6:44 am    Post subject: Some things missing Reply with quote

I hope you understand that the
Backlight_on= &h08
Backlight_off = &h00

Are aliases. It shall be OR'ed with what should go on the in-output pins of the PCF8574 on the small PCB. &h08 will put a 1 in the 4th pin of the PCF8574.

I see no
Backlight = Backlight_on
or
Backlight = Backlight_off

Some LCD command should trigger going to the library so perhaps you can add CLS to your two LCD commands.

If you don't fill backlight it will stay 0 and your backlight will stay off.

Could you give it a try?
Ben Zijlstra
Back to top
View user's profile Visit poster's website
pippofranco

Bascom Member



Joined: 02 Oct 2010
Posts: 6

PostPosted: Wed Apr 12, 2017 8:42 am    Post subject: Reply with quote

I managed to get it running:

I modified the line :
Dim Backlight As Byte into Dim Lcd_backlight As Byte
and solved the 3 errors

got rid of
Backlight_on Alias &H08
Backlight_off Alias &H00
as Lcd_backlight accepts 0 or 1
(&H08 is actually the value to write to the Pcf8574 to turn on/off the backilight)
Not needed but added Const Pcf_e2 = 3


Code:

$regfile = "M328pdef.dat"                                   ' the used chip
$crystal = 8000000                                          ' frequency used

$lib "bl_Lcd_i2c.lib"

Const Pcf_d4 = 4
Const Pcf_d5 = 5
Const Pcf_d6 = 6
Const Pcf_d7 = 7
Const Pcf_rs = 0
Const Pcf_rw = 1
Const Pcf_e1 = 2
Const Pcf_e2 = 3

Dim A As Byte
Dim _lcd_e As Byte
Dim Lcd_backlight As Byte


_lcd_e = 128

Const Pcf8574_lcd = &H7E

Config Scl = Portd.3
Config Sda = Portd.4
Config I2cdelay = 10
I2cinit
Waitms 100
Lcd_backlight = 1

Cls
Home
Lcd "i2c-display"
For A = 0 To 10
   Lcd_backlight = 1
   Locate 2 , 1
   Lcd A
   Waitms 800
   Lcd_backlight = 0
   Locate 2 , 1
   Lcd "    "
   Waitms 800
Next
Lcd_backlight = 1
Locate 2 , 1
Lcd "End"
End
 


Thank you for the help
Regards,
PF
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-ARDUINO All times are GMT + 1 Hour
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
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