Place to put your Basic demos and examples

Moderator: Mmiscool

User avatar
By mezjoc
#90371 "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
User avatar
By mezjoc
#90423 In this example, the current temperature value is displayed.
for example: Temp = 22.6 C
Wiring on the D1 mini panel:
DS18B20 / DAT -> D4 / GPIO2
LCD / SCL -> D1 / GPIO5
LCD / SDA -> D2 / GPIO4
VCC -> 5V
GND -> GND
------------------------------------------------------------------------------------------
'/I2C LCD Init 4-bit.bas/2021.02.04.
wifi.connect
memclear
cls
let address = 39 'PCF8574 I2C Address
i2c.setup(4,5) 'choose your I2C bus pins
a$ = "Temp="
hom = int(temp(0)*10)/10
b$ = str(hom)
c$ = " C"
text$ = a$ & b$ & c$ 'text$ = "Hello World"
'P7 P6 P5 P4 P3 P2 P1 P0 --- PCF8574
' | | | | | | | |
'D7 D6 D5 D4 Bl.EN R/W RS --- HD44780
[Initialization]
delay 150 'step1
i2c.begin(address)
i2c.write(52) '0011 0100b=52 'step2
i2c.write(0)
delay 5
i2c.write(52) '0011 0100b=52 'step3
i2c.write(0)
delay 1
i2c.write(52) '0011 0100b=52 'step4
i2c.write(0)
delay 1
i2c.write(36) '0010 0100b=36 'step5
i2c.write(0)
delay 1
i2c.write(36) '0010 0100b=36 'step6
i2c.write(0)
i2c.write(132) '1000 0100b=132
i2c.write(0)
delay 1
i2c.write(4) '0000 0100b=4 'step7
i2c.write(0)
i2c.write(132) '1000 0100b=132
i2c.write(0)
delay 1
i2c.write(4) '0000 0100b=4 'step8
i2c.write(0)
i2c.write(20) '0001 0100b=20
i2c.write(0)
delay 5
i2c.write(4) '0000 0100b=4 'step9
i2c.write(0)
i2c.write(100) '0110 0100b=100 '0 1 I/D S
i2c.write(0) 'I/D=1-->Increment by 1
i2c.end() 'S=0-->No shift
delay 1
'Initialization ends 'step10
i2c.begin(address) 'step11
i2c.write(4) '0000 0100b=4
i2c.write(0)
i2c.write(196) '1100 0100b=196 '1 1 C B
i2c.write(0) 'C=0-->Cursor off
i2c.end() 'B=0-->Blinking off
delay 100
'Display:
print "Specified string(text$):"
print text$
print "The number of characters in the string:"
print len(text$)
print
for n = 1 to len(text$)
i2c.begin(address)
i2c.write((asc(mid(text$,n,1)) and 240) + 13)
i2c.write(0)
i2c.write((asc(mid(text$,n,1)) and 15) << 4 + 13)
i2c.write(0)
i2c.end()
next n
i2c.begin(address)
i2c.write(8) '0000 1000=Blacklight:On
i2c.end()
button "EXIT",[quit]
wait
[quit]
end
:roll: