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
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: LCD 1602 - Library

Post by Roberthh » Tue Jan 24, 2017 7:59 pm

Just since that effect caused me some minutes of head scratching: if the device ha a reset input - is that pulled high?

j0hnsmith
Posts: 1
Joined: Tue Nov 21, 2017 8:30 pm

Re: LCD 1602 - Library

Post by j0hnsmith » Tue Nov 21, 2017 9:11 pm

[quote=mcauser post_id=17129 time=1484406564 user_id=732]
Most PCF backpacks have a potentiometer for adjusting the display contrast. It may appear the display isn't working when the contrast is extreme.
[/quote]

Backlight was turning on/off but spent at least 2 hours messing around with addresses, pins etc etc, trying to get something to be displayed. I thought the potentiometer was for changing the address, working now, thanks.

keithostertag
Posts: 16
Joined: Sun Dec 17, 2017 3:46 pm

Re: LCD 1602 - Library

Post by keithostertag » Tue Feb 13, 2018 5:13 am

I'm trying something similar using a pyboard and the 1602 LCD and the PCF8574 I2C backpack, but can't get it properly wired. I'm using 2K pull up resistors, I haven't tried loading any software yet just trying to scan to make sure it is wired correctly. The LCD shows only a single row of blocks.

Here's what I get:

Code: Select all

>>> from machine import I2C, Pin
>>> lcd = I2C(scl=Pin('Y9'), sda=Pin('Y10'), freq=10000)
>>> lcd.scan()
[]
I have a different device on the other I2C bus and it is working:

Code: Select all

