STM32: Interfacing 16x2 LCD with I2C "backpack" board - Page 1
Forum section: electronics / general

author: dtodorov
author_rank: Contributor
timestamp: April 22, 2020, 09:21:56 am
content: Hi all,recently I started-off a project with STM32F100 that needs to interface an LCD module (HD44780-like) via an I2C adapter board. The LCD+I2C is fairly common and cheaply bought from aliexpress..So it goes like this:1) The I2C board interfaces the HD44780 LCD controller in 4-byte mode2) I followed the instructions on how to initialize the LCD and initially for Single-line mode it was working fine, text was clearly visible and all commands I issued were functional (enabling cursors, setting position, etc).3) However, when I enabled the 2-Line mode the character brightness drops, but text is still visible. Also, writing text on the second line is functional now.4) The I2C board has a pot for screwing around with the Vo contrast adjustment, but it seems that the display is at it's best contrast when Vo=0V. Turning the pot towards increasing Vo only makes it dimmer.So I am a bit confused and honestly I don't have a spare LCD to test the setup on. Hence, any suggestions and opinions are very welcomeP.S I am still setting up a github repo to publish the code and schematics.Thanks,Dimitar

author: greenpossum
author_rank: Frequent Contributor
timestamp: April 22, 2020, 09:52:27 am
content: There should be lots of libraries for driving the 1602 you can use. If you are not sure if you are doing it right with STM32 and you have an Arduino handy, there is a 1602 library you can use to testAs far as I know the pot is only to adjust the contrast of the characters against the background. It shouldn't interact with the software. When you find the right point leave it there. Also the backlight draws a fair bit of current so make sure it's well supplied.

author: dtodorov
author_rank: Contributor
timestamp: April 22, 2020, 11:20:44 am
content: Quote from: greenpossum on April 22, 2020, 09:52:27 amThat's a good suggestion actually, thanks! What is a nowadays a lab without 1kOhm, 1nF an arduionos laying around - will give it a go later today.Quote from: greenpossum on April 22, 2020, 09:52:27 amSo the thing is I thought the same. The pot I leave untouched in both 1Line and 2Lines mode. Even when stepping through the code I could see that the instruction enabling the 2Line mode causes it to dim. As for the supply -> it uses the 5V USB supply. On first looks it appears to be sufficient, but I will give it some extra chooch form a separate source just to make sure.

author: dtodorov
author_rank: Contributor
timestamp: April 22, 2020, 05:04:37 pm
content: Solved it.I tried running the display with an arduino mini clone board and used thisthis library. When flashing the arduino though, I noticed that 5V supply is used and the code initialized the display quite correctly.The STM32 is powered by 3.3V and I had the same 3.3V supply rail wrongly connected to LCD and PCF backpack modules. The PCF8574 expander IC can operate between c.a 2.5V and 6V, which is ok for 3.3V I2C communication, but the LCD module itself (HD44870) needs 5V to operate properly. I guess the 1-Line mode is working just marginally with Vo=0V.Luckily, the STM32's IOs are 5V tolerant so it's ok to supply the LCD and PCF modules with 5V directly from USB and now it appears to be working fine.

author: jackthomson43
author_rank: Contributor
timestamp: April 23, 2020, 02:20:50 am
content: STM32is way too difficult to use and i never got this 3.3V logic. It's better to use Arduino, you will find ready made examples for I2C LCD.

author: newbrain
author_rank: Super Contributor
timestamp: April 23, 2020, 08:12:39 am
content: Quote from: jackthomson43 on April 23, 2020, 02:20:50 amA bike without training wheels is too difficult to use and I never got this brakes thing.This seems more a statement on one's commitment, rather than on the platform.The 3.3V part does not make any sense to me - there's nothing to get, just make sure to use the right voltage, and, as the OP discovered (kudos for solving your problem!), most STM32 I/Os are 5V tolerant.Is STM32 (or any non-Arduino platform) more difficult to use?Quite definitely:It takes more reading: reference manuals, datasheets.It takes more understanding of how the MCU and peripherals work.It usually means you have to know C or C++ better (there are some alternatives).You might need (the horror!) to write your own libraries.You often use more complex (and powerful) tools, either as IDE or on the command lineAnd so and so forth...As for the bike, once you start without training wheels, get the hang of braking with brakes instead of your feet, and understand how to operate the gear shifter, you'll have much more freedom and fun in what you do, and even be able to select the right bike for the right task.Disclaimer:Personally, I never used Arduino, I think it's a good introductory platform but I don't like 95% of the code I see floating around.I am a grumpy old fart, I started with MPUs in the late 70's...my training wheels had been off for a long time when Arduino appeared.

author: dtodorov
author_rank: Contributor
timestamp: April 23, 2020, 09:27:11 am
content: Actually, I want to stay away from the STM32/Arduoino dogmatic discussion.My one-liner opinion is that "debugging with printf() is a punishment".But just a small follow-up on the 3.3V/5V topic:It appears the HD44780 is a legacy de-facto standard driver 5V chip for LCDs and yet has not evolved adequately to modern day. At least commercially, it seems it's the major player for alphanumeric LCDs.So looking at thedatasheetthe HD44780 can actually work on 3.3V itself and drive the LCD, however, to get the contrast right you need to have the Vo <= Vcc - 5V. That basically means setting it negative vs ground for 3.3V Vcc.To overcome this issue and make the module 3.3V compatible, you could add a voltage inverter charge pump IC (like the TC7660 + 2 caps) and most of the LCD modules have footprints to easily do so. I found a good articlehere.The shameful part is that I decided to bodge my LCD module, but only had a charge pump in DIP package. But eager was the cat, I ended up with this abomination:The complete system now works just fine on 3.3V supply!A quick takeaway is that there are LCD modules for sale that come with already populated parts that enable 3.3V operation.So when buying such modules you need to pay a bit more attention to this detail.

author: Till Matte
author_rank: Contributor
timestamp: April 23, 2020, 01:05:19 pm
content: The common 16x2 lcd module has logic voltage in 3.3V and 5V, before using, you have to check the1602 lcddatasheet for checking the LCD logic voltage if it is 3.3V or 5V input? they are different, the lcd input voltage have to be matched.

author: dtodorov
author_rank: Contributor
timestamp: April 26, 2020, 10:28:25 am
content: For those interested the code is uploaded to githubhere.

author: jackthomson43
author_rank: Contributor
timestamp: May 01, 2020, 12:41:23 pm
content: Thanks for the code, I will try interfacing16x2 LCDwith STM32 using this github code.

author: dtodorov
author_rank: Contributor
timestamp: May 01, 2020, 05:20:38 pm
content: You're welcome!BTW, there's still quite some things under development, but it should be enough to get you going. I plan to have it finished by this weekend and also upload schematics of the setup I am running.You can always let me know if you see troubles along the way.