STM32F407Disc : Write data on LCD
-
- Posts: 118
- Joined: Wed Dec 27, 2017 8:52 am
STM32F407Disc : Write data on LCD
Hello,
So i am currently interfacing STM32f4 with LCD(16*2) display. So have already tried few code available on github but its not working. So i have written few functions to write character on LCD display. But problem lies in the fact that output is not getting displayed on LCD.
below i have given my code.
"""
import pyb
from pyb import Pin, delay, millis
import time
#LCD Commands
LCD_CLEAR = 0x01 # DB0: clear display
LCD_HOME = 0x02 # DB1: return to home position
LCD_OFF = 0X08
LCD_ON = 0X0C
CURSOR_ON = 0X0E
CURSOR_OFF = 0X0C
CURSOR_BLINK = 0X0F
LCD_SHIFT_LEFT = 0x18
LCD_SHIFT_RIGHT = 0x1C
CURSOR_SHIFT_LEFT = 0X10
CURSOR_SHIFT_RIGHT = 0X14
LCD_4BIT_1LINE = 0x20 #4-bit interface, 1 line, 5*7 Pixels
LCD_4BIT_2LINE = 0x28 #4-bit interface, 2 lines, 5*7 Pixels
LCD_8BIT_1LINE = 0X30 #8-bit interface, 1 line, 5*7 Pixels
LCD_8BIT_2LINE = 0X38 #8-bit interface, 2 lines, 5*7 Pixels
#LCD_PIN_DECLARATION
rs = pyb.Pin('PB1', Pin.OUT_PP, Pin.PULL_UP)
rw = pyb.Pin('PB4', Pin.OUT_PP, Pin.PULL_UP)
en = pyb.Pin('PB5', Pin.OUT_PP, Pin.PULL_UP)
d0 = pyb.Pin('PE8', Pin.OUT_PP, Pin.PULL_UP)
d1 = pyb.Pin('PE9', Pin.OUT_PP, Pin.PULL_NONE)
d2 = pyb.Pin('PE10', Pin.OUT_PP, Pin.PULL_NONE)
d3 = pyb.Pin('PE11', Pin.OUT_PP, Pin.PULL_NONE)
d4 = pyb.Pin('PE12', Pin.OUT_PP, Pin.PULL_NONE)
d5 = pyb.Pin('PE13', Pin.OUT_PP, Pin.PULL_NONE)
d6 = pyb.Pin('PE14', Pin.OUT_PP, Pin.PULL_NONE)
d7 = pyb.Pin('PE15', Pin.OUT_PP, Pin.PULL_NONE)
# ASK25_LCD_INIT
def ASK25_LCD_Init(): # ASK25_LCD_INIT
rs.low() #Clear RS RW EN
rw.low()
en.low()
pyb.udelay(15) #15us
ASK25_LCD_WRITE_COMMAND(LCD_CLEAR)
delay(2)
ASK25_LCD_WRITE_COMMAND(LCD_CLEAR)
delay(4)
ASK25_LCD_WRITE_COMMAND(LCD_8BIT_2LINE)
delay(1)
ASK25_LCD_WRITE_COMMAND(LCD_HOME)
pyb.udelay(50)
ASK25_LCD_WRITE_COMMAND(LCD_OFF)
ASK25_LCD_WRITE_COMMAND(LCD_ON)
ASK25_LCD_WRITE_COMMAND(CURSOR_ON)
delay(50)
def LCD_Clear_Values():
d0 = 0
d1 = 0
d2 = 0
d3 = 0
d4 = 0
d5 = 0
d6 = 0
d7 = 0
def hal_write_8bits(command):
# """Writes 8 bits of data to the LCD."""
rw.low()
d0.value(command & 0x01)
d1.value(command & 0x02)
d2.value(command & 0x04)
d3.value(command & 0x08)
d4.value(command & 0x01)
d5.value(command & 0x02)
d6.value(command & 0x04)
d7.value(command & 0x08)
def ASK25_LCD_Enable():
#"""Pulse the enable line high, and then low again."""
en.low()
pyb.udelay(1)
en.high()
pyb.udelay(1) # Enable pulse needs to be > 450 nsec
en.low()
pyb.udelay(100) # Commands need > 37us to settle
# ASK25_LCD_Write_COMMAND
def ASK25_LCD_WRITE_COMMAND(command): # ASK25_LCD_Write_COMMAND
Lcd_Data = command
rs.low() #Clear rs
rw.low() #Clear rw
LCD_Clear_Values() #Clear Old Value
hal_write_8bits(command)
ASK25_LCD_Enable()
# ASK25_LCD_Write_DATA
def ASK25_LCD_Write_Data(character): # ASK25_LCD_Write_DATA
Lcd_Data = character
ASK25_LCD_WRITE_COMMAND(CURSOR_OFF)
rs.high() #Set RS
rw.low() #Set RW
LCD_Clear_Values() #Clear Old Values
hal_write_8bits(character)
ASK25_LCD_Enable()
#MAIN PROGRAM
ASK25_LCD_Init()
ASK25_LCD_Write_Data(0x32)
"""
So can anyone help me to improve with this code...
So i am currently interfacing STM32f4 with LCD(16*2) display. So have already tried few code available on github but its not working. So i have written few functions to write character on LCD display. But problem lies in the fact that output is not getting displayed on LCD.
below i have given my code.
"""
import pyb
from pyb import Pin, delay, millis
import time
#LCD Commands
LCD_CLEAR = 0x01 # DB0: clear display
LCD_HOME = 0x02 # DB1: return to home position
LCD_OFF = 0X08
LCD_ON = 0X0C
CURSOR_ON = 0X0E
CURSOR_OFF = 0X0C
CURSOR_BLINK = 0X0F
LCD_SHIFT_LEFT = 0x18
LCD_SHIFT_RIGHT = 0x1C
CURSOR_SHIFT_LEFT = 0X10
CURSOR_SHIFT_RIGHT = 0X14
LCD_4BIT_1LINE = 0x20 #4-bit interface, 1 line, 5*7 Pixels
LCD_4BIT_2LINE = 0x28 #4-bit interface, 2 lines, 5*7 Pixels
LCD_8BIT_1LINE = 0X30 #8-bit interface, 1 line, 5*7 Pixels
LCD_8BIT_2LINE = 0X38 #8-bit interface, 2 lines, 5*7 Pixels
#LCD_PIN_DECLARATION
rs = pyb.Pin('PB1', Pin.OUT_PP, Pin.PULL_UP)
rw = pyb.Pin('PB4', Pin.OUT_PP, Pin.PULL_UP)
en = pyb.Pin('PB5', Pin.OUT_PP, Pin.PULL_UP)
d0 = pyb.Pin('PE8', Pin.OUT_PP, Pin.PULL_UP)
d1 = pyb.Pin('PE9', Pin.OUT_PP, Pin.PULL_NONE)
d2 = pyb.Pin('PE10', Pin.OUT_PP, Pin.PULL_NONE)
d3 = pyb.Pin('PE11', Pin.OUT_PP, Pin.PULL_NONE)
d4 = pyb.Pin('PE12', Pin.OUT_PP, Pin.PULL_NONE)
d5 = pyb.Pin('PE13', Pin.OUT_PP, Pin.PULL_NONE)
d6 = pyb.Pin('PE14', Pin.OUT_PP, Pin.PULL_NONE)
d7 = pyb.Pin('PE15', Pin.OUT_PP, Pin.PULL_NONE)
# ASK25_LCD_INIT
def ASK25_LCD_Init(): # ASK25_LCD_INIT
rs.low() #Clear RS RW EN
rw.low()
en.low()
pyb.udelay(15) #15us
ASK25_LCD_WRITE_COMMAND(LCD_CLEAR)
delay(2)
ASK25_LCD_WRITE_COMMAND(LCD_CLEAR)
delay(4)
ASK25_LCD_WRITE_COMMAND(LCD_8BIT_2LINE)
delay(1)
ASK25_LCD_WRITE_COMMAND(LCD_HOME)
pyb.udelay(50)
ASK25_LCD_WRITE_COMMAND(LCD_OFF)
ASK25_LCD_WRITE_COMMAND(LCD_ON)
ASK25_LCD_WRITE_COMMAND(CURSOR_ON)
delay(50)
def LCD_Clear_Values():
d0 = 0
d1 = 0
d2 = 0
d3 = 0
d4 = 0
d5 = 0
d6 = 0
d7 = 0
def hal_write_8bits(command):
# """Writes 8 bits of data to the LCD."""
rw.low()
d0.value(command & 0x01)
d1.value(command & 0x02)
d2.value(command & 0x04)
d3.value(command & 0x08)
d4.value(command & 0x01)
d5.value(command & 0x02)
d6.value(command & 0x04)
d7.value(command & 0x08)
def ASK25_LCD_Enable():
#"""Pulse the enable line high, and then low again."""
en.low()
pyb.udelay(1)
en.high()
pyb.udelay(1) # Enable pulse needs to be > 450 nsec
en.low()
pyb.udelay(100) # Commands need > 37us to settle
# ASK25_LCD_Write_COMMAND
def ASK25_LCD_WRITE_COMMAND(command): # ASK25_LCD_Write_COMMAND
Lcd_Data = command
rs.low() #Clear rs
rw.low() #Clear rw
LCD_Clear_Values() #Clear Old Value
hal_write_8bits(command)
ASK25_LCD_Enable()
# ASK25_LCD_Write_DATA
def ASK25_LCD_Write_Data(character): # ASK25_LCD_Write_DATA
Lcd_Data = character
ASK25_LCD_WRITE_COMMAND(CURSOR_OFF)
rs.high() #Set RS
rw.low() #Set RW
LCD_Clear_Values() #Clear Old Values
hal_write_8bits(character)
ASK25_LCD_Enable()
#MAIN PROGRAM
ASK25_LCD_Init()
ASK25_LCD_Write_Data(0x32)
"""
So can anyone help me to improve with this code...
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: STM32F407Disc : Write data on LCD
There are at least two MicroPython drivers for Hitachi HD44780 LCD's. This one from Dave Hylands. There is also an asynchronous one I wrote which may be found here.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
-
- Posts: 118
- Joined: Wed Dec 27, 2017 8:52 am
Re: STM32F407Disc : Write data on LCD
Okay. While using your asynchronous mode code, their is an import error at time of importing uasyncio module i.e "" import uasyncio as asyncio ""
I have downloaded your project, and searched for the module "uasyncio" its not appearing. So how to get this module or any other alternative ?
Thanks
I have downloaded your project, and searched for the module "uasyncio" its not appearing. So how to get this module or any other alternative ?
Thanks
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: STM32F407Disc : Write data on LCD
There are some instructions here. The same principle applies to installing any of the standard MicroPython libraries.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
-
- Posts: 118
- Joined: Wed Dec 27, 2017 8:52 am
Re: STM32F407Disc : Write data on LCD
Okay, i read ReadMe file and downloaded the uasyncio (asynchronous lib.) .Now i am facing a new problem.
As shown in the alcd test example, i have imported all the modules given below.
"""
So its showing module object has no attribute 'get_event_loop'. So what should i do now ?
As shown in the alcd test example, i have imported all the modules given below.
Now, whenever i write next instruction " lcd = LCD(PINLIST,cols=16)" , it gives me this error:import uasyncio as asyncio
import utime as time
from alcd import LCD, PINLIST
AttributeError: 'module' object has no attribute 'get_event_loop'Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "alcd.py", line 81, in __init__
"""
So its showing module object has no attribute 'get_event_loop'. So what should i do now ?
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: STM32F407Disc : Write data on LCD
Something has gone wrong with the installation of uasyncio. This is what I see on a Pyboard:
Later today I'll test the uasyncio installation procedure on a Pyboard running the standard firmware.
Code: Select all
>>> import uasyncio
>>> dir(uasyncio)
['_socket', 'StopLoop', 'EventLoop', 'start_server', 'uasyncio', 'IORead', 'sleep', 'IOWriteDone', 'ensure_future', 'wait_for', 'set_debug', 'sleep_ms', 'IOReadDone', 'SleepMs', 'core', 'coroutine', 'TimeoutObj', 'type_gen', 'SysCall', 'utimeq', 'select', 'DEBUG', '__name__', 'wait_for_ms', '__path__', 'TimeoutError', 'SysCall1', 'StreamReader', 'IOWrite', 'log', 'get_event_loop', 'time', 'Task', 'PollEventLoop', 'StreamWriter', 'open_connection', 'uerrno']
>>> 'get_event_loop' in dir(uasyncio)
True
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: STM32F407Disc : Write data on LCD
OK, I've tried this on a Pyboard V1.0. I flashed today's standard firmware and followed the installation instructions in the uasyncio tutorial, copying the directories and their contents to /flash. This was successful.
So I'm foxed as to your problem. Alas I haven't got an STM32F407Disc to exactly replicate your installation.
So I'm foxed as to your problem. Alas I haven't got an STM32F407Disc to exactly replicate your installation.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
-
- Posts: 118
- Joined: Wed Dec 27, 2017 8:52 am
Re: STM32F407Disc : Write data on LCD
Okay. i get a FALSE value.
But in this command micropython -m upip install -p ~/syn micropython-uasyncio i get error of micropython command not found.
So can you help me in installing uasyncio either with upip or pip utility.
Thanks
Whenever i followed this link https://github.com/peterhinch/micropyth ... UTORIAL.md to install uasyncio .import uasyncio as asyncio
>>> dir (asyncio)
['inspect', 'asyncio', '__name__', '__file__']
But in this command micropython -m upip install -p ~/syn micropython-uasyncio i get error of micropython command not found.
I tried to install with the help of pip utility. And here is the output which i get in the terminal.edutech@edutech-desktop:~/nikhil/upython_stm/micropython/syn$ micropython -m upip install -p ~/syn micropython-uasyncio
micropython: command not found
I am currently using Ubuntu 14.04. So how to install this without error ? I tried to follow document, but their its not mentioned properly how to install it. A single command is given with creating a folder ~/sys.edutech@edutech-desktop:~/nikhil/upython_stm/micropython/syn$ pip install micropython-uasyncio
Collecting micropython-uasyncio
Downloading micropython-uasyncio-1.4.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-0W1VQO/micropython-uasyncio/setup.py", line 7, in <module>
import optimize_upip
ImportError: No module named optimize_upip
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-0W1VQO/micropython-uasyncio/
So can you help me in installing uasyncio either with upip or pip utility.
Thanks
Last edited by nikhiledutech on Tue Jan 02, 2018 9:26 am, edited 2 times in total.
-
- Posts: 118
- Joined: Wed Dec 27, 2017 8:52 am
Re: STM32F407Disc : Write data on LCD
I think this is the same problem which you too faced while py board.
Your issue link https://forum.micropython.org/viewtopi ... 4#p16284
And more thing i want to bring in notice is that, I am booting from flash not SDcard.
Your issue link https://forum.micropython.org/viewtopi ... 4#p16284
And more thing i want to bring in notice is that, I am booting from flash not SDcard.
-
- Posts: 118
- Joined: Wed Dec 27, 2017 8:52 am
Re: STM32F407Disc : Write data on LCD
Hiii Sir,
I manually created a sub-folder named "uasyncio" in flash drive and pasted init.py , core.py, queues.py, synchro.py in that sub folder.
So now when i use your lcd example, its working Thankyou sir for help.
But do let me know, I did right step by creating sub folder in flash and pasting necessary files (i.e __init__,core,queues,synchro) OR is their any easier way ?
And as your program is for 4-bit mode, can i implement 8-bit mode by making necessary changes ? And do you have any idea why my synchronous LCD program didn't worked?
Once again THANKYOU
I manually created a sub-folder named "uasyncio" in flash drive and pasted init.py , core.py, queues.py, synchro.py in that sub folder.
So now when i use your lcd example, its working Thankyou sir for help.
But do let me know, I did right step by creating sub folder in flash and pasting necessary files (i.e __init__,core,queues,synchro) OR is their any easier way ?
And as your program is for 4-bit mode, can i implement 8-bit mode by making necessary changes ? And do you have any idea why my synchronous LCD program didn't worked?
Once again THANKYOU