Page 1 of 6

LCD 1602 - Library

Posted: Fri Jan 06, 2017 8:30 am
by ernitron
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

Re: LCD 1602 - Library

Posted: Fri Jan 06, 2017 9:09 am
by ernitron
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?

Re: LCD 1602 - Library

Posted: Fri Jan 06, 2017 9:20 am
by Roberthh
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

Re: LCD 1602 - Library

Posted: Fri Jan 06, 2017 4:56 pm
by mcauser
@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

Re: LCD 1602 - Library

Posted: Fri Jan 06, 2017 7:43 pm
by ernitron
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 :-)

Re: LCD 1602 - Library

Posted: Sat Jan 07, 2017 6:12 am
by Mike Teachman
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.

Re: LCD 1602 - Library

Posted: Fri Jan 13, 2017 11:08 pm
by ZKDMun
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?

Re: LCD 1602 - Library

Posted: Sat Jan 14, 2017 12:09 am
by dhylands
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.

Re: LCD 1602 - Library

Posted: Sat Jan 14, 2017 10:02 am
by ZKDMun
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? :/

Re: LCD 1602 - Library

Posted: Sat Jan 14, 2017 2:39 pm
by ZKDMun
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?