NodeMCU Projects: Difference between revisions
Content added Content deleted
Line 372: | Line 372: | ||
= I2C LCD = |
= I2C LCD = |
||
https://forum.micropython.org/viewtopic.php?f=16&t=2858 |
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] |
||
https://forum.micropython.org/viewtopic.php?f=16&t=2858&start=30 |
|||
*Download the below library files from below link & upload them to NodeMCU: |
|||
https://github.com/dhylands/python_lcd/tree/master/lcd |
https://github.com/dhylands/python_lcd/tree/master/lcd |
||
esp8266_i2c_lcd.py |
- esp8266_i2c_lcd.py |
||
lcd_api.py |
- lcd_api.py |
||
*Connect the NodeMCU to I2C LCD-1602 as below: |
|||
D1 SCL ------------ SCL |
D1 SCL ------------ SCL |
||
D2 SDA ------------ SDA |
D2 SDA ------------ SDA |
||
Line 385: | Line 386: | ||
There are |
*There are many versions of this device - the difference is the controller IC. |
||
If you have the PCF8574T. the default I2C bus address is 0x27. |
*If you have the PCF8574T. the default I2C bus address is 0x27. |
||
If you have the PCF8574AT the default I2C bus address is 0x3F. |
*If you have the PCF8574AT the default I2C bus address is 0x3F(63). |
||
*Defining Address: |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
<syntaxhighlight lang="python"> |
<syntaxhighlight lang="python"> |
||
>>> from machine import I2C |
>>> from machine import I2C |
||
>>> i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000) |
>>> i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000) |
||
>>> print(i2c.scan()) |
|||
>>> print(i2c.scan()) |
>>> print(i2c.scan()) |
||
[63] |
[63] |
||
Line 403: | Line 403: | ||
</syntaxhighlight> |
</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 /> |
<br /> |