Page 1 of 3

Anyone working on HD44780 library?

Posted: Fri Aug 01, 2014 11:25 pm
by CRImier
I've received my board yesterday. It's great - though I might need to upgrade its firmware ;-) I've also got one HD44780-based 16x2 display (without I2C converter, unfortunately). I guess this library just needs to exist, and I've read through LiquidCrystal source - it will be quite easy to just rewrite it from C to Python as it's easy to read and understand. The question is - is somebody working on that? I'm asking because I'm sure neither that person neither me would like to waste time on what somebody's doing already =)
If not, I start tomorrow ;-)

Re: Anyone working on HD44780 library?

Posted: Fri Aug 01, 2014 11:38 pm
by dhylands
I wrote a python library which talks to an HD44780 based display which is connected over i2c. This was for the BeagleBoneBlack, and used an LCD module similar to this one

The library is split into 2 parts. The lcd.py file knows what commands and stuff to send to the LCD, but not how to get them there.
The i2c_lcd.py file knows how to send commands via i2c to the lcd panel

You can write a replacement for the i2c_lcd.py which talks to the LCD connected directly.

I should port the i2c layer to the pyboard.

Re: Anyone working on HD44780 library?

Posted: Sat Aug 02, 2014 12:02 am
by CRImier
Aha, clear! Thank you for the code! I guess for directly connected display library I'll copy LiquidCrystal interface because it'll be easier for Arduino folks to rewrite their code if they move to different board, but your code might make an excellent base for LiquidCrystal_I2C =)

Re: Anyone working on HD44780 library?

Posted: Sat Aug 02, 2014 6:26 am
by dhylands
I added a pyb_i2c_lcd.py file and pyb_i2c_lcd_test.py to my github repository.

I posted a small video showing it workng

Re: Anyone working on HD44780 library?

Posted: Sat Aug 02, 2014 10:46 am
by CRImier
Nice! Do you consider passing pyb.I2C class object to a constructor a good practice? If so, I guess I've got some pull requests to make =)

Re: Anyone working on HD44780 library?

Posted: Sat Aug 02, 2014 5:09 pm
by dhylands
CRImier wrote:Nice! Do you consider passing pyb.I2C class object to a constructor a good practice? If so, I guess I've got some pull requests to make =)
Not sure what you mean? Send the PRs anyways. I'm happy to review and discuss. I have lots of C and C++ experience and not so much python, so I'm still learning to do things in the "pythonic" way.

I wanted to pass an instance of the pyb.I2C class into I2cLcd since when you're using I2C you typically have multiple devices on the bus, so you don't want them each to initialize the bus. So I could have multiple LCDs, or an LCD and a temperature sensor, or whatever.

Re: Anyone working on HD44780 library?

Posted: Sun Aug 03, 2014 7:37 am
by dhylands
I got 4-bit and 8-bit mode working usng GPIO pins.

In my case I was using a 4x20 LCD. I uploaded a youtube video.

Adding support for the LiquidCrystal API seems like a reasonable thing to do.

Re: Anyone working on HD44780 library?

Posted: Tue Aug 05, 2014 2:11 am
by UltraBob
Glad I looked at the forums, I had just been starting to write support for an LCD using 4-bit or 8-bit mode. Now instead I'll dig in and try to figure out how to use what you've already done. Once again Dave saves the day!

Re: Anyone working on HD44780 library?

Posted: Tue Aug 05, 2014 4:26 am
by UltraBob
I'm not yet finding the issue, but it seems like as soon as I put the lcd module into the libs directory, importing GdioLcd causes the board to freeze with all LEDs on the board lit up. It seems to only work for me if I keep the module files in my root directory. Am I doing something wrong, or is this perhaps a bug?

Re: Anyone working on HD44780 library?

Posted: Tue Aug 05, 2014 6:10 am
by dhylands
I occasionally get syntax errors on lines that are fine (although these may have been caused by this bug: https://github.com/micropython/micropython/issues/788 (on non-DEBUG builds it doesn't assert, it just corrupts some memory)

This seems to happen after doing a Control-D, and goes away if I hit the reset button.

Are you copying them to the /lib directory on the sdcard or the lib directory on the internal flash?

I tested on the internal flash, so I see:

Code: Select all

Micro Python v1.2-65-g6c70511 on 2014-08-04; PYBv1.0 with STM32F405RG
Type "help()" for more information.
>>> import os
>>> os.listdir('/flash/lib')
['lcd.py', 'pyb_gpio_lcd.py', 'pyb_gpio_lcd_test.py']
>>> import pyb_gpio_lcd_test
This was using today's build (just a regular build).

Perhaps try this:
- Build and flash the latest (do a make clean and then a make)
- Clear out the internal /flash (Mode 3 described here: http://micropython.org/doc/general)
- From the PC, create the lib directory
- copy lcd.py, pyb_gpio_lcd.py, and pyb_gpio_lcd_test.py to the lib directory
- Press the reset button
- Do:

Code: Select all

import pyb_gpio_lcd_test
pyb_gpio_lcd_test.test_main()
Do you see a problem?