Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to print on LCD #13

Open
nikhil1983 opened this issue Dec 29, 2017 · 9 comments
Open

Unable to print on LCD #13

nikhil1983 opened this issue Dec 29, 2017 · 9 comments

Comments

@nikhil1983
Copy link

nikhil1983 commented Dec 29, 2017

Hello,
I am a newbie in Micropython. I am working on STM32F407Discovery board. I wanted to display character on LCD (16x2) display. I tried to use the module given by you, but its not displaying any character on LCD.

Below is code ..

from pyb import Pin, delay, millis
from pyb_gpio_lcd import GpioLcd

#Configuring LCD Pins
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_DOWN)
d1 = pyb.Pin('PE9', Pin.OUT_PP,Pin.PULL_DOWN)
d2 = pyb.Pin('PE10', Pin.OUT_PP,Pin.PULL_DOWN)
d3 = pyb.Pin('PE11', Pin.OUT_PP,Pin.PULL_DOWN)
d4 = pyb.Pin('PE12', Pin.OUT_PP,Pin.PULL_DOWN)
d5 = pyb.Pin('PE13', Pin.OUT_PP,Pin.PULL_DOWN)
d6 = pyb.Pin('PE14', Pin.OUT_PP,Pin.PULL_DOWN)
d7 = pyb.Pin('PE15', Pin.OUT_PP,Pin.PULL_DOWN)

