WEMOS D1 mini ==> I2C LCD control with ESP8266BASIC instruct
Posted: Sat Jan 30, 2021 3:30 pm
"Hello World" was displayed on the LCD (16x2) with ESP8266BASIC instructions. The output is made via I2C communication.
The task consists of two parts:
1. Initialize HD44780 (4-bit data transfer!)
2. Display the characters in two steps. First the top 4 bits, then the bottom 4 bits. All dumps are closed by the i2c.write (0) statement.
Please help:
How can the value of a variable be written to the LCD display?
Regards: mezjoc
'/I2C LCD Init 4-bit_1.bas/2021.01.30.
wifi.connect
memclear
cls
let address = 39 'PCF8574 I2C Address
i2c.setup(4,5) 'choose your I2C bus pins
'P7 P6 P5 P4 P3 P2 P1 P0 --- PCF8574
' | | | | | | | |
'D7 D6 D5 D4 Blacl. EN R/W RS --- HD44780
'step1
delay 150
'step2
i2c.begin(address)
i2c.write(52) '0011 0100b=52
i2c.write(0)
delay 5
'step3
i2c.write(52) '0011 0100b=52
i2c.write(0)
delay 1
'step4
i2c.write(52) '0011 0100b=52
i2c.write(0)
delay 1
'step5
i2c.write(36) '0010 0100b=36
i2c.write(0)
delay 1
'step6
i2c.write(36) '0010 0100b=36
i2c.write(0)
i2c.write(132) '1000 0100b=132
i2c.write(0)
delay 1
'step7
i2c.write(4) '0000 0100b=4
i2c.write(0)
i2c.write(132) '1000 0100b=132
i2c.write(0)
delay 1
'step8
i2c.write(4) '0000 0100b=4
i2c.write(0)
i2c.write(20) '0001 0100b=20
i2c.write(0)
delay 5
'step9
i2c.write(4) '0000 0100b=4
i2c.write(0)
i2c.write(100) '0110 0100b=100
i2c.write(0)
'0 1 I/D S,0110=6D
'I/D=1-->Increment by 1
'S=0-->No shift
i2c.end()
delay 1
'step10
'Initialization ends
'step11
i2c.begin(address)
i2c.write(4) '0000 0100b=4
i2c.write(0)
i2c.write(196) '1100 0100b=196
i2c.write(0)
'1 1 C B
'C=0-->Cursor off
'B=0-->Blinking off
i2c.end()
delay 100
'Display:
'H e l l o space
'72D 101D 108D 108D 111D 32D
'0100 1000, 0110 0101, 0110 1100, 0110 1100, 0110 1111, 0010 0000
'P7 P6 P5 P4 P3 P2 P1 P0 --- PCF8574
' | | | | | | | |
'D7 D6 D5 D4 Blacl. EN R/W RS --- HD44780
i2c.begin(address)
i2c.write(77) '0100 1101=77
i2c.write(0)
i2c.write(141) '1000 1101=141
i2c.write(0) '-->H
i2c.write(109) '0110 1101=109
i2c.write(0)
i2c.write(93) '0101 1101=93
i2c.write(0) '-->e
i2c.write(109) '0110 1101=109
i2c.write(0)
i2c.write(205) '1100 1101=205
i2c.write(0) '-->l
i2c.write(109) '0110 1101=109
i2c.write(0)
i2c.write(205) '1100 1101=205
i2c.write(0) '-->l
i2c.write(109) '0110 1101=109
i2c.write(0)
i2c.write(253) '1111 1101=253
i2c.write(0) '-->o
i2c.write(45) '0010 1101=45
i2c.write(0)
i2c.write(13) '0000 1101=13
i2c.write(0) '-->space
i2c.end()
'W o r l d
'87D 111D 114D 108D 100D
'0101 0111, 0110 1111, 0111 0010, 0110 1100, 0110 0100
i2c.begin(address)
i2c.write(93) '0101 1101=93
i2c.write(0)
i2c.write(125) '0111 1101=125
i2c.write(0) '-->W
i2c.write(109) '0110 1101=109
i2c.write(0)
i2c.write(253) '1111 1101=253
i2c.write(0) '-->o
i2c.write(125) '0111 1101=125
i2c.write(0)
i2c.write(45) '0010 1101=45
i2c.write(0) '-->r
i2c.write(109) '0110 1101=109
i2c.write(0)
i2c.write(205) '1100 1101=205
i2c.write(0) '-->l
i2c.write(109) '0110 1101=109
i2c.write(0)
i2c.write(77) '0100 1101=77
i2c.write(0) '-->d
i2c.write(8) '0000 1000=Blacklight:On
i2c.end()
print ("Hello World-->LCD")
[quit]
end
The task consists of two parts:
1. Initialize HD44780 (4-bit data transfer!)
2. Display the characters in two steps. First the top 4 bits, then the bottom 4 bits. All dumps are closed by the i2c.write (0) statement.
Please help:
How can the value of a variable be written to the LCD display?
Regards: mezjoc
'/I2C LCD Init 4-bit_1.bas/2021.01.30.
wifi.connect
memclear
cls
let address = 39 'PCF8574 I2C Address
i2c.setup(4,5) 'choose your I2C bus pins
'P7 P6 P5 P4 P3 P2 P1 P0 --- PCF8574
' | | | | | | | |
'D7 D6 D5 D4 Blacl. EN R/W RS --- HD44780
'step1
delay 150
'step2
i2c.begin(address)
i2c.write(52) '0011 0100b=52
i2c.write(0)
delay 5
'step3
i2c.write(52) '0011 0100b=52
i2c.write(0)
delay 1
'step4
i2c.write(52) '0011 0100b=52
i2c.write(0)
delay 1
'step5
i2c.write(36) '0010 0100b=36
i2c.write(0)
delay 1
'step6
i2c.write(36) '0010 0100b=36
i2c.write(0)
i2c.write(132) '1000 0100b=132
i2c.write(0)
delay 1
'step7
i2c.write(4) '0000 0100b=4
i2c.write(0)
i2c.write(132) '1000 0100b=132
i2c.write(0)
delay 1
'step8
i2c.write(4) '0000 0100b=4
i2c.write(0)
i2c.write(20) '0001 0100b=20
i2c.write(0)
delay 5
'step9
i2c.write(4) '0000 0100b=4
i2c.write(0)
i2c.write(100) '0110 0100b=100
i2c.write(0)
'0 1 I/D S,0110=6D
'I/D=1-->Increment by 1
'S=0-->No shift
i2c.end()
delay 1
'step10
'Initialization ends
'step11
i2c.begin(address)
i2c.write(4) '0000 0100b=4
i2c.write(0)
i2c.write(196) '1100 0100b=196
i2c.write(0)
'1 1 C B
'C=0-->Cursor off
'B=0-->Blinking off
i2c.end()
delay 100
'Display:
'H e l l o space
'72D 101D 108D 108D 111D 32D
'0100 1000, 0110 0101, 0110 1100, 0110 1100, 0110 1111, 0010 0000
'P7 P6 P5 P4 P3 P2 P1 P0 --- PCF8574
' | | | | | | | |
'D7 D6 D5 D4 Blacl. EN R/W RS --- HD44780
i2c.begin(address)
i2c.write(77) '0100 1101=77
i2c.write(0)
i2c.write(141) '1000 1101=141
i2c.write(0) '-->H
i2c.write(109) '0110 1101=109
i2c.write(0)
i2c.write(93) '0101 1101=93
i2c.write(0) '-->e
i2c.write(109) '0110 1101=109
i2c.write(0)
i2c.write(205) '1100 1101=205
i2c.write(0) '-->l
i2c.write(109) '0110 1101=109
i2c.write(0)
i2c.write(205) '1100 1101=205
i2c.write(0) '-->l
i2c.write(109) '0110 1101=109
i2c.write(0)
i2c.write(253) '1111 1101=253
i2c.write(0) '-->o
i2c.write(45) '0010 1101=45
i2c.write(0)
i2c.write(13) '0000 1101=13
i2c.write(0) '-->space
i2c.end()
'W o r l d
'87D 111D 114D 108D 100D
'0101 0111, 0110 1111, 0111 0010, 0110 1100, 0110 0100
i2c.begin(address)
i2c.write(93) '0101 1101=93
i2c.write(0)
i2c.write(125) '0111 1101=125
i2c.write(0) '-->W
i2c.write(109) '0110 1101=109
i2c.write(0)
i2c.write(253) '1111 1101=253
i2c.write(0) '-->o
i2c.write(125) '0111 1101=125
i2c.write(0)
i2c.write(45) '0010 1101=45
i2c.write(0) '-->r
i2c.write(109) '0110 1101=109
i2c.write(0)
i2c.write(205) '1100 1101=205
i2c.write(0) '-->l
i2c.write(109) '0110 1101=109
i2c.write(0)
i2c.write(77) '0100 1101=77
i2c.write(0) '-->d
i2c.write(8) '0000 1000=Blacklight:On
i2c.end()
print ("Hello World-->LCD")
[quit]
end