Page 1 of 3

16x2 LCD

Posted: Mon Dec 10, 2018 2:47 am
by hamurai
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.

Re: 16x2 LCD

Posted: Mon Dec 10, 2018 7:35 am
by shaoziyang
You may try I2C LCD1602 drive below:

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

Re: 16x2 LCD

Posted: Tue Dec 11, 2018 12:00 am
by hamurai
[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 ;)

Re: 16x2 LCD

Posted: Thu Feb 20, 2020 9:39 pm
by iz2rpn
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?

Re: 16x2 LCD

Posted: Fri Feb 21, 2020 2:07 am
by shaoziyang
How do you use it?

Re: 16x2 LCD

Posted: Fri Feb 21, 2020 5:04 am
by iz2rpn
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!')

Re: 16x2 LCD

Posted: Fri Feb 21, 2020 5:08 am
by jimmo
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!')

Re: 16x2 LCD

Posted: Fri Feb 21, 2020 5:18 am
by iz2rpn
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

Re: 16x2 LCD

Posted: Fri Feb 21, 2020 6:28 am
by jimmo
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.

Re: 16x2 LCD

Posted: Fri Feb 21, 2020 8:11 am
by shaoziyang
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")