LCD 2X16 I2c on ESP32

Discuss development of drivers for external hardware and components, such as LCD screens, sensors, motor drivers, etc.
Target audience: Users and developers of drivers.
Post Reply
guyd
Posts: 81
Joined: Fri Jul 20, 2018 6:08 am

LCD 2X16 I2c on ESP32

Post by guyd » Sat Oct 06, 2018 7:23 am

Hi,
I wish to use such LCD on both ESP32 and ESP8266.
I've found dhylands github - https://github.com/dhylands/python_lcd.

but I need some help to install it on my device, since using instuction on README.MD file, didn't work for me.

Guy

shaoziyang
Posts: 363
Joined: Sun Apr 17, 2016 1:55 pm

Re: LCD 2X16 I2c on ESP32

Post by shaoziyang » Sat Oct 06, 2018 8:35 am


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

Re: LCD 2X16 I2c on ESP32

Post by mcauser » Mon Oct 08, 2018 3:06 am

I'm going to assume you are using a 1602 LCD with one of these I2C backpacks:
https://www.aliexpress.com/item/LCD1602 ... 14933.html

Git clone or download the repo: https://github.com/dhylands/python_lcd
Open the lcd folder.
You simply need to copy 2 of these files to your board.
You can use rshell, ampy, etc.

Depending on how many free IO pins you have, and whether you are using the PCF8574 I2C backpack or connecting directly to the LCD determines which files to copy across.

For ESP8266 -> PCF8574 backpack -> LCD, copy these files to your board:
* esp8266_i2c_lcd.py
* lcd_api.py

For ESP8266 -> LCD, copy these files to your board:
* nodemcu_gpio_lcd.py
* lcd_api.py

The ESP32 can use the same examples.
There is an ESP32 example, esp32_gpio_lcd.py, which is basically identical to nodemcu_gpio_lcd.py.

When connecting via GPIO, you have the option to use 4 or 8 data lines.

If you want to use an MCP23008 IO expander, have a look at pyb_i2c_adafruit_lcd.py

Once you have uploaded the drivers to your board, have a look at the associated _test.py files, which show you how to interact with them.

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

Re: LCD 2X16 I2c on ESP32

Post by mcauser » Mon Oct 08, 2018 3:08 am

Also, have a read of this thread: viewtopic.php?f=14&t=1422

guyd
Posts: 81
Joined: Fri Jul 20, 2018 6:08 am

Re: LCD 2X16 I2c on ESP32

Post by guyd » Tue Oct 09, 2018 5:21 pm

mcauser wrote:
Mon Oct 08, 2018 3:06 am
I'm going to assume you are using a 1602 LCD with one of these I2C backpacks:
https://www.aliexpress.com/item/LCD1602 ... 14933.html

Git clone or download the repo: https://github.com/dhylands/python_lcd
Open the lcd folder.
You simply need to copy 2 of these files to your board.
You can use rshell, ampy, etc.

Depending on how many free IO pins you have, and whether you are using the PCF8574 I2C backpack or connecting directly to the LCD determines which files to copy across.

For ESP8266 -> PCF8574 backpack -> LCD, copy these files to your board:
* esp8266_i2c_lcd.py
* lcd_api.py

For ESP8266 -> LCD, copy these files to your board:
* nodemcu_gpio_lcd.py
* lcd_api.py

The ESP32 can use the same examples.
There is an ESP32 example, esp32_gpio_lcd.py, which is basically identical to nodemcu_gpio_lcd.py.

When connecting via GPIO, you have the option to use 4 or 8 data lines.

If you want to use an MCP23008 IO expander, have a look at pyb_i2c_adafruit_lcd.py

Once you have uploaded the drivers to your board, have a look at the associated _test.py files, which show you how to interact with them.
1) Yes this is exactly the item I use.
2) I'm using the exact lcd library as mentioned.
3) copied those files
4) what gpio's should be for i2c ?
5) what to do if lcd screen needs 5v and from ESP8266 I'm getting 3.3v ?
6) this is the one I use https://www.aliexpress.com/item/ESP8266 ... 66224.html

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

Re: LCD 2X16 I2c on ESP32

Post by mcauser » Tue Oct 09, 2018 11:18 pm

Normally people use pins D1 and D2 for I2C.
D1 GPIO5 for SCL
D2 GPIO4 for SDA

There’s a problem though. I2C requires pull up resistors on the SCL+SDA pins. You’ll need some external 10k resistors connecting both to 3V3. “Pulling them up” instead of leaving them floating.

There is a trick you can use. Most ESP8266 boards have onboard 10k pull up resistors, on the D3+D4 pins, for setting the correct boot mode. You can use these for I2C if you can live with the onboard led (on D4) flickering.

https://wiki.wemos.cc/products:d1:d1_mini

D3 GPIO0 SCL
D4 GPIO2 SDA

The LCD does require 5V Vcc, so power it from your 5V pin. The SCL and SDA pins are 5V tolerant.
If you are adding your own external pull ups, I’d connect them to 3V3, just to be paranoid.

You can get 3V LCDs, but they usually cost more and are harder to find. You should be fine with a 5V LCD.

guyd
Posts: 81
Joined: Fri Jul 20, 2018 6:08 am

Re: LCD 2X16 I2c on ESP32

Post by guyd » Wed Oct 10, 2018 7:41 am

Hi,
thank you for your answer.
lets leave the 5v issue for later.

1) can I decide that D3, D4 will be i2c ? I thought it is a dedicated hardware ( as I know In RPI boards ).
2) my motivation to use ESP8266 is to be much simpler and reliable than RPI zero -over there I have my system working properly, but it seems ( adding the voltage issue ), let fit. Am I correct ?

Post Reply