Page 1 of 2

3C : LCD I2C

Posted: Fri Jan 21, 2011 12:59 pm
by Dan81
Hello

I'm still using "Customize Component Code" (only for Flowcode v4)

I'll post the code soon.

There'll be all the usual "Component Macros" with an I2C management.

I use a classic LCD with a GPIO (from Microchip) : MCP23008.

The only rule is to respect the schematic below.
lcd_mcp.jpg
lcd_mcp.jpg (28.11 KiB) Viewed 45590 times
Daniel

Re: 3C : LCD I2C

Posted: Fri Jan 21, 2011 2:31 pm
by Benj
Hi Dan,

Great idea for an article. We actually use the SPI version of this output expander on the EB057 and EB058 gLCD to allow for the LCD pins to be controlled from a single E-blocks port. The SPI version is pretty much identical but because of the overhead for I2C communications the SPI version will run a little faster. With a slow device like the LCD the I2C method shouldn't experience any slowdown.

Many thanks.

Re: 3C : LCD I2C

Posted: Sun Jan 30, 2011 12:39 pm
by Dan81
How to use I2C LCD.

INTRODUCTION

I2C bus is very interesting cause it needs only 2 lines of the micro-controller.
You can find lots of components (RTC, thermometer, Led dimmer, …).

The bus frequency is 100kHz, writing a register will take about 300us.
It could be a bit slow for some components, but for some others it is quick enough.

I was working with an RTC (DS1307) and needed to display the time.
Using a classic LCD will waste 6 (or 10) pins of my Pic and a real I2C LCD was expensive enough

Then I decided to use an I2C GPIO (MCP 23008) from Microchip.

For me, the code customization with version 4 of Flowcode is very interesting cause all the code stays with your Flowchart.

On top of that, I wanted to use this new component identical to Matrix_Multimedia (with simulation).

End of chat.


TECHNICAL

For hardware the only rule is to respect the schematic given above ( close to the one given by Matrix M in the LCD help)

For the Software,
Choose your LCD as usual (2x16 , 4x20,…), the macros are identical (and simulable).

The supplementary thing is to add a I2C component and to add the macro I2C "Init" BEFORE the LCD init.
Note : I2C is only "Hardware" , the software mode is not supported (it could be).

Note2 : It is not necessary to provide a port for connection, if you leave "unconnected", when you compile, you will get 2 warnings which tell you "some components are not connected" but everything will go well.



Remarks :
- I have done the same thing with a PCF8574A and a real I2C LCD (BATRON BTHQ21605AV-YETF-LED04-I2C from Farnell , a little detail : the char set is not standard)
- You can do the same thing with the keyboard.

Daniel

PS : thanks for the feedback

Re: 3C : LCD I2C

Posted: Fri Feb 04, 2011 5:45 pm
by ncc1502
Has anybody done the same work for the LCD on an SPI port expander?

Re: 3C : LCD I2C

Posted: Fri May 03, 2013 3:27 pm
by Dan81
Hello Bercioiu

The same flowchart as above but with a PCF8574A.

Daniel

Re: 3C : LCD I2C