def test_main():
"""Test function for verifying basic functionality."""
print("Running test_main")
lcd = GpioLcd(rs,en,d0,d1,d2,d3,d4,d5,d6,d7,2,16)
lcd.putstr("It Works!\nSecond Line")
delay(3000)
lcd.clear()
count = 0
while True:
lcd.move_to(0, 0)
lcd.putstr("%7d" % (millis() // 1000))
delay(1000)
count += 1

I have initalised the LCD pins correctly and the code is getting executed properly, still i am unable to understand why nothing gets printed on LCD. Can anyone help me in the above code and how to implement on STM32F407disc board.

Hoping for some quick help..

@dhylands
Copy link
Owner

I missed this earlier - sorry for the late reply. When you power on the LCD do you see a row of black squares. If not, then you need to adjust the contrast voltage until you do. If you don't see the black squares at poweron then you will never see anything when the LCD is working properly.

@nikhil1983
Copy link
Author

Hey,
Yes, LCD is working properly, as rows of black square appear when i turn LCD on. But still haven't found any solution to use this module.

I have used async method, published by Sir Peter Hinch and it works well. So sir, if you have discovery board can you try out this module with it.

@dhylands
Copy link
Owner

dhylands commented May 10, 2018

ok - I found a few errors in your script.

1 - You're missing an import pyb or you should be using Pin instead of pyb.Pin
2 - You forgot to pass in the rw_pin and backlight_pin parameters when you call GpioLcd (this is why the example uses named arguments)
3 - There is no need to initialize the output pins. GpioLcd does this already. You can just pass in pyb.Pin('PB1') or pyb.Pin.board.PB1
4 - PULL_UP/PULL_DOWN only apply to input pins

The last 2 points aren't really errors per say. Here's a modified version of your script that works:

from pyb import Pin, delay, millis
from pyb_gpio_lcd import GpioLcd

#Configuring LCD Pins
rs = Pin('PB1')
rw = Pin('PB4')
en = Pin('PB5')
d0 = Pin('PE8')
d1 = Pin('PE9')
d2 = Pin('PE10')
d3 = Pin('PE11')
d4 = Pin('PE12')
d5 = Pin('PE13')
d6 = Pin('PE14')
d7 = Pin('PE15')

def test_main():
  """Test function for verifying basic functionality."""
  print("Running test_main")
  lcd = GpioLcd(rs,en,d0,d1,d2,d3,d4,d5,d6,d7,rw,None,2,16)
  lcd.putstr("It Works!\nSecond Line")
  delay(3000)
  lcd.clear()
  count = 0
  while True:
    lcd.move_to(0, 0)
    lcd.putstr("%7d" % (millis() // 1000))
    delay(1000)
    count += 1

@nikhil1983
Copy link
Author

Hello thanks, its working. just wanted to know how can we shift our message right or left on LCD using this module ?

@dhylands
Copy link
Owner

The HD44780 supports a MOVE display/cursor left./right command. I don't have a wrapper for it in LcdApi, but I was able to get it to scroll using:

      lcd.hal_write_command(lcd.LCD_MOVE | lcd.LCD_MOVE_DISP)

or

      lcd.hal_write_command(lcd.LCD_MOVE | lcd.LCD_MOVE_DISP | lcd.LCD_MOVE_RIGHT)

@nikhil1983
Copy link
Author

But the issue with above command are once the character are shifted out from right, the shifted out character are not getting shifted in from left.

So if i want to make a scrolling display, "ABCD" once the D goes out of 16th column, in the next loop D Should come in 1st column and C in 16th Column.

@dhylands
Copy link
Owner

Yep - that's the same behaviour I see as well.

The hardware appears to be inserting spaces, which means that you'd need to use the cursor positioning commands and draw the character that you want shifted in

@nikhil1983
Copy link
Author

Okay. here are some function i created using your driver file.

def main():
ask25_lcd_driver.ASK25_LCD_Init() #Initalising the LCD
while True:
x = 0
ask25_lcd_driver.ASK25_LCD_Set_Cursor(0, 0) #Setting the Cursor position (row,col)
ask25_lcd_driver.ASK25_LCD_Display_String("ABCD")
ask25_lcd_driver.ASK25_LCD_Shift_Display(Right)
pyb.delay(200)
x+=1
if ( x > 1):
ask25_lcd_driver.ASK25_LCD_Set_Cursor(0,0)
ask25_lcd_driver.ASK25_LCD_Display_String("D")
ask25_lcd_driver.ASK25_LCD_Set_Cursor(0, 0) #Setting the Cursor position (row,col)
ask25_lcd_driver.ASK25_LCD_Display_String("ABC")

So after D gets rolled, i am using cursor positioning command to put the Char D at 0,0 location. But its not happening. Also the delay between the whole String rolled out and string rolling in nearly 4-5 sec.

@dhylands
Copy link
Owner

I suspect that you must have some delays in your code. I can shift in 10 characters in 10 milliseconds.

According to the HD47780 datasheet, when you shift the display, you're actually shifting the DDRAM address. This means that after shifting the display by 1 character right, then the top-left corner is at x=0x27. See https://www.sparkfun.com/datasheets/LCD/HD44780.pdf page 12 for details.

Here's the sample code I tested with (using the 8-bit parallel GPIO on the STM32F407 Discovery board):

import pyb

def test_main():
    """Test function for verifying basic functionality."""
    print("Running test_main a")
    rs = pyb.Pin('PB1',Pin.OUT_PP)
    rw = pyb.Pin('PB4', Pin.OUT_PP)
    en = pyb.Pin('PB5', Pin.OUT_PP)
    d0 = pyb.Pin('PE8', Pin.OUT_PP)
    d1 = pyb.Pin('PE9', Pin.OUT_PP)
    d2 = pyb.Pin('PE10', Pin.OUT_PP)
    d3 = pyb.Pin('PE11', Pin.OUT_PP)
    d4 = pyb.Pin('PE12', Pin.OUT_PP)
    d5 = pyb.Pin('PE13', Pin.OUT_PP)
    d6 = pyb.Pin('PE14', Pin.OUT_PP)
    d7 = pyb.Pin('PE15', Pin.OUT_PP)
    rw.value(0)
    lcd = GpioLcd(rs_pin=rs,
                  enable_pin=en,
                  d0_pin=d0,
                  d1_pin=d1,
                  d2_pin=d2,
                  d3_pin=d3,
                  d4_pin=d4,
                  d5_pin=d5,
                  d6_pin=d6,
                  d7_pin=d7,
                  num_lines=2, num_columns=16)
    lcd.putstr("It Works!\nSecond Line\nThird Line\nFourth Line")
    t1 = pyb.millis()
    for i in range(10):
      lcd.move_to(0x27 - i, 0)
      lcd.hal_write_data(ord('0') + i)
      lcd.hal_write_command(lcd.LCD_MOVE | lcd.LCD_MOVE_DISP | lcd.LCD_MOVE_RIGHT)
      #delay(1000)
    t2 = pyb.millis()
    print('Delta =', t2 - t1, 'msecs')
    pyb.delay(1000)
    lcd.clear()
    count = 0
    while True:
        lcd.move_to(0, 0)
        lcd.putstr("%7d" % (millis() // 1000))
        delay(1000)
        count += 1

test_main()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants