This is an old revision of the document!
Whatever you do, you expect to have some output of the system. Sometimes there is a blinking LED, sometimes information about connected/disconnected network and some other time simply trace algorithm progress. In laboratories where you have physically connected MCU to your programming device (i.e. computer), you usually would choose Serial port to report about what is going on. However here all you have is access via the video stream. Perhaps those are reasons you will use this LCD display in your every lab work.
This hands-on lab guide is intended for the Beginners but other target groups may benefit from it, treating it as a tool for advanced projects.
There are no other prerequisites than LCD I2C library. Mind, LCD is controlled via the I2C bus. LCD Display is 4×20 characters. LCD is controlled via I2C extender: LCM1602. The I2C extender address is 0x3F and the I2C bus is connected to the pins D1 and D2 (D1 is SCL and D2 is SDA).
Initialize LCD screen, clear it then write some fancy text on it, i.e. “Hello IOT!” in the first line then your first name in the second line and the name of the city you're in, in the third. In the fourth line, print right-aligned number of loop iterations (delay it for 1 second between updates - yes, 1, to observe video stream lag and delays.
You should see the texts in the camera and ticking counter.
There are no special steps to be performed.
Include lcd driver library:
#include <LiquidCrystal_I2C.h>
Instantiate software controler component for the LCD display:
LiquidCrystal_I2C lcd(0x3F,20,4); // set the LCD address to 0x3F for a 20 chars and 4 line display
Declare some variables: counter i, its length n and buffer for the into to string conversion:
int i = 0; char buffer [50]; int n;
We will use them in further part of the code.
Initialize display - we suggest to do it in setup() function:
... lcd.init(D2,D1); // initialize the lcd I2C lcd.backlight(); // switch on the backlight ...
Clear the contents, set cursor and draw static text - still in setup() function:
... lcd.home(); lcd.print("Hello IOT!"); lcd.setCursor(0, 1); lcd.print("James Bond here"); lcd.setCursor(0,2); lcd.print("London"); ...
Implement loop() to draw number of loop executions:
... i++; n=sprintf(buffer,"%d",i); lcd.setCursor(20-n,3); lcd.print(i); delay(1000); ...
Observe text, its position and counter ticking in lower, right corner.