NodeMCU Projects: Difference between revisions
→I2C LCD
Line 372:
= I2C LCD =
Source: [https://forum.micropython.org/viewtopic.php?f=16&t=2858 forum.micropython.org] & [https://forum.micropython.org/viewtopic.php?f=16&t=2858&start=30 forum.micropython.org]
*Download the below library files from below link & upload them to NodeMCU:
https://github.com/dhylands/python_lcd/tree/master/lcd
- esp8266_i2c_lcd.py
- lcd_api.py
*Connect the NodeMCU to I2C LCD-1602 as below:
D1 SCL ------------ SCL
D2 SDA ------------ SDA
Line 385 ⟶ 386:
*There are
*If you have the PCF8574T. the default I2C bus address is 0x27.
*If you have the PCF8574AT the default I2C bus address is 0x3F(63).
*Defining Address:
An i2c.scan() should reveal which address to use▼
lcd=I2cLcd(i2c, 0x27, 2, 16)▼
lcd=I2cLcd(i2c, 39, 2, 16)▼
▲*An i2c.scan() should reveal which address to use:
▲lcd=I2cLcd(i2c, 0x27, 2, 16)
▲lcd=I2cLcd(i2c, 39, 2, 16)
<syntaxhighlight lang="python">
>>> from machine import I2C
>>> i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000)
>>> print(i2c.scan())
[63]
Line 403:
</syntaxhighlight>
*Print the output on the LCD:
<syntaxhighlight lang="python">
import time
from machine import I2C, Pin
from esp8266_i2c_lcd import I2cLcd
i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000)
lcd = I2cLcd(i2c, 63, 2, 16)
while True:
lcd.putstr("Hello Tester..\nIt's working!")
time.sleep(2)
lcd.clear()
lcd.putstr("Test 2\nMicropython_lcd")
time.sleep(2)
lcd.clear()
</syntaxhighlight>
<br />
|