16x2 LCD

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
User avatar
hamurai
Posts: 2
Joined: Mon Dec 10, 2018 1:36 am

16x2 LCD

Post by hamurai » Mon Dec 10, 2018 2:47 am

Howdy everyone! I just scooped up an ESP32S (my first ever board) along with a 16x2 LCD (https://www.amazon.com/gp/product/B0711 ... UTF8&psc=1) and was looking for a good place to start. My background is in software development but electronics is a fairly new hobby. For writing to the display should I be looking for a class such as https://github.com/wjdp/micropython-lcd or is there a simple way to write directly using I2C?

I've been looking at the I2C class docs and am able to scan addresses and receive 39 back (21 to SDA, 22 to SLC), but I'm not sure what to do with it. If I attempt to `writeto` it I receive the acks but the display immediately shuts off. Any newbie help is appreciated as everything I've found is either for the 8266 or a different version of the ESP32 and I'm not sure how the pins correlate to my NodeMCU ESP32S.

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

Re: 16x2 LCD

Post by shaoziyang » Mon Dec 10, 2018 7:35 am

You may try I2C LCD1602 drive below:

https://github.com/micropython-Chinese- ... 2C_LCD1602

User avatar
hamurai
Posts: 2
Joined: Mon Dec 10, 2018 1:36 am

Re: 16x2 LCD

Post by hamurai » Tue Dec 11, 2018 12:00 am

[quote=shaoziyang post_id=32524 time=1544427339 user_id=1625]
You may try I2C LCD1602 drive below:

https://github.com/micropython-Chinese- ... 2C_LCD1602
[/quote]

Thanks! That class worked beautifully. As for the display not working, TIL what a potentiometer is ;)

iz2rpn
Posts: 7
Joined: Thu Feb 20, 2020 9:35 pm

Re: 16x2 LCD

Post by iz2rpn » Thu Feb 20, 2020 9:39 pm

hamurai wrote:
Tue Dec 11, 2018 12:00 am
shaoziyang wrote:
Mon Dec 10, 2018 7:35 am
You may try I2C LCD1602 drive below:

https://github.com/micropython-Chinese- ... 2C_LCD1602
Thanks! That class worked beautifully. As for the display not working, TIL what a potentiometer is ;)
I have tried it too but it gives me this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: function takes 2 positional arguments but 1 were given

How can I solve it?

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

Re: 16x2 LCD

Post by shaoziyang » Fri Feb 21, 2020 2:07 am

How do you use it?

iz2rpn
Posts: 7
Joined: Thu Feb 20, 2020 9:35 pm

Re: 16x2 LCD

Post by iz2rpn » Fri Feb 21, 2020 5:04 am

shaoziyang wrote:
Fri Feb 21, 2020 2:07 am
How do you use it?
i2c 22 scl and 21 sda. i have an esp32 devkit v1

Code: Select all

import mp_i2c_lcd1602 #this works

l=mp_i2c_lcd1602.LCD1602() #this gives me the error I was telling you about
l.puts('Hello!')
Last edited by iz2rpn on Fri Feb 21, 2020 5:08 am, edited 1 time in total.

User avatar
jimmo
Posts: 1938
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: 16x2 LCD

Post by jimmo » Fri Feb 21, 2020 5:08 am

It looks like the example code is wrong. Should be:

Code: Select all

import mp_i2c_lcd1602
import machine

i2c = machine.I2C(scl=22,sda=21)

l=mp_i2c_lcd1602.LCD1620(i2c)
l.puts('Hello!')

iz2rpn
Posts: 7
Joined: Thu Feb 20, 2020 9:35 pm

Re: 16x2 LCD

Post by iz2rpn » Fri Feb 21, 2020 5:18 am

jimmo wrote:
Fri Feb 21, 2020 5:08 am
It looks like the example code is wrong. Should be:

Code: Select all

import mp_i2c_lcd1602
import machine

i2c = machine.I2C(scl=22,sda=21)

l=mp_i2c_lcd1602.LCD1620(i2c)
l.puts('Hello!')

Code: Select all

import mp_i2c_lcd1602
from machine import I2C, Pin

i2c = machine.I2C(scl=Pin(22), sda=Pin(21))

l=mp_i2c_lcd1602.LCD1620(i2c) 
#Traceback (most recent call last):
 #File "<stdin>", line 1, in <module>
 #AttributeError: 'module' object has no attribute 'LCD1620'

l=mp_i2c_lcd1602.LCD1602(i2c)
#Traceback (most recent call last):
  #File "<stdin>", line 1, in <module>
  #File "mp_i2c_lcd1602.py", line 13, in __init__
  #File "mp_i2c_lcd1602.py", line 40, in setcmd
  #File "mp_i2c_lcd1602.py", line 34, in send
  #File "mp_i2c_lcd1602.py", line 27, in setReg
  #OSError: [Errno 19] ENODEV

User avatar
jimmo
Posts: 1938
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: 16x2 LCD

Post by jimmo » Fri Feb 21, 2020 6:28 am

Looks like another typo in the example code -- as you've realised it should be LCD1602

The ENODEV means that it couldn't communicate over I2C. Can you try adding a scan after constructing the I2C instance, e.g.

Code: Select all

i2c = machine.I2C(scl=Pin(22), sda=Pin(21))
print(i2c.scan())
If it gives you back an address, then modify the LCD_I2C_ADDR in mp_i2c_lcd1602.py

If not, then check things like power and pull-up resistors.

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

Re: 16x2 LCD

Post by shaoziyang » Fri Feb 21, 2020 8:11 am

I have modify the LCD1602 drive, add autoaddress() function add print() function.

Image

https://github.com/micropython-Chinese- ... 2C_LCD1602

Code: Select all

from machine import I2C, Pin
from mp_i2c_lcd1602 import LCD1602
from time import sleep_ms

i2c = I2C(1, sda=Pin(9), scl=Pin(10))

LCD = LCD1602(i2c)

LCD.puts("I2C LCD1602")

Post Reply