>>> i2c = I2C(scl=Pin('X9'), sda=Pin('X10'), freq=10000)
>>> i2c.scan()
[35]
I'm powering the LCD independently with a 5V source. I've also tried resistor values of 5K and 330ohms. AFAIK I've got the backpack soldered to the LCD correctly by looking around the Internet for photos. Adjusting the contrast shouldn't affect the scan, correct? Any ideas of what I should be checking? (I'm still new to this).

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

Re: LCD 1602 - Library

Post by mcauser » Tue Feb 13, 2018 5:33 am

I thought the PCF8574 I2C backpack already has onboard I2C pull-up resistors?
You should see the PCF8574 backpack show up in an i2c.scan() as 0x20 - 0x27 (configurable with A0,A1,A2 solder pads).

The contrast is independent of the i2c.scan(). It's just a potentiometer between VCC and the backlight LED.
If it's bright enough, you don't even need the backlight on. Some of the backpacks contain a jumper for the backlight LED.

Until you run the HD44780 display initialise commands, seeing a row of blocks isn't out of the ordinary.
eg. https://github.com/dhylands/python_lcd/ ... cd_test.py

It should show up on I2C scans without being initialised. Try removing your additional pull-ups and i2c.scan() again.

keithostertag
Posts: 16
Joined: Sun Dec 17, 2017 3:46 pm

Re: LCD 1602 - Library

Post by keithostertag » Tue Feb 13, 2018 5:38 pm

Thank you! That's a big help, but still no joy with or without pull up resistors.

Do I need to select an address, or am I correct that the default address of 0x27 needs no jumpers?

To make sure I am doing this correctly, here's what I've done:
I copied the contents of pyb_i2c_lcd_test.py to the pyboard's main.py file, and also copied lcd_api.py and pyb_i2c_lcd.py to the pyboard (I'm not using an sd card). Reset, and I see the pyboard's LED's flashing briefly, but no change in the LCD. I reset again then attempt to scan the bus but again (after connecting via the screen program since I'm using Linux from the command line) still get only an empty set.

Did I misunderstand... does running the pyb_i2c_lcd_test.py initialize the bus?

Also, how do I select an address? Mine are not jumpered on the backpack, just solder pads. I can't find a reference showing how to relate the A[0..2] addresses to the LCD pins, for instance.

Addendum: now I see an error:

Code: Select all

Running test_main
Traceback (most recent call last):
  File "main.py", line 48, in <module>
  File "main.py", line 16, in test_main
  File "pyb_i2c_lcd.py", line 24, in __init__
OSError: [Errno 5] EIO
MicroPython v1.9.3-240-ga275cb0f on 2018-01-11; PYBv1.1 with STM32F405RG
Type "help()" for more information.
>>> 
Line 24 in __init__ is

Code: Select all

self.i2c.send(0, self.i2c_addr)
, so it's an address problem? I've got the scl connected to pin Y9 and the sda connected to Y10 on the pyboard.
lcd_with_backpack.jpg
lcd_with_backpack.jpg (92.62 KiB) Viewed 12053 times

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 » Tue Feb 13, 2018 10:03 pm

Your frequency is probably too low. You're showing 10,000 when it should be 100,000.

The pyboard includes pullup resistors on Y9 and Y10.

The pyb_i2c_lcd_test.py assumes that the LCD on I2C bus 2, which is pins Y9 and Y10:
https://github.com/dhylands/python_lcd/ ... est.py#L15
Some earlier versions of this used bus 1, so make sure your file has a 2 there.

Make sure that you can see a single line of black squares when you power on the LCD (this should happen just by applying power - no I2C connection is required). If you can't, adjust the pot until you can, otherwise you won't see anything on the LCD even if it is working.

With no solder pads of the A0..A2 connected then the low 3 bits of the address will be 1's. Each pad you solder changes that pin to a zero.

0x27 = 0 0 1 0 0 1 1 1 or 0 0 1 0 0 A2 A1 A0

Be aware that i2c.scan reports addresses in decimal, so 0x27 = 39 decimal. The fact that you have a device 35 showing up would map to address 0x23 suggests that your A2 address pin is soldered or perhaps has a bad solder job on the pullup resistor for the A2 pin.

keithostertag
Posts: 16
Joined: Sun Dec 17, 2017 3:46 pm

Re: LCD 1602 - Library

Post by keithostertag » Wed Feb 14, 2018 12:21 am

Thanks Dave and mcauser!

So I finally discovered the problem.

I removed everything else from the setup (to prevent complications) and changed the frequency as you suggested and it still didn't work... but I was able to finally get a scan working... and the default address of this board is 0x3f! (No soldering issues)

Code: Select all

>>> from machine import Pin, I2C
>>> lcd = I2C(scl=Pin('Y9'), sda=Pin('Y10'), freq=100000)
>>> lcd.scan()
[63]
>>>
After changing the DEFAULT_I2C_ADDR to 0x3f in three files (main.py, pyb_i2c_lcd.py, and pyb_i2c_lcd_test.py) the code works as intended... yay!

I bought these LCD's and backpacks from China, so I guess sometimes addresses are different...

Thanks again Dave and mcauser and everyone else for this thread and your help! I would still be stuck if not for you guys, and there's still a lot to learn...

RajaRamesh
Posts: 51
Joined: Wed May 08, 2019 10:54 am

Re: LCD 1602 - Library

Post by RajaRamesh » Sun Jun 09, 2019 5:03 pm

mcauser wrote:
Fri Jan 06, 2017 4:56 pm

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")
Hi, i am trying to display some text on lcd screen with the help of above code. but i am getting below error. could you please let me know what was wrong?
lcd_error.jpg
lcd_error.jpg (46.6 KiB) Viewed 10155 times

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

Re: LCD 1602 - Library

Post by Roberthh » Sun Jun 09, 2019 6:03 pm

What do you get with

Code: Select all

from machine import I2C
i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000)
print(i2c.scan())

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

Re: LCD 1602 - Library

Post by mcauser » Sun Jun 09, 2019 8:05 pm

Did you add pull ups on the SDA and SCL lines? I2C requires them.
Pins D3 (GPIO0) and D4 (GPIO2) have onboard 10k pull ups for setting the boot mode.
If you don’t want to add extra hardware and don’t mind D4 led blinking, use the two pins for I2C instead of D1 (GPIO5) and D2 (GPIO4). I use D4 for clock so it blinks on activity.

Hang on... these backpacks come with onboard pull ups. You shouldn’t need to add additional ones or use D3/D4.
Last edited by mcauser on Sun Jun 09, 2019 8:18 pm, edited 1 time in total.

Post Reply