Closed BertLindeman closed 6 months ago
Hi Bert,
I'm on mobile, but let me see if I can help before I get back to my desk.
From what I understand, you'd like to write N characters beginning at cursor position X, Y (column, row).
For this, I believe you can use this method to set the cursor: https://github.com/Thomascountz/micropython_i2c_lcd/blob/main/hd44780.py#L234-L241, and then write the characters while advancing the cursor or write a string of length 8 using the other methods in the class.
Anywhere not visited by the cursor will not be updated. So long as you use the lower-level hd44780 class methods, you should be able to achieve the manipulation you're going for.
It's been a while since I've visited this code myself, so as you suggest, I will try writing a test for this when I'm back home.
Thanks for trying out the library! I would love to see what you're making!
Fast response Thomas.
Will try it. I am just fiddling with the sunfounders kit combined with NodeRed. Current "project" Get Open Weather map current weather and show on a 1602 lcd. No rocket science but fun to do.
Thanks for the rapid response.
Bert
That sounds like an awesome project and after Googling it, it looks like there are great things in the kit to build with. I hope your weather station project goes well!
Here's the code I'm hoping will address your original question along with a video preview of a simulation. Please let me know if this isn't quite what you were looking for.
from machine import Pin, I2C
import utime
from pcf8574 import PCF8574
from hd44780 import HD44780
from lcd import LCD
def main_test():
print("Create an I2C object")
i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
print("Create a PCF8574 object")
pcf8574 = PCF8574(i2c)
print("Create an HD44780 object")
hd44780 = HD44780(pcf8574, num_lines=2, num_columns=16)
print("Create an LCD object")
lcd = LCD(hd44780, pcf8574)
while True:
print ("Clear the display")
lcd.clear()
print("Turn on backlight")
lcd.backlight_on()
print("Test writing a string to the first line of the LCD")
lcd.write_line("Hello, world!", 0)
utime.sleep(3)
# Ref: https://github.com/Thomascountz/micropython_i2c_lcd/issues/4
print("Test writing an 8-character string at a specific cursor position")
greetings = ["friends!", "amigos!", "venner!", "Freunde!", "vrienden!"]
for greeting in greetings:
hd44780.set_cursor(line=0, column=7)
hd44780.write_string(greeting)
utime.sleep(1)
utime.sleep(3)
print ("Clear the display")
lcd.clear()
print("Test writing 8 characters to a specific cursor position one at a time")
hd44780.set_cursor(line=0, column=7) # midway through the top line
for character in "I <3 uPy!":
hd44780.write_char(character) # Cursor "auto-advances"
if character != " ":
utime.sleep(1)
utime.sleep(2)
print(
"Write a string to the first line of the LCD to indicate that the test is completed"
)
lcd.write_line("Test completed!", 0)
print("Wait for a while")
utime.sleep(2)
print("Clear the LCD at the end of each loop iteration")
lcd.clear()
if __name__ == "__main__":
main_test()
Cheers! 🚀
Here is a link to where you can access the simulation on Wowki: https://wokwi.com/projects/396956588422568961
FUN! I just started this morning for the first test on wokwi. Coincidence does not exist. A great way to show the breadboard and the results.
Awesome stuff! I hope this little library makes using the display easier. And, I forgot to say, thank you very much for the PR/contribution!
Hi,
Just started to use your lcd library.
I see functions are in HD44780 but I do not know how to implement it.
A snippet:
or
Both obviously do not work. Maybe an idea to add such to the test program?
Thanks,
Bert