Raspberry PI + YwRobot Arduino LCM1602 IIC V1 HD44780 LCD

Finally i have some time to write a new post.

Let's start:
I bought a YwRobot Arduino LCM1602 IIC V1 HD44780 LCD from amazon for 6,57 €

It has a I2C interface (so it will use just 2 cables, SDA & SCL, + 2 for VCC & GND).

I found some tutorials online, but they were for Arduino or python... NOTHING FOR C!!
So i decided to write a damn C lib for this component.
I had to cross check various codes/datasheets to understand how it works, but at the end i wrote it.
So, this is my lib! Enjoy it ;)
You can grab from the link at the end of the post.

    #include "stdio.h"  
    #include "string.h"  
    #include "i2c.h"  
    #include "lcd.h"  
    #define I2C_FILE_NAME "/dev/i2c-0"  
    const char* txt[]  = {  
        "I work on the PI",  
        "via liblcm1602.a"  
    int main(){  
        int i2c_dev;  
        lcd lcd0;  
        // 0x27 is the address of the i2c device  
        i2c_dev = open_i2c(I2C_FILE_NAME, 0x27);  
        if(i2c_dev <0){  
           printf("Error: %d\n", i2c_dev);  
           return 1;  
        lcd_init(&lcd0, i2c_dev);  
        lcd_print(&lcd0, txt[0], strlen(txt[0]), 0);  
        lcd_print(&lcd0, txt[1], strlen(txt[1]), 1);  
        return 0;  


  1. Hello,

    First of all thank you so much for your code example. I had the same problem, i was looking for codes for the LCD and only found phyton codes. And actually I'm prefering C. Your code really helped me a lot!

    But there is one question left: Which datasheets have you used for your code? How do know which registers to set?

    thanks ;)

    1. Here: http://pdf1.alldatasheet.com/datasheet-pdf/view/63673/HITACHI/HD44780.html
      The lcd screen is an HD44780

  2. This comment has been removed by the author.

  3. Thank you! Works for Orange PI PC too. Just have to change i2c_dev = open_i2c(I2C_FILE_NAME, 0x27); - 0x27 to 0x3f

    Is it posible to rotate screen?

  4. i am using codewarrior
    i have freescale kl25z and i am trying to use your lib
    but faild with all those #include XXX
    everytime i imported a missin h file and try to cimpile it says me there are another h file missing etc...


Post a Comment

Popular posts from this blog

Install Package Homebrew

Reversing Wii U Executables