Git Product home page Git Product logo

lcdi2c's Introduction

Linux kernel module for alphanumeric LCDs on HD44780 and I2C expander attached. Module supports LCDs with PCF8574 based expanders attached.

The module requires kernel version 3.x or higher, access to I2C bus on destination machine (module was tested on RaspberryPI 2 with kernel 4.1 and i2c_bcm2708 already loaded). It is currently able to drive only one LCD at once, however you have a choice which LCD you would like to drive by this module, using proper module option.

requirements

  • Running Linux Kernel and its source code. Version 3.x or higher is supported.
  • Prepared Kernel source for modules compilation.
  • Already loaded kernel modules for i2c bus (for example i2c_bcm2708 is the default module for Raspberry Pi) and i2c-dev if you want to test LCD before module compilation.

compilation

  • Install DKMS toolset (sudo apt install dkms - for Ubuntu and all Debian-ish distros)

  • Checkout the repo somewhere within your directory tree:

    git clone https://github.com/lucidm/lcdi2c.git lcdi2c-1.0.1

  • Copy the clone to /usr/src:

    sudo cp -r lcdi2c-1.0.1 /usr/src/

  • Add source of the module to the DKMS build system:

    sudo dkms add -m lcdi2c -v 1.0.1

  • Finally, install the module on default path:

    sudo dkms install -m lcdi2c -v 1.0.1

  • Connect the expander to power supply and i2c bus, go to examples and run

    python lcddev.py

module arguments

  • Module expects some arguments to be set before loading. If none of them is given, module will load default values, which may, or may not be suitable for your particular LCD back board. If you want to read more about module parameters run command "modinfo lcdi2c" which will display short description about module it self and arguments you can set.

  • busno - bus number, same as in proof application.

  • address - I2C expander address, default set to 0x27

  • pinout - array of number of pins configuration. Not all expanders are configured the same, so you have to be prepared for different pin configurations, this parameter will help you to make this out. This parameter is a list of numbers representing pshysical pin number of the expander chip, connected to your LCD control lines in order given order: RS,RW,E,BL,D4,D5,D6,D7. So for example, if your expander pins are pshysically connected in following configuration: D4 = PIN.0, D5 = PIN.1, D6 = PIN.2, D7 = PIN.3, RS = PIN.4, RW = PIN.5, E = PIN.6, BL = PIN.7, you should set this argument to: 4,5,6,7,0,1,2,3. Pin BL is used for switching backlight of an LCD. Default value is: 0,1,2,3,4,5,6,7 some popular cheap expanders (usually with black solder mask on PCB) use this pin configuration.

  • cursor - set to 1 will show cursor at start, 0 - will prevent from displaying the cursor. Default set to 1

  • blink - 1 will blink current character position, 0 - blinking character will be disabled. Default set to 1

  • major - driver will register new device in /dev/i2clcd, you can force major number of the device by using this configuration option or leave it for kernel to decide. Preffered is not to give this parameter and let the kernel decide. You can later read the number form /sys filesystem.

  • topo - LCD topology, same as described in "testing" section. Default set to 4 (16x2).

/sys device interface

  • Module has two sets of interfaces you can interact with your LCD. It registers /dev/lcdi2c character device, which you can open and manipulate using standard open/close/read/write/ioctl quintet, or through /sys interface. However you are able to use /dev/lcdi2c device, /sys interface is preffered. Let's work out /sys interface first. Once module is loaded, driver will register new class devices called "/sys/class/alphalcd" in which subdirectory "lcdi2c" will be created.

  • "/sys/class/alphalcd/lcdi2c" is the directory containing all interace files required to interact with LCD, here is alphabetically ordered list of files with short descritpiion:

    • brighness - write "0" to this file to switch backlight off, any value different from 0 up to 255 will switch backlight on.

    • blink - write "0" to switch blinking character off, "1" to switch it on. Reading this file will tell you about current status of blinking.

    • clear - write only, writing "1" to this file will clear LCD.

    • cursor - write "0" for switch display cursor off, "1" for switch cursor on. Reading this file will tell you about current status of the cursor.

    • customchar- HD44780 and its clones usually provide way to define 8 custom characters, this file will let you to define those characters. This file is binary, each character consists of 9 bytes, first byte informs about character number (characters have numbers from 0 to 7), next eight bytes is bitmap definition of the character itself. Next 9 bytes repeats this pattern for another character. Total length of this file is 72 bytes. Writing to this file will make you able to define your own set of new 8 characters. If you want to define new bitmat for a character, write at least 9 bytes, first byte is character number you'd like to change, next 8 bytes defines bitmap of the character. You are allowed to define more than one character per write, but keep in mind, you're always writing 9 * n bytes, where n is number of characters you'd like to define.

    • data - driver uses internal buffer which is 1:1 internal LCD RAM mirror, everything you write to LCD through driver interface will be represented in this file. You can also write to this file, and all that you wrote would be visible on the display. Keep in mind, size of RAM of LCD is limited only to 104 bytes. Internal RAM organization depends on "topo" parameter, however reading this file will represent what is actually on the screen, and writing to it will have 1:1 representation on the LCD, configuration of this buffer depends on current LCD display topology (for some displays, not all bytes in RAM are used to display data and it's true for this buffer file too). If you want to know more about this kind of displays RAM organization, please read link below http://web.alfredstate.edu/weimandn/lcd/lcd_addressing/lcd_addressing_index.html which will greatly explain how RAM organization differs in different LCD types.

    • dev - description of major:minor device number associated with /dev/lcdi2c device file.

    • home - writing "1" will cause LCD to move cursor to first column and row of LCD.

    • meta - description of currently used LCD. You can only read this file to get current LCD configurartion.

    • position - this file will help you to set or read current cursor position. This file contains two bytes, value of first byte informs about current cursor position at column, second byte contain information about current cursor position at row. Writing two bytes to this file, will set cursor at position.

    • reset - write only file, "1" write to this file will reset LCD to state after module was loaded.

    • scrollhz - scroll horizontally, write "1" to this file to scroll content of LCD horizontally by 1 character to the right, scrolling to the left is made by writing "0" to this file. This scrolling technique will not change contents of internal RAM of your display, so "data" file will also keep its content intact. Opposite character which leave display during the scroll will appear on the on the other outermost position, so this scroll always keeps information on the screen. This is the internal HD44780 mechanism.

/dev/lcdi2c device interace

  • Module has alternative interface to drive connected LCD. It registers /dev/lcdi2c device file, which you're able to write to or read from. Typical method for accessing such devices is to use open() function, complementary close() function, read() and write() functions. To be able to use rest of features of HD44780 some ioctls commands are provided. List of all suprted IOCTLS commands with codes is available through /sys/class/alphalcd/lcdi2c/meta file under IOCTLS: section. Command codes repeat functionality of /sys interface. However some are unavailable, like "meta" for example. Reading and writing to the device is also different, you should write to it using write() function and complementary read() function to read data from device. Below is a list of supported IOCTL commands:

    • CLEAR - writing "1" as argument of this ioctl, will clear the display

    • HOME - writing "1" as argument of this ioctl, will move cursor to first column and row of the display

    • RESET - writing "1" will reset LCD to default state

    • GETCHAR - this ioctl will return ASCII value of current character (character cursor is hovering at)

    • SETCHAR - this ioctl will set given ASCII character at position pointed by current cursor setting

    • GETPOSITION - will return current cursor position as two bytes, value of first byte represents current column, second one - current row

    • SETPOSITION - writing two bytes to this ioctl will set current cursor position on the display

    • GETBACKLIGHT - will return "0" if backlight is currently switched off, "1" otherwise

    • SETBACKLIGHT - "1" written to this ioctl will switch backlight on or if "0" is written, will switch it off

    • GETCURSOR - returns current cursor visibility status, "0" - invisible, "1" - visible

    • SETCURSOR - sets cursor visibility, "0" - invisible, "1" - visible

    • GETBLINK - returns blinking cursor status, "0" - cursors is not blinking, "1" - cursor is blinking

    • SETBLINK - sets or resets cursor blink, "0" - cursor will blink, "1" - cursor will not blink

    • SCROLLHZ - wrtting "0" to this ioctl will scroll screen to the left by one column, "1" - will scroll to the right

    • SETCUSTOMCHAR - allows to define new character map for given character number. This ioctl expects 9 bytes of data exactly, first byte is character number eight subsequent bytes defines actual bitmap of font. This control differs from "customchar" in a way, that you cannot send more than one character definition at once. If you want to define more than one character, just call this ioctl multiple times for each character you would like to define.

media

Ruby GEM

Francesc Oller

lcdi2c's People

Contributors

lucidm avatar gandalfdg avatar

lcdi2c's Issues

Increase speed

Maximum execution time of a data write after sending the instruction is 37 microseconds, but we seem to be sleeping for 50 microseconds, and not checking the busy flag. HD44780 documentation suggests that time to execute the next instruction will be longer if a new instruction is written while the busy flag is high.

  • investigate the frequency of the raspberry pi's I2C bus
  • see if we can tighten writing by reading the busy flag without sleeping, or will that just add more overhead

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.