LCD 1602 - Library

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
User avatar
ernitron
Posts: 89
Joined: Fri Jun 03, 2016 5:53 pm
Location: The Netherlands

LCD 1602 - Library

Post by ernitron » Fri Jan 06, 2017 8:30 am

I made some research but I have found little about LCD 1602 and micropython.

I am looking for a simple library to pilot an LCD 1602 from WeMos D1 Mini (or other esp8266). Looking for simple API to send text on line 1 or 2, maybe adjust dim. Things like that.

Are any problem to drive from the 5V output of WeMos? Has it enough current or should it be powered separately?

Thanks in advance.

EDIT: I will use a LCD 1602 16x2 HD44780 with IIC/I2C Serial Interface Adapter Module
https://www.aliexpress.com/item/1602-16 ... Title=true

User avatar
ernitron
Posts: 89
Joined: Fri Jun 03, 2016 5:53 pm
Location: The Netherlands

Re: LCD 1602 - Library

Post by ernitron » Fri Jan 06, 2017 9:09 am

I have found this https://github.com/dhylands/python_lcd and looks pretty much what I was looking for.

Questions:
1. Did anybody make it working with WeMos D1 Mini?
2. Will it work in both i2c and GPIO modes?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: LCD 1602 - Library

Post by Roberthh » Fri Jan 06, 2017 9:20 am

The 5V Pin of the Wemos D1 is connected via a Diode to the 5V Bus of USB. I cannot read the sign of that diode on my device, but some datasheets say B5819, which is a 1 A Schottky diode. Since the ESP8266 consumes about 200 mA max, there are at least 300mA available for the display power, assuming 500 mA from USB. I recommend to add an an additional buffering capacitor at the 5V.

@dhylands has some stuff here: https://github.com/dhylands/python_lcd

User avatar
mcauser
Posts: 507
Joined: Mon Jun 15, 2015 8:03 am

Re: LCD 1602 - Library

Post by mcauser » Fri Jan 06, 2017 4:56 pm

@ernitron
1. Yes, using various HD44780s, 08x2, 16x1, 16x2, 16x4, 20x4, blue and yellow.
2. Yes, using both PCF8574 I2C backpacks and GPIO pins (4x data pins).

The 08x2 pin arrangement does not mate with the I2C backpacks as the pins are on 2 rows. You can still use the backpack, but you will need to use some wires instead.

Add these to your ESP8266 build's /modules:
https://github.com/dhylands/python_lcd/ ... lcd/lcd.py

for I2C backpack:
https://github.com/dhylands/python_lcd/ ... i2c_lcd.py
https://github.com/dhylands/python_lcd/ ... cd_test.py

for GPIO:
https://github.com/dhylands/python_lcd/ ... pio_lcd.py
https://github.com/dhylands/python_lcd/ ... cd_test.py

Connections:
WeMos D1 Mini -- PCF8574 I2C backpack
D1 SCL ------------ SCL
D2 SDA ----------- SDA
GND --------------- GND
5V ----------------- VCC

Power consumption:
My blue and green 16x2 LCDs: 21mA with backlight on, 5.4mA with backlight off.
My blue and green 20x4 LCDs: 36mA with backlight on, 5.5mA with backlight off.

Code: Select all

from time import sleep_ms, ticks_ms
from machine import I2C, Pin
from esp8266_i2c_lcd import I2cLcd

i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000)

lcd = I2cLcd(i2c, 0x27, 2, 16)
lcd.putstr("Hello ernitron\nIt's working!")
lcd.clear()
lcd.putstr("Using dhylands\npython_lcd")

lcd = I2cLcd(i2c, 0x27, 4, 20)
lcd.putstr("WeMos D1 Mini with  PCF8574 I2C backpackWorks with HD44780s:08x2 16x1 16x2 20x4")
lcd.clear()
lcd.putstr("line 1\nline 2\nline 3\nline 4")
Image
Image
http://imgur.com/a/h6UWJ

User avatar
ernitron
Posts: 89
Joined: Fri Jun 03, 2016 5:53 pm
Location: The Netherlands

Re: LCD 1602 - Library

Post by ernitron » Fri Jan 06, 2017 7:43 pm

mcauser wrote:@ernitron
1. Yes, using various HD44780s, 08x2, 16x1, 16x2, 16x4, 20x4, blue and yellow.
2. Yes, using both PCF8574 I2C backpacks and GPIO pins (4x data pins).
...
Hi @mcauser, what a reply! I am flattered!

I can't wait to assemble and test all this brilliant solution. Thanks... (just let me know where I should send the chocolate cake I will specially bake for you :-)

User avatar
Mike Teachman
Posts: 155
Joined: Mon Jun 13, 2016 3:19 pm
Location: Victoria, BC, Canada

Re: LCD 1602 - Library

Post by Mike Teachman » Sat Jan 07, 2017 6:12 am

Most Excellent ! Many thanks @dhylands, @mcauser, and @ernitron. :D I've wanted to get these displays working with esp/uP for some time now. I put a level shifter in the mix as it's likely the i2c lines are pulled to 5V on the LCD backpack which might put the ESP at risk. Not sure that is really needed or not.
Attachments
lcd1602-up.jpg
lcd1602-up.jpg (185.61 KiB) Viewed 47110 times

ZKDMun
Posts: 42
Joined: Thu Nov 24, 2016 2:34 pm
Location: Hamburg

Re: LCD 1602 - Library

Post by ZKDMun » Fri Jan 13, 2017 11:08 pm

How can I find out the right I2C address?

Because I am using the same wiring on my NodeMCU
VIN -> VCC
GND -> GND
D1 -> SCL
D2 -> SDA
and the same code from mcausers exampler, but nothing appeard on the LED...
On some websites I read that the I2C address "0x27" can be wrong, and I have to try another one...

but how can I find out which I2C address is the right one?

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: LCD 1602 - Library

Post by dhylands » Sat Jan 14, 2017 12:09 am

Normally, if you do a scan of the i2c bus it will return all of the detected devices.

Did you add pullups on the SDA and SCL lines? I2C requires them.

The PCF8574 I2C chip on the backpack has 3 address lines called A0, A1, A2. How those are wired up determines the lest significant 3 bits of the I2C address.

On my board, these address lines are pulled up to 5V via resistors on the boards, and there are solder pads that can use to connect them to ground instead.

ZKDMun
Posts: 42
Joined: Thu Nov 24, 2016 2:34 pm
Location: Hamburg

Re: LCD 1602 - Library

Post by ZKDMun » Sat Jan 14, 2017 10:02 am

On the backside of my LCD-Module there is a PCF8574T-Module... I thought this will do it?
Or are some resistors between the Module and the NodeMCU needed? How should I wire this? :/

ZKDMun
Posts: 42
Joined: Thu Nov 24, 2016 2:34 pm
Location: Hamburg

Re: LCD 1602 - Library

Post by ZKDMun » Sat Jan 14, 2017 2:39 pm

For the pull up:
is this wiring ok?
Image
(the lines to the bottom are the connections to the LCD... didnt fount the right module for fritzing)

I used 4.7k ohm resistors and 10k ohm resistors... but nothing worked?

Post Reply