cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103 LCD20x4 i2C

paul sauv
Associate III
Posted on May 01, 2018 at 06:29

Good morning,

I'm beginner with STM but managed to get working a STM32F103 LCD16x2 using i2C

Now, I would like to use i2C but with 20x4 LCD, nothing fancy

I modified the library according to what I was thinking correct but I can't get it working properly.

I used this tutorial for the 16x2 lcd:

http://controllerstech.com/i2c-lcd-in-stm32/

 

because I use this i2C module: 

PCF8574

And the LCD screen 20x4:

https://www.aliexpress.com/item/2PCS-Lot-LCD-Board-2004-20-4-LCD-20X4-5V-Blue-Screen-LCD-2004A-Display-LCD/32637673263.html

 

I have weird characters wrote on the LCD but not at the good position and not what it's supposed to be displayed

The project is attached

Do you have any idea of what I did wrong ?

Thank you

#lcd-display #i2c #stm32f103
16 REPLIES 16
Posted on May 01, 2018 at 10:04

Observe, what's on the LCD pins, by a logic analyzer, and compare that to HD44780 datasheet.

JW

Posted on May 03, 2018 at 10:48

Unfortunately I don't know how to do that...

I changed the I2C address for 0x27 which seems to be the correct one when A1, A2 and A3 are low, but not working either

henry.dick
Senior II
Posted on May 03, 2018 at 13:03

Easy.

1. Read the LCD datasheet and see how it works. Sending data to four lines is just starting at different addresses.

2. Read the i2c expanders datasheet and schematic to see how to send the commands

3. Done.

Cannot be simpler than that.

paul sauv
Associate III
Posted on May 16, 2018 at 14:36

Good afternoon,

I made some progress:

Use slave address 0x27<<1 diplay the correct first row

But when i'm supposed to display to the following row, nothing.

Idon't understand because I use common display and I2C odule, this is strange.

Here is the whole project

https://drive.google.com/open?id=1gIY039_RFFDAfFDW0_sDU0ZDy4AEFY8E

 

Any help is appreciated

Thank you

Posted on May 16, 2018 at 14:50

not sure exactly, but

some displays will display the 21st character on the next line

and other displays need a CR to go the 2nd line.

its in the datasheet.

what page are you reading ?

send us the link to the data sheet.

Posted on May 16, 2018 at 14:52

Hi

I think this is the correct datasheet:

https://www.sparkfun.com/datasheets/LCD/HD44780.pdf

 
Posted on May 16, 2018 at 14:56

Figure 6 in the datasheet, shows the address of the first character on the second line is 40.

A CR will probably do it.

Posted on May 16, 2018 at 15:04

What is a CR?

Because I tried to write on line 2:

&sharpdefine LCD_START_LINE_2 0x40

void lcd_gotoxy(uint8_t x, uint8_t y)

{

&sharpif LCD_LINES == 1

lcd_send_cmd(LCD_SET_DDRAM_ADDRESS |

(LCD_START_LINE_1 + x));

&sharpelif LCD_LINES == 2

if (y == 0)

lcd_send_cmd(LCD_SET_DDRAM_ADDRESS |

(LCD_START_LINE_1 + x));

else

lcd_send_cmd(LCD_SET_DDRAM_ADDRESS |

(LCD_START_LINE_2 + x));

&sharpelif LCD_LINES == 4

if (y == 0)

lcd_send_cmd(LCD_SET_DDRAM_ADDRESS |

(LCD_START_LINE_1 + x));

else if (y == 1)

lcd_send_cmd(LCD_SET_DDRAM_ADDRESS |

(LCD_START_LINE_2 + x));

else if (y == 2)

lcd_send_cmd(LCD_SET_DDRAM_ADDRESS |

(LCD_START_LINE_3 + x));

else

lcd_send_cmd(LCD_SET_DDRAM_ADDRESS |

(LCD_START_LINE_4 + x));

&sharpendif

}

but not working:

lcd_gotoxy(0,0); //

lcd_send_string ('subscribe');

lcd_gotoxy(0,2);

lcd_send_string ('to this channel');

this print nothing

Posted on May 16, 2018 at 21:38

Just write characters consecutively, without using any 'goto', maybe with small delay between each character so you see how they appear up consecutively. They should start to show up in next lines - maybe not consecutively, most probably like 1-3-2-4. There may be a delay between the lines.

This should reveal you the 'structure'/adressing of the module itself. They can be built in several ways so there's no 'good recipe' unless you have datasheet for the particular make of the module (which I presume you don't have).

If you can display only on 2 lines using this method, you haven't properly initialized the module (i.e. you need to put it into the 1/16 duty mode).

JW