Issue
The below shown code only clears page_1 data where main displays some text on chip 1 i.e., page_1(in code) but after set cursor col to 63+ text is written in chip 2 i.e., page_2 (in code) but then the data in it are not getting cleared while contents of page_1 does in any condition
import time
import RPi.GPIO as GPIO
# timing constants
E_PULSE = 0.0000001
E_DELAY = 0.0000005
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.OUT) # rs
GPIO.setup(7, GPIO.OUT) # rw
GPIO.setup(8, GPIO.OUT) # en
GPIO.setup(9, GPIO.OUT) # d0
GPIO.setup(10, GPIO.OUT) # d1
GPIO.setup(11, GPIO.OUT) # d2
GPIO.setup(14, GPIO.OUT) # d3
GPIO.setup(15, GPIO.OUT) # d4
GPIO.setup(17, GPIO.OUT) # d5
GPIO.setup(18, GPIO.OUT) # d6
GPIO.setup(22, GPIO.OUT) # cs1
GPIO.setup(23, GPIO.OUT) # cs2
GPIO.setup(24, GPIO.OUT) # rst
# Set pins to low
GPIO.output(4, 0) # rs
GPIO.output(7, 0) # rw
GPIO.output(8, 0) # en
GPIO.output(22, 0) # cs1
GPIO.output(23, 0) # cs2
GPIO.output(24, 0) # rst
def data_write(value, mode):
GPIO.setup(25, GPIO.OUT) # d7 as o/p
GPIO.output(7, 0)
GPIO.output(4, mode)
GPIO.output(9, value & 0x01)
GPIO.output(10, value & 0x02)
GPIO.output(11, value & 0x04)
GPIO.output(14, value & 0x08)
GPIO.output(15, value & 0x10)
GPIO.output(17, value & 0x20)
GPIO.output(18, value & 0x40)
GPIO.output(25, value & 0x80)
# Toggle E
time.sleep(E_DELAY)
GPIO.output(8, True)
time.sleep(E_PULSE)
GPIO.output(8, False)
time.sleep(E_DELAY)
# Waiting write operation complete by listening BUSY signal
def busy_chk():
GPIO.setup(25, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.output(7, 1)
GPIO.output(4, 0)
time.sleep(E_DELAY)
GPIO.output(8, True)
time.sleep(E_PULSE)
GPIO.output(8, False)
time.sleep(E_DELAY)
# Wait until BUSY(d7) is off
while GPIO.input(25):
pass
GPIO.setup(25, GPIO.OUT) # set d7 back to Output
def page_1():
GPIO.output(22, 1) # Select left controller
GPIO.output(23, 0) # Select right controller
def page_2():
GPIO.output(22, 0) # Select left controller
GPIO.output(23, 1) # Select right controller
def init_disp():
GPIO.output(24, 1) # Reset the display
page_1()
data_write(0x3F, 0) # command to turn ON LCD
page_2()
data_write(0x3F, 0) # command to turn ON LCD
page_1()
data_write(0xC0, 0) # start line command
page_2()
data_write(0xC0, 0) # start line command
def clr_disp():
page_1()
for y in range(8):
set_cursor(0, y)
for i in range(64):
data_write(0x00, 1)
page_2()
for y in range(8):
set_cursor(0, y)
for i in range(64):
data_write(0x00, 1)
def set_cursor(col, row):
if row >= 8:
raise ValueError('Invalid Input')
pass
data_write((row | 0xB8) & 0xBF, 0)
if col < 63:
page_1() # Enable left controller
data_write((col | 0x40) & 0x7F, 0)
else:
page_2() # Enable right controller
data_write(((col - 64) | 0x40) & 0x7F, 0)
def main():
init_disp()
busy_chk()
clr_disp()
set_cursor(0, 0)
data_write(0x02, 1)
data_write(0x02, 1)
data_write(0xFE, 1)
data_write(0x02, 1)
if __name__ == "__main__":
main()
this code below is supposed to clear dots of page_2
def clr_disp():
page_1()
for y in range(8):
set_cursor(0, y)
for i in range(64):
data_write(0x00, 1)
page_2()
for y in range(8):
set_cursor(0, y)
for i in range(64):
data_write(0x00, 1)
some please tell me where I'm going wrong, i'm not very good at coding
thank you
Solution
In function clr_disp()
you first call page_2()
but then in for loop you call set_cursor(0, y)
and because you pass 0
as col
we get into first if condition which resets the cursor back to page1.
You can test this if you comment the first part of your clear display, you should see that your second part also clears the page1.
You should clear your display like this:
def clr_disp():
for y in range(8):
set_cursor(0, y)
for i in range(64):
data_write(0x00, 1)
for y in range(8):
set_cursor(64, y)
for i in range(64):
data_write(0x00, 1)
Answered By - Grekkq Answer Checked By - Mildred Charles (WPSolving Admin)