Posted: Fri May 03, 2013 7:56 pm
by bercioiu
Thank you for the reply!
In the custom component I see a new macro "OUT7" how can I use that? It is for P7 on the pcf? If yes, how can I use that in the flowchart? And one more question: I see that PCF is a little different from MCP , in the PCF I didn`t see the reset pin, so, what modification have to make to your schematic if I want to use PCF instead MCP?
Thank you again!

Re: 3C : LCD I2C

Posted: Sun May 05, 2013 10:46 am
by Dan81
Hello Bercioiu

It is (quite) the same schematic.
Image3.jpg
Image3.jpg (18.61 KiB) Viewed 43627 times
The macro "OUT7" was a project , it is empty (sorry).

Daniel

Re: 3C : LCD I2C

Posted: Mon May 13, 2013 11:39 am
by bercioiu
Hi DAN!
First, thanks for your help so far!
I cant compile your file with LCD for PCF 8574 (LCD-I2C-PCF8574a-1.fcf), when I compile it return me the following errors:

Code: Select all

LCD-I2C-PCF8574a-1.c(145): Illegal symbol name: %
LCD-I2C-PCF8574a-1.c(146): Illegal symbol name: %
LCD-I2C-PCF8574a-1.c(147): Illegal symbol name: %
LCD-I2C-PCF8574a-1.c(148): Illegal symbol name: %
LCD-I2C-PCF8574a-1.c(149): Illegal symbol name: %
LCD-I2C-PCF8574a-1.c(150): Illegal symbol name: %
LCD-I2C-PCF8574a-1.c(151): Illegal symbol name: %
LCD-I2C-PCF8574a-1.c(152): Illegal symbol name: %
LCD-I2C-PCF8574a-1.c(153): Illegal symbol name: %
LCD-I2C-PCF8574a-1.c(154): Illegal symbol name: %
LCD-I2C-PCF8574a-1.c(155): Illegal symbol name: %
LCD-I2C-PCF8574a-1.c(156): Illegal symbol name: %
LCD-I2C-PCF8574a-1.c(157): Illegal symbol name: %
LCD-I2C-PCF8574a-1.c(158): Illegal symbol name: %
LCD-I2C-PCF8574a-1.c(159): Illegal symbol name: %
LCD-I2C-PCF8574a-1.c(160): Illegal symbol name: %
LCD-I2C-PCF8574a-1.c(161): Illegal symbol name: %
LCD-I2C-PCF8574a-1.c(162): Illegal symbol name: %
LCD-I2C-PCF8574a-1.c(163): Illegal symbol name: %
LCD-I2C-PCF8574a-1.c(164): Illegal symbol name: %
LCD-I2C-PCF8574a-1.c(168): Illegal symbol name: %
LCD-I2C-PCF8574a-1.c(169): Illegal symbol name: %
LCD-I2C-PCF8574a-1.c(177): Illegal symbol name: %
LCD-I2C-PCF8574a-1.c(224): Illegal symbol name: 3
LCD-I2C-PCF8574a-1.c(225): Illegal symbol name: 3
LCD-I2C-PCF8574a-1.c(226): Illegal symbol name: 3
LCD-I2C-PCF8574a-1.c(227): Illegal symbol name: 3
LCD-I2C-PCF8574a-1.c(228): Illegal symbol name: 3
LCD-I2C-PCF8574a-1.c(229): Illegal symbol name: 3
LCD-I2C-PCF8574a-1.c(230): Illegal symbol name: 3
LCD-I2C-PCF8574a-1.c(231): Illegal symbol name: 3
LCD-I2C-PCF8574a-1.c(233): Illegal symbol name: 3
LCD-I2C-PCF8574a-1.c(234): Illegal symbol name: 3
LCD-I2C-PCF8574a-1.c(235): Illegal symbol name: 3
LCD-I2C-PCF8574a-1.c(236): Illegal symbol name: 3
LCD-I2C-PCF8574a-1.c(237): Illegal symbol name: 3

36 errors detected
Error: preprocessing error

failure
What can I do to compile it?
Thanks!

L.E. I forgot to mention that I use Flowcode 5 with all updates (5.5.2.1).

Re: 3C : LCD I2C

Posted: Mon May 13, 2013 7:25 pm
by Dan81
Hello Bercioiu

This custom code is for Flowcode 4.

Daniel

Re: 3C : LCD I2C

Posted: Mon May 13, 2013 7:38 pm
by bercioiu
There is a way to modify this custom code for Flowcode V5 ? What is the different between V4 and V5?
Thank you anyway!

Re: 3C : LCD I2C

Posted: Sat Sep 07, 2013 7:06 pm
by Mouine
Hello Dan81,

I try to complie the code with flowcode V5 but it not work, do you have one for it ?
I try it with flowcode V4 and i it work perfectly.

Thanks

Re: 3C : LCD I2C

Posted: Wed Mar 12, 2014 1:50 am
by MilekNS
Dan81 wrote:Hello Bercioiu

The same flowchart as above but with a PCF8574A.

Daniel

Hello Dan. I'm trying to control i2c LCD with PCF8574 but on Atmel AVR (atmega168) MCU.
I managed to open LCD-I2C-PCF8574a.fcf in Flowcode AVR 5.3 to see basic commands. I realized the main substance of "code" but there is one thing that I don't understand at all.
Physical Connection of LCD ?! That LCD (your is 20x4 and mine is 16x2, anyway standard) should be connected to I2C pins of MCU, ( in my case those are 27-SDA and 28-SCL), Vcc and GND, 4 wire total, and as far I understand those should be the only 4 pins used for LCD. I have 4 pin IDC connector for i2c with those 4.
But when I opened LCD-I2C-PCF8574a.fcf under LCD connections I saw that almost entire PORT B is used ?!
From PB0-PB3 for data bits of lcd and PB4-RS and PB5-EN.
During Simulation I see on "view chip" that states of those pins are being changed from LOW to HI, randomly.
Question is What to do with those ?? I need those pins of PORT B for something else, those are my "inputs on plc board" and I can't allow their state to change without any signal on real inputs, I need those pins completely free from lcd controll .
If I "remove" those connection of LCD to Port B in Flowcode I get warnings and error during compile? :|
I have not made ​​any real hardware for LCD yet, until i get anything logical in simulation , main MCU board is finished and tested for everything else except I2C communication to others "slaves"
// sorry bcs my probably bad english

Re: 3C : LCD I2C

Posted: Thu Mar 13, 2014 9:16 am
by Dan81
Hello Milek

Customisation was made for Flowcode v4 (different with Flowcode v5).
Connections to portB are not really made (it is a I2C bus) .
You can move connections to "unconnected" and the compilation will be OK with Flowcode4.

If you can manage a LCD with C code, it is enough easy to manage it through a PCF (but a bit long !) .

Moving the code to Flowcode5 is not useful because Flowcode6 is the current version.

Sorry

Daniel

Re: 3C : LCD I2C

Posted: Thu Mar 13, 2014 4:41 pm
by MilekNS
Hi Dan.

So does it mean that if I open FC, chose my MCU target (mega168) and make exactly same Flowcode diagram like yours, completely from scratch but in FC V5.3 it will not work because such a diagram is intended for V4 and same one goes bad in v5? I did that already and simulation works ok, LCD writes all those stuff from diagram, numbers, letters, characters, it compiles to C (with warning about LCD unconnected ) but not in .hex
I don't understand? Is it not the same in recent versions, that for example some block like "calculation", or "decision" are different in V4 and V5? Problem for me is that I don't understand #C, that's why I'm using FC ( also pretty hard to get around with it ) to program something "simple" by drawing diagrams.

Is there any other simple solution how to make my i2c LCD to work in V5, but w/o moving to V6 ? :roll:
If there is a new version of some SW (like in this case FC-V6) than the previous one should not just get obsolete easy like that? Ok, I know, it's "easy" to work in FC for some simple task, but when there is a problem like "how to control i2c LCD" there is no any specific tutorial about that, help file is unusable for that. There no any webpage here, or tutorial where I can simply see do this, this and this and it will work? thanks and sorry to bothering you.

Re: 3C : LCD I2C

Posted: Thu Mar 13, 2014 5:38 pm
by Benj
Hello,

If you look in the I2C component help file for v5 then there is information about how to use the I2C bus and how to read / write data.

There should also be a page on Wikipedia regarding I2C which should provide some insight on the protocol.

I2C is a fairly simple protocol so once you get the basics it should be possible to talk to just about any I2C device using the same principals.

I hope you can appreciate that we cannot write specific tutorials for all of the millions of different devices out there. If you want to document how you get on then this would be great and would potentially help out other users in a similar situation.

Re: 3C : LCD I2C

Posted: Sat Mar 15, 2014 9:12 pm
by MilekNS
hello Benj

I2C component help file was first thing to look. But...for someone who works as anesthesiologist in hospital it doesn't help me a lot... :D electronics is something that interests me a side, and i don't have that much knowledge. For me it was a great success even to make PCB! :lol: I have build some mcu projects before but only those where I found finished .hex and I was interested to learn how to program something that I could use around my house, in garage, just anything, C was the problem, nooo way I could learn that easy, but making something by "drawing diagram" sounds as great solution!
I understand that i2c use two wires for communication, an that's practically all.
"
Sending Data
Output a start condition //Starts the device listening to the I²C bus.
Transmit the External Device address with the LSB cleared. //Enables the device and sets to write mode.
Transmit the Internal address. //Sets the address to start writing data to.
Transmit a byte of data. //Device will acknowledge and increment internal address until page limit is reached
....
Transmit a byte of data. //Device will acknowledge and increment internal address until page limit is reached
Output a stop condition //Stops the device listening to the I²C bus.
Alternatively use the Send_Byte_Transaction macro.


This part of help file doesn't tell me anything, i see it's "example" for some memory chip but any way i don't know what to do with that, what blocks in diagram i have to use, where to put those and how to set all features.

I made one diagram based on Dan81 example.
Result: Simulation-ok , LCD ( in simulation ) show what i wanted to see, simple word "text" and then characters behind. Compile to C-OK, compile to .hex-OK Problem: as in my first comment i saw that states of pins on POrtB are being changed (view chip) , Dan said "Connections to portB are not really made" but i just sent hex to mcu and because i have some LED's attached to PortB i see they are blinking, ( I didn't made i2c board with that 8574 chip until i get something that could work ) so connections to portB are really made. If disconnect LCD from portB (in flowcode), simulation still work but with warning about unconnected device, compile to C-ok, compile to .hex doesn't work.
I'm really desperate about this. I understand it should be probably easy but for someone who understands the issues and I'm not in this story. :roll:

I wanted to attach that diagram files but it's on my home pc but i saved some *screen shoots* on my flash drive,
These days I'm on duty in hospital so I will not be able to deal with fc until I get back to home town.
sorry because long text, sorry because probably "tips&tricks" is wrong places to write all this. :roll:

Re: 3C : LCD I2C

Posted: Mon Mar 24, 2014 7:07 pm
by MilekNS
Still nothing. :cry:

Should I open new thread?

Re: 3C : LCD I2C

Posted: Wed Apr 16, 2014 9:36 am
by Benj
Hello Mike,

Sorry for the delay, could you attach your program so we can have a look at the compilation errors? What version of Flowcode are you using?

Re: 3C : LCD I2C

Posted: Mon Apr 21, 2014 10:34 am
by Dan81
Hello Milek

I've modified the flowchart for AVR and Flowcode5.
It seems to be OK in simulation , but I can't test it in real .

You will have to modify the chip configuration and quartz frequency.

Daniel

Re: 3C : LCD I2C

Posted: Tue Jul 22, 2014 6:46 pm
by MilekNS
hello Dan81.

It was some time ago since I visited this forum (and used FC at all) last time and i was happy to see the answer :)

I have tried simulation and build hex, both works now, on pc and hex is generated, but my problem also is hardware check, the wiring of my pcb it's not same as matrix multimedia lcd and little schematic you have posted earlier in this thread.

address 0x20=Ok, connections for data bus d4-d7 lines=OK, RS pin of lcd=OK, but my RW is connected to p5 and EN of lcd to p6, backlight to P7 (npn transistor)

i just need information where in custom code to find that part where i can change order of connection between PCF and LCD because my pcf8574 is smd chip and i have no any other way to make changes except in code. cutting my pcb traces and soldering wires arround doesn't look as option.

chip configuration and quartz frequency , no problem ,they are already same :)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------

EDIT: TODAY i took my pcb and looked around , changes on board were minimal so I have decided to make them.
now connections are same,

PCF-LCD
-----------
PO--D4
P1 --D5
P2 --D6
P3 --D7
P4 --RS
P5 --En
backlight is ON because it's connected to Vcc and gnd.
a2,a1,a2 are all tied to GND so address is 0x20, everything ( I think) as it should be but something is not OK. on my LCD just after power up first row of 16 is filled like in picture attached (it's not my picture, i have just find it on internet because it's same issue as mine)

Re: 3C : LCD I2C

Posted: Sat Jul 26, 2014 10:24 am
by Dan81
Hello Milek

Have you put pull up resistors on clock and data lines ?

Which hardware are you using ?

Daniel

Re: 3C : LCD I2C

Posted: Sat Jul 26, 2014 11:29 am
by KevinH
Check the requirements of the contrast pin3.
For other LCD's I have used the wiring pin3 direct to the supply pins will often not work.

Place a 10k preset between +5 and GND and take the wiper to pin3. As you adjust the setting it should go from all pixel black to a blank display, and somewhere in between the characters 'may' burst into view.

Re: 3C : LCD I2C

Posted: Sun Jul 27, 2014 2:12 pm
by MilekNS
Dan81 wrote:Hello Milek

Have you put pull up resistors on clock and data lines ?

Which hardware are you using ?

Daniel
Yeap, there are pull-up on scl and sda but 3,9k, i hope it's fine bcs i don't have higher values at this moment but there are still pull-up's, maybe i could add to them one more in series to get 7k8 for both data lines?

I'm using my own design, a board with ATmega168 ( internal 8mhz). Everything else (mostly very simple stuff) i have tried on that board is working except i don't know how to use i2c :) Dan Your code work in simulation and it's ok 99% but connections is probably different than what I need. Also I was wondering is there any chance to "kill" pcf8574 by sending some wrong commands during all these tests ?!but anyway I did make those changes for RW and En pins of LCD but it didn't worked...

I was also looking for some finished hex code for atmega 168 (or atmega8) just to burn it to mcu and check is my pcf8574 board is ok at all and i have found this http://mmdolze.users.sourceforge.net/us ... h-twi.html it has same wiring except back light where mine is npn transistor and not pnp BUT there is no hex included and i can't get it no chance. :oops:
KevinH wrote:Check the requirements of the contrast pin3.
For other LCD's I have used the wiring pin3 direct to the supply pins will often not work.

Place a 10k preset between +5 and GND and take the wiper to pin3. As you adjust the setting it should go from all pixel black to a blank display, and somewhere in between the characters 'may' burst into view.
I thought of it so that part is 100% ok, i have some other board with tiny2313 programmed just to scroll text around on LCD (standard 4b parallel connection) and contrast on pin3 is adjusted to be ok. Then I switch my lcd to PCB With 8574 and get those square like from picture above but they are visible because i set same value of POT on both boards.

Re: 3C : LCD I2C

Posted: Sun Jul 27, 2014 6:50 pm
by KevinH
First I'm very new to Flowcode so am using this as part of my learning how programs are constructed, so I'm of little help here! BUT, I now recall having a similar problem with an LCD many years ago (Using STE bus and Arcom Basic) which I eventually located as the LCD's power up/ reset time. The issue was the LCD was taking greater than 1 second to initialise, so was ignoring my my set-up codes during this time.

Try an initial delay of say 2 seconds and see if this helps, if it does gradually reduce it until it faults and choose a reliable delay greater than this.

The other delay that others have reported as an issue is the pulse on the 'E' line which seems to require some 10mS, however I can't recall having this issue, but did 'play' with many delay values to get things right.

The simulation would not find this type of issue, so there is hope.....

Re: 3C : LCD I2C

Posted: Mon Jul 28, 2014 10:24 am
by MilekNS
Dan81, I was just looking your last FC diagram and under LCD component/ custom code / component macros

Defines, RawSend (there is one more RawSend below ?), Start, Clear, Enable_pulse and Backlight are true (customized) and further under:

Start /Edit code I see there are lines of Wdt_delay_ms() ?

As i remember My WDT fuse bit is not ON :roll: i need WDT turned on to get this (maybe) working, right ?
I would try that right now but my isp programmer is at my home, not close, so i just asking at least to know is that possible issue?