ARDUINO UNO – C++ Usecase

Prerequisite : Basic knowledge of C++ is required to complete the steps here. This particular blog post is for students and hobbyist interested in c++ embedded use case and exploring different low cost projects.  You may follow this by clicking on Follow button on the page.

Key Takeaway : ARDUINO IDE Library  and LCD display

Creating LCD Project : The project creation,build and execute method is similar to earlier blog arduino-uno-10-min-hello

lcd1

Take a note of  LCD module detail at the beginning of  Scroll scatch or source file generated “The LiquidCrystal library works with all LCD displays that are compatible with the Hitachi HD44780 driver. ”  The LCD module should be compatible with this.  Check the datasheet of LCD module under test. Generally LCD module with 16 bit interface should work with this. 

Do a sanity check of GPIO pins with LCD module under test and make sure you initialize the library with the same set of GPIOs.

I will recommend to use Arduino shields wherever a bunch of connections are needed for time sensitive signals. Shields are Arduino PCB form factor based boards that can be plugged on  for extending its features. Avoid the practice shown below if you can get required shield , Otherwise you may face loose connection issue. This is important to save time and efforts.

lcd2

LCD Example source code :

/*The example source code integrates the  LiquidCrystal library with header file*/

// include the library code:
#include <LiquidCrystal.h>

/*And then create instance of this as lcd*/

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

Device setup 

/*The default setup() function of sketch initializes the LCD and prints first hello world*/

void setup() {
// set up the LCD’s number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print(“hello, world!”);
delay(1000);
}

Application code 

/*as the name implies  loop() of sketch will run continuously from top–bottom–top*/

void loop() {
// scroll 13 positions (string length) to the left
// to move it offscreen left:
for (int positionCounter = 0; positionCounter < 13; positionCounter++) {
// scroll one position left:
lcd.scrollDisplayLeft();
// wait a bit:
delay(150);
}

Where is the LCD driver code ? 

Liquid Crystal Library 

You may refer to library installation folder in your PC

C:\Program Files (x86)\Arduino\libraries\LiquidCrystal\src

The header file LiquidCrystal.h declares the class LiquidCrystal and LiquidCrystal.cpp defines all constructor,destructor and functions.

class LiquidCrystal : public Print {
public:
LiquidCrystal(uint8_t rs, uint8_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
LiquidCrystal(uint8_t rs, uint8_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3);

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::
void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS);

void clear();
::::::::::::::::::::::::::::::::::::::
void scrollDisplayLeft();
void scrollDisplayRight();
void leftToRight();
void rightToLeft();
void autoscroll();
:::::::::::::::::::::::::::::::::::::
void setCursor(uint8_t, uint8_t);
virtual size_t write(uint8_t);
void command(uint8_t);

using Print::write;
private:
void send(uint8_t, uint8_t);
void write4bits(uint8_t);
void write8bits(uint8_t);
:::::::::::::::::::::::::::::::::
uint8_t _displaymode;

:::::::::::::::::::::::::::::::::::::::::::::

uint8_t _numlines;
uint8_t _row_offsets[4];
};

#endif

Where to find Arduino GPIO and memory space specific files ?

The Liquidcrystal.h file is linked with Arduino platform specific built-in functions through Arduino.h in :

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino

Further the Arduino platform is linked with Arduino device through  io.h,interrupt,h etc in :

C:\Program Files (x86)\Arduino\hardware\tools\avr\avr\include\avr

Here are few other interesting topics @Embedkari

How to Learn C  practically ? 

How to do web scraping with Python ? 

How to choose sensor, processing device and network for IoT ?

How Computer Vision is  impacting Processor Road MAP ? 

How device driver is related to Operating System ?

How to Learn Linux Device driver coding ? 

How I can practice AVR, ARM, Linux and other Embedded Questions for Interview ? 

How can I start learning RISC-V without purchasing development board ?

How RISC architecture differs in simple and advanced embedded processors ? 

How to use Home Router to understand Embedded Linux Commands ?

Thanks for reading till end. Please provide your feedback regarding this article. Also subscribe  Embedkari for other interesting topics. .

Embedkari has introduced its first low cost technical training .

 

2 comments

  1. Post a schematic of the pin connections also.
    I have a Arduino and a HD44780 compatible LCD.
    Would like to try this out.

    BTW, your old team mate here. 🙂

  2. Nice to hear from you Subrato, The circuit pins are mentioned in example code generated by Arduino. Let me clarify
    * LCD RS pin to digital pin 12 //sanjay: Resistor Select
    * LCD Enable pin to digital pin 11
    * LCD D4 pin to digital pin 5
    * LCD D5 pin to digital pin 4
    * LCD D6 pin to digital pin 3
    * LCD D7 pin to digital pin 2
    * LCD R/W pin to ground
    * 10K resistor ends to +5V and ground //sanjay: Connect Backlight VCC to +5V
    * wiper to LCD VO pin (pin 3) //sanjay: contrast pin variable voltage provision(0 to +5V)
    //sanjay : If you plan to change GPIO port number, you need to change arguments of
    LiquidCrystal lcd(12, 11, 5, 4, 3, 2);//sanjay RS,EN,four data bins(4-bit mode)
    Further reference for LCD: https://electronicsforu.com/resources/learn-electronics/16×2-lcd-pinout-diagram
    Hope this helps. Drop me a line if any issue. As per LinkedIn, It seems that you moved to different organization. Have a Great time -)
    Thanks
    Sanjay

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.