lcd module that supports i2c interface

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
BrendanSimon
Posts: 33
Joined: Wed Sep 07, 2016 10:46 am

lcd module that supports i2c interface

Post by BrendanSimon » Fri Dec 09, 2016 12:32 pm

Is there a good LCD module that works with the I2C interface ?

I found `charlcd` on PyPI and it supports various interfaces (parallel and i2c) on Linux. I ported it to work with MicroPython. It works, but it is quite slow. I can see the characters being printed on a 20x4 display.

The implementation writes each I2C byte as a single byte from the python module. I think it would be much faster if the bytes were accumulated into a byte buffer, and all bytes written to I2C via the I2C.write(buf). Even if it was a line at a time, rather than calling I2C.write(byte) for each byte.

Does anything exist already that people may be using?

Thanks, Brendan.

User avatar
deshipu
Posts: 1219
Joined: Thu May 28, 2015 5:54 pm

Re: lcd module that supports i2c interface

Post by deshipu » Sat Dec 10, 2016 8:06 pm

The SSD1306 and similar modules have an I2C interface (depends on the particular module, the chip supports several modes, but not all modules have all the pins broken out). It's not an LCD display, but an OLED display (it doesn't rely on backlight, instead each pixel is a separate LED), but I guess that's a technical detail that is not that important. They tend to be rather small though (although there are some oled displays that are much larger in that family).

Generally speaking, I²C is rather slow and inefficient, so for driving larger displays with more pixels usually SPI or parallel interface are preferred.

BrendanSimon
Posts: 33
Joined: Wed Sep 07, 2016 10:46 am

Re: lcd module that supports i2c interface

Post by BrendanSimon » Sun Dec 11, 2016 9:43 am

I can see how my question is a little confusing. What I was asking about was a Python module for controlling an LCD with an I2C interface.

I have a 2004A LCD that I purchased on eBay and it uses I2C (the ebay headline mentions SPI/I2C, but it only supports I2C :( )

I got it working the `charlcd` python module I found on PyPi, but it is slow due to its design, so I wanted to know if there other LCD Python modules around that work with MicroPyton, before going off and writing my own (or reworking charlcd).

User avatar
dhylands
Posts: 2494
Joined: Mon Jan 06, 2014 6:08 pm
Location: Shuswap, BC, Canada
Contact:

Re: lcd module that supports i2c interface

Post by dhylands » Sun Dec 11, 2016 10:03 am

If it's compatible with the HD44780 style LCD then I have a variety of drivers over here:
https://github.com/dhylands/python_lcd
You may need to make changes depending on the i2c module used and how it's wired up.

BrendanSimon
Posts: 33
Joined: Wed Sep 07, 2016 10:46 am

Re: lcd module that supports i2c interface

Post by BrendanSimon » Wed Dec 14, 2016 10:46 am

Yes, it is compatible with the HD44780. It has the backpack with the i2c port expander on it.

I had a look at your code and it looks well designed, however it uses the same approach as `charlcd`, which writes each byte one-by-one from Python land. I was looking for something that might use the machine I2C API, with `writeto()` method, which can take a buffer, and presumably hit the I2C bus at a faster rate from C land. It means accumulating the commands/data in a buffer first, then calling `writeto()`.

I will have a crack at porting your code and/or `charlcd` and see how it goes and what kind of performance improvement I get (if any).

Thanks, Brendan.

BrendanSimon
Posts: 33
Joined: Wed Sep 07, 2016 10:46 am

Re: lcd module that supports i2c interface

Post by BrendanSimon » Sun Dec 18, 2016 1:20 am

I actually ran your test code on my board, modified test app for 4x20 display, and it works great. It is noticeably faster that the `charlcd` module that I ported, so now I don't feel the urgent need for a `machine.IC2.write(buf)` implementation :)

A `machine.I2C.write(buf)` implementation may not even be faster?
I guess it could be if buffering of lines/screens is done efficiently in python and effectively blitting the data using `machine.I2C.write()`?

Thanks, Brendan :)

BrendanSimon
Posts: 33
Joined: Wed Sep 07, 2016 10:46 am

Re: lcd module that supports i2c interface

Post by BrendanSimon » Sun Dec 18, 2016 1:39 am

David (@dhylands),

I want to add your lcd code to my github micropython page, and provide some examples that use my keyboard modules, etc.

https://github.com/BrendanSimon/micropython_experiments

What's the best way to do that? A git sub-module?

Thanks, Brendan.

User avatar
dhylands
Posts: 2494
Joined: Mon Jan 06, 2014 6:08 pm
Location: Shuswap, BC, Canada
Contact:

Re: lcd module that supports i2c interface

Post by dhylands » Sun Dec 18, 2016 1:49 am

Yeah - if you want to use the LCD code exactly "as-is" then using a submodule works well.

If you want to make changes to the code (that wouldn't be upstreamable), then just copying the files is probably simpler.

BrendanSimon
Posts: 33
Joined: Wed Sep 07, 2016 10:46 am

Re: lcd module that supports i2c interface

Post by BrendanSimon » Sun Dec 18, 2016 2:49 am

ok. Does sub-module not allow you to make changes and submit pull-requests ?

If not, then I guess I could fork your repo, and do a sub-module from my fork, and if there are any changes I think are worthy of pushing upstream then I can submit a pull-request from my fork.

User avatar
dhylands
Posts: 2494
Joined: Mon Jan 06, 2014 6:08 pm
Location: Shuswap, BC, Canada
Contact:

Re: lcd module that supports i2c interface

Post by dhylands » Sun Dec 18, 2016 4:15 am

You can submit pull requests from any github repository, whether a sub-module or not.

You can also fork the repository (which you need to do to submit PRs anyways), make your forked repo be the submodule, and keep changes on a branch even if they aren't taken in the main repo.

Post Reply