Git Product home page Git Product logo

pilcd's Introduction

PiLCD

A library for controlling a lcd with a Raspberry Pi, using a lcm1602 backpack

  • Print text to display
  • Add custom characters

Usage

#include "pilcd.h to include library in your code.

int lcd_dev_init(int i2c_num, i2c_addr)
Initiates i2c connection and returns a device number.
i2c-num - device number (ex. 1 for /dev/i2c-1)
i2c-addr - lcd address (normally 0x27)

void lcd_init(int i2c)
Initiates the display.
i2c - device number

int lcd_print_str(int i2c, const char *str, int row, int chars)
Prints a c-string to given row.
i2c - device number
*str - c-string (pointer to char-array)
row - which row to print at
chars - how many chars (ex. strlen(str))

void lcd_add_char(int i2c, unsigned char chr[], int lines)
Adds a custom character to volatile memory.
i2c - device number
chr[] - char-array with character-codes (see below)
lines - how many lines (8 for each character for 5x8 lcd (see below)

###Custom characters

To add custom characters, use the lcd_add_char()-function and supply a character array like the example.

You need to supply all characters each time, so you can't add characters by running the function multiple times.

To print your custom characters, you simply print the number of your characters, starting on 0.

Note: C function strlen uses 0x00 (first custom character) as a null terminator/end of string, so in order to use strlen you have to start your custom characters at position 1, preferebly by adding a blank (8 * 0x00) character.

Example, 3 custom characters (forms a bottle):

unsigned char bottle[] = { 0x0,0x1,0x2,0x2,0x2,0x2,0x2,0x1,
                           0x0,0x1f,0x0,0x0,0x0,0x0,0x0,0x1f,
                           0x0,0x10,0x8,0x7,0x1,0x7,0x8,0x10 };

lcd_add_char(display,bottle,24);

char beer[] = { 0, 1, 2 };
lcd_print_str(display, beer, 1, 3); //row 1, 3 characters

Automatic way to make custom characters

Thanks to

tech2077 blog for making this possible at all.

pilcd's People

Watchers

James Cloos avatar Patrik Höggren avatar

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.