Coder Social home page Coder Social logo

rasplcddriver's Introduction

RaspLCDDriver

Rasberry Pi C++ LCD 20x4 Driver via I2C

More info on my blog: https://blog.monotok.org/raspberry-pi-20x4-lcd-i2c-c-driver/

Here is a list of functions available:

voidlcdSendCommand(unsignedchar command);
voidlcdString(constchar* message);
voidsetCursorPositionRowCol(int row, int col);
voidclearColumnsRowCol(int row, int colToClearTo, int colToClearFrom);
voidblinkCursor();
voidenableUnderlineCursor();
voidclearDisplayClearMem();
voidclearDisplayKeepMem();
voidsetEntryMode();
voidsetDisplayOnCursorOff();
voidset4Bit2Line();
voidset8Bit2Line();
voidmoveCursorRight();
voidmoveCursorLeft();
voidresetCursorPosition();
voidscroll1CharRightAllLines();
voidscroll1CharLeftAllLines();
voidclearLine(int lineNo);

The most important functions available allow you to clear certain parts of the display and then move the cursor to any position. This allows you to write logic to update only what has changed etc.

An example:

I wanted to keep the i2c and LCD parts separate as you don't want to call the LCD driver just to open the i2c bus for another i2c device. As a result the LcdDriver constructor takes a pointer to an i2c object.

int main(int argc, char *argv[])
{
I2cControl *i2c = new I2cControl(1);
LcdDriver lcd(lcdAdd, i2c);

lcd.lcdSendCommand(LCD_BEG_LINE_1);
lcd.lcdString("SensorID:");
lcd.setCursorPositionRowCol(1,11);
lcd.lcdString("Here");

lcd.setCursorPositionRowCol(2,0);
lcd.lcdString("Temp: ");
lcd.setCursorPositionRowCol(2,8);
lcd.lcdString("22.4 C");

lcd.setCursorPositionRowCol(3,0);
lcd.lcdString("Battery: ");
lcd.setCursorPositionRowCol(3,11);
lcd.lcdString("45%");

//Sleep for 4 seconds so we can observe the display
std::this_thread::sleep_for(std::chrono::milliseconds(4000));

//Change battery to the word humidity
lcd.clearColumnsRowCol(3,8,0);
lcd.setCursorPositionRowCol(3,0);
lcd.lcdString("Humidity:");

//Create and draw custom half battery symbol
uint8_t customChar[8] = {
        0x0E,
        0x11,
        0x11,
        0x11,
        0x1F,
        0x1F,
        0x1F,
        0x1F
};
lcd.createCustomChar(1, customChar);
//you might need to sleep for a short while before trying to display the custom char
lcd.setCursorPositionRowCol(4,8);
lcd.lcdSendCustomChar(1);

delete i2c;

return0;
}

rasplcddriver's People

Contributors

monotok avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.