So I want to turn on a lcd 16x2 using my Raspberry Pi Pico but it can't detect the file requested. First, I upload the file with
import machine
import utime
rs= machine.Pin(16,machine.Pin.OUT)
e = machine.Pin(17,machine.Pin.OUT)
d4 = machine.Pin(18,machine.Pin.OUT)
d5 = machine.Pin(19,machine.Pin.OUT)
d6 = machine.Pin(20,machine.Pin.OUT)
d7 = machine.Pin(21,machine.Pin.OUT)
def setCursor(line, pos):
b = 0
if line==1:
b=0
elif line==2:
b=40
returnHome()
for i in range(0, b+pos):
moveCursorRight()
def clearScreen():
rs.value(0)
send2LCD8(0b00000001)#clear screen
longDelay(2)#clear screen needs a long delay
rs.value(1)
def setupLCD():
rs.value(0)
send2LCD4(0b0011)
send2LCD4(0b0011)
send2LCD4(0b0011)
send2LCD4(0b0010)
send2LCD8(0b00101000)
send2LCD8(0b00001100)#lcd on, blink off, cursor off.
send2LCD8(0b00000110)#increment cursor, no display shift
send2LCD8(0b00000001)#clear screen
longDelay(2)#clear screen needs a long delay
rs.value(1)
def displayString(row, col, input_string):
setCursor(row,col)
for x in input_string:
send2LCD8(ord(x))
longDelay(10)
Then, I rename it lcd_pico.py And in the main.py file, I write
from lcd_pico import *
setupLCD()
displayString(1,0,"WELCOME")
displayString(2,0,"TO")
longDelay(4000)
displayString(1,0,"CIRCUIT")
displayString(2,0,"DIGEST")
longDelay(4000)
while(True):
displayString(1,0,"CIRCUIT")
displayString(2,0,"DIGEST")
longDelay(1000)
clearScreen()
longDelay(500)
And I get the error
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "lcd_pico.py", line 26, in setupLCD
NameError: name 'send2LCD4' isn't defined
Any ideas of what I can do?
I tried to turn on a lcd using raspberry pi pico. I expected to see some text on the lcd, but, I get a error in the editor Thonny IDE
Obviously because you haven't defined you send2LCD4()
function.
I guess you used the example from here:
https://www.instructables.com/Raspberry-Pi-PICO-LCD-not-I2C/
It's defined as:
def send2LCD4(BinNum):
d4.value((BinNum & 0b00000001) >>0)
d5.value((BinNum & 0b00000010) >>1)
d6.value((BinNum & 0b00000100) >>2)
d7.value((BinNum & 0b00001000) >>3)
pulseE()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.