Using the LCD with InventOne

One of the things that make a good project is it’s user interface. To have a good user interface, you need a good display.

This tutorial would take you through using the InventOne board and an LCD display.

Requirements

  1. LCD 16x2 with I2C serial adapter.
  2. InventOne board.
  3. Jumper wires (Female-Male).
  4. Laptop
  5. Internet

You can get this components from aliexpress, amazon, or ebay, while ordering for the LCD make sure you get the one with the I2C adapter. Please order for your inventone board from this link.

Hardware

An LCD is a liquid crystal display which can be used to display virtually any character (although limited by the amount stored in its memory) the LCD in this project serves as a means to communicate to the user. Am pretty sure google has a chunk of tutorials about liquid crystal displays.

To ease the stress of using an LCD we would be using an I2C adapter with the LCD, this reduces the number of pins needed to use the LCD to about four at the cost of having to download a new library to use the adapter. The adapter allows us to move most of the LCD control to software, for instance when the backlight jumper is in, to turn on the LCD backlight you can just do “lcd.backlight();” and it comes ON and "lcd.nobacklight()" and it turns OFF, awesome right? I know.

The LCD is powered with a 5V voltage source, gnd from the LCD goes to gnd on the board. Finally, the SDA and SCL pins are to be connected to any digital pin on the board (just make sure you put the corresponding pin configuration in your code); in this project my connections are as follows:

VCC -> 5v

SDA -> D4

SCL -> D3

GND -> GND

 

Circuit diagram for connecting inventone to LCD
Liquid Crystal Display with InventOne

 

 Software

Since we are using an I2C serial adapter, most of the work would be done in software. The first thing is to ensure that you have a working IDE, check out this great tutorial on how to setup your IDE for the InventOne board. After that you need to get a library that supports LCD I2C, so we found this cool library; LiquidCrystal_I2C  just navigate to Sketch, Include Library, Manage Libraries options in the Arduino IDE then search for LiquidCrystal_I2C. Install the library and the IDE handles the rest.

I2C Library for LCD display
Final result upon adding I2C library for LCD

 

Next we need to get the I2C address your inventone board assigns to the LCD, run this scan code it does all the job for you.

#include <Wire.h>

void setup()
{
  Wire.begin(D4, D3);  //Wire.begin(sda_pin, scl_pin);

  Serial.begin(115200);
  Serial.println("\nI2C Scanner");
}

void loop()
{
  byte error, address;
  int nDevices;

  Serial.println("Scanning...");

  nDevices = 0;
  for(address = 1; address < 127; address++ )
  {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.print(address,HEX);
      Serial.println(" !");

      nDevices++;
    }
    else if (error==4)
    {
      Serial.print("Unknow error at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.println(address,HEX);
    }
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");

  delay(3000); // wait 5 seconds for next scan
}

 When you have successfully gotten the address do well to adjust the address field in the “LiquidCrystral_I2C lcd (address, lcd_length, lcd_width);” section of the code below.

// include the library 
#include <LiquidCrystal_I2C.h>

// initialize the LCD with the LCD address and the LCD //type
LiquidCrystal_I2C lcd(0x3F, 16, 2);
//The function works like this:                            //LiquidCrystal_I2C lcd(address, length, width);
//length and width are those of the LCD

void setup() {

  Wire.begin(D4, D3);   //Wire.begin(sda_pin, scl_pin);
  // Initialize the LCD
  lcd.init();
  // Turn ON the LCD back light

  lcd.backlight();
}

void loop() {
  //The LCD is indexed from 0, hence (0,0) represents the topmost 

  //left corner of the LCD
  lcd.setCursor(0, 0); //set cursor to column 0,line 0
  lcd.print("Welcome to InvenTech");
  lcd.scrollDisplayLeft();
  delay(500);
}

Awesome you can now run the code, it does exactly what you type in the “lcd.print()” function. We have added the "lcd.scrollDisplayLeft()" to add some effect to the displayed text.

Lets run through the code real quick:

First we include the required library, next we tell the library the I2C address of the LCD and the size of the LCD via "LiquidCrystal_I2C lcd(0x3F, 16, 2);" note that my own address is 0x3F yours might be different do well to run the scan. "lcd.init();" is a function needed to make things work effectively "lcd.backlight()" puts ON the backlight (the green light). To properly place our text on the LCD, we need to first set the cursor location to the beginning of the LCD we do this with the "lcd.setCursor()" function. Finally, use "lcd.print()" to print on the LCD as an exercise try figuring out what the last two functions do. 

Final project "Welcome to InvenTech"

Complete project prints "Welcome to InvenTech"

Great job, should you have any issue setting up this project you can place a comment in the comment section below. You'd get a response as soon as possible.