Display char or CGRAM using uasyncio method
-
- Posts: 118
- Joined: Wed Dec 27, 2017 8:52 am
Display char or CGRAM using uasyncio method
Hello,
I am using displaying data on LCD using async method given by Sir Peter Hinch. But i wanted to know have anyone use the async module, to display charachter at different position on LCD.
And is there any way to use async method to display CGRAM, like Sir Dhylands have done in LCD interfacing module ?
I am using displaying data on LCD using async method given by Sir Peter Hinch. But i wanted to know have anyone use the async module, to display charachter at different position on LCD.
And is there any way to use async method to display CGRAM, like Sir Dhylands have done in LCD interfacing module ?
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Display char or CGRAM using uasyncio method
I'm not sure which LCD or which of my libraries you're using. My touch GUI for the official LCD160CR display uses uasyncio and can display text (and other objects) anywhere on the screen.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
-
- Posts: 118
- Joined: Wed Dec 27, 2017 8:52 am
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Display char or CGRAM using uasyncio method
The driver simply maps a fixed-length line of text onto a row of the display. To display a line with specific formatting I'd create a new string using the string format operator and re-display it. It's not very efficient but with a display of typically 2 rows of 16 columns I thought the complexity of a more fully featured driver wasn't justified, either in terms of refresh speed or RAM allocation.
If you're still concerned others have written HD44780 drivers which may be more fully featured.
If you're still concerned others have written HD44780 drivers which may be more fully featured.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
-
- Posts: 118
- Joined: Wed Dec 27, 2017 8:52 am
Re: Display char or CGRAM using uasyncio method
okay, i just assigned different spaces to different variables and use string formatting.
Code: Select all
one = ""
two = " "
three = " "
four = " "
five = " "
six = " "
seven = " "
eight = " "
nine = " "
ten = " "
elleven = " "
twelve = " "
thirteen = " "
fourteen = " "
fifteen = " "
sixteen = " "
#Cursor position are from 0 to 15
async def ASK25_LCD_Display_Character(a):
lcd[0] = '{}A'.format(a)
await asyncio.sleep(1)
position = [one, two, three, four, five, six, seven, eight, nine, ten, \
elleven, twelve, thirteen, fourteen, fifteen, sixteen]
#for x in range(16):
# loop = asyncio.get_event_loop()
# loop.run_until_complete(ASK25_LCD_Display_Character(position[x]))
loop = asyncio.get_event_loop()
x = 0
while True:
if (x < 16):
loop.run_until_complete(ASK25_LCD_Display_Character(position[x]))
pyb.delay(1)
x+=1
if (x == 16):
x = 0
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Display char or CGRAM using uasyncio method
You might like to consider
This can be used as follows:
This version will erase any characters after the passed string (i.e. it will always have the specified width):
Further, I don't think you've grasped how to use uasyncio. I suggest you look at the tutorial in this repo. Normally you run the event loop for the duration of your program rather than starting and stopping it repeatedly.
Code: Select all
'{:>{n}s}'.format('A', n=6)
Code: Select all
>>> def print_at(st, col):
... return '{:>{col}s}'.format(st, col=col+len(st))
...
>>> print_at('dog', 2)
' dog'
>>>
Code: Select all
def print_at(st, col, width=16):
return '{:>{col}s}{:{t}s}'.format(st,'', col=col+len(st), t = width-(col+len(st)))
Code: Select all
>>> print_at('cat', 2)
' cat '
>>> len(_)
16
>>>
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
-
- Posts: 118
- Joined: Wed Dec 27, 2017 8:52 am
Re: Display char or CGRAM using uasyncio method
okay. thanks sir for suggestion.
Actually i have uasyncio module only with lcd, so didn't go in much depth of module. But i guess i need to understand how to use uasyncio now.
Actually i have uasyncio module only with lcd, so didn't go in much depth of module. But i guess i need to understand how to use uasyncio now.
-
- Posts: 118
- Joined: Wed Dec 27, 2017 8:52 am
Re: Display char or CGRAM using uasyncio method
Hey Sir,
I used method given by you, and it worked well.
Now i am using same method to display scrolling messages . i have created a function with parameter passed Data, row and Shift Direction.
I have given my code below.
I used method given by you, and it worked well.
Now i am using same method to display scrolling messages . i have created a function with parameter passed Data, row and Shift Direction.
I have given my code below.
At present, the message will be completely scolled out of LCD, than it comes on col 1 again.Problem is that when my message gets scrolled out of LCD (i.e message = " exam", message[-1] gets scrolled out), i want that message[-1] to display at the col 1 of LCD along with message[0:2] displayed at last columns of LCD.
Code: Select all
async def Display_Character(data, row, col):
lcd[row] = '{:>{col}s}'.format(data, col = col + len(data) )
await asyncio.sleep_ms(500)
Right = 0
Left = 1
#Function to show scrolling message
async def ASK25_LCD_Display_Data_Shift(data, row, Shift_Direction):
col = 0
if (Shift_Direction == Right): #Testing Shift Direction
position = Right
elif (Shift_Direction == Left):
position = Left
while True:
if (col < 16):
col+=1
else:
col = 0
loop.run_until_complete(Display_Character(data, row, col ))
loop.run_until_complete(ASK25_LCD_Display_Data_Shift('ABC', 0, Right))
-
- Posts: 118
- Joined: Wed Dec 27, 2017 8:52 am
Re: Display char or CGRAM using uasyncio method
And Sir how to use this same module for 8 bit mode.
I have changed the initstring to this INITSTRING = b'\x33\x32\x38\x0C\x06\x01' 0x38 means i have selected 8 bit mode as per my knowledge.
And in Pin list i have defined my pins : (RS, E, D0 -D8 pin)
PINLIST = ('PB1','PB5','PE8','PE9','PE10','PE11','PE12','PE13','PE14','PE15')
here goes def__init__ function .
And here i tried to the code lookiong at Sir @dhylands code :
Is that correct way ? Or can you guide me through it ?
I have changed the initstring to this INITSTRING = b'\x33\x32\x38\x0C\x06\x01' 0x38 means i have selected 8 bit mode as per my knowledge.
And in Pin list i have defined my pins : (RS, E, D0 -D8 pin)
PINLIST = ('PB1','PB5','PE8','PE9','PE10','PE11','PE12','PE13','PE14','PE15')
here goes def__init__ function .
Code: Select all
def __init__(self, pinlist, cols, rows = 2): # Init with pin nos for enable, rs, D4, D5, D6, D7
self.initialising = True
self.LCD_E = Pin(pinlist[1], Pin.OUT) # Create and initialise the hardware pins
self.LCD_RS = Pin(pinlist[0], Pin.OUT)
self.datapins = [Pin(pin_name, Pin.OUT) for pin_name in pinlist[2:]]
self.d0_pin = pinlist[2]
self.d1_pin = pinlist[3]
self.d2_pin = pinlist[4]
self.d3_pin = pinlist[5]
self.d4_pin = pinlist[6]
self.d5_pin = pinlist[7]
self.d6_pin = pinlist[8]
self.d7_pin = pinlist[9]
self.cols = cols
self.rows = rows
self.lines = [""] * self.rows
self.dirty = [False] * self.rows
for thisbyte in LCD.INITSTRING:
self.lcd_byte(thisbyte, LCD.CMD)
self.initialising = False # Long delay after first byte only
loop = asyncio.get_event_loop()
loop.create_task(self.runlcd())
Code: Select all
Writes 8 bits of data to the LCD.
def lcd_8bits(self, value):
self.d1_pin.value(value & 0x08)
self.d2_pin.value(value & 0x04)
self.d1_pin.value(value & 0x02)
self.d0_pin.value(value & 0x01)
self.hal_write_4bits(value >> 4)
self.d7_pin.value(nibble & 0x08)
self.d6_pin.value(nibble & 0x04)
self.d5_pin.value(nibble & 0x02)
self.d4_pin.value(nibble & 0x01)
self.LCD_E.value(True) # Toggle the enable pin
time.sleep_us(LCD.E_PULSE)
self.LCD_E.value(False)
Is that correct way ? Or can you guide me through it ?
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Display char or CGRAM using uasyncio method
Sorry, I have no experience of 8 bit mode: I see no point in using more pins than necessary.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.