How To Code An I2C LCD

The I2C LCD is a truncated version of the traditional LCD in that the six digital pins typically assigned to the Arduino are eliminated in favor of just two analog pins. In this project we will assemble an Arduino circuit that displays the current day and time on an I2C LCD screen. Use this link to be briefed on assembling the DS3231 RTC as this section focuses on the LCD only. Note that multiple I2C units can be used provided the SCL and SDA pins are connected in parallel as depicted in the sketch below.

Required Items:

I2C LCD        DS3231RTC

 

Fritzing Sketch:

 

I2C LCD Rear View

Note that the Fritzing sketch makes it appear like you have to solder many connections to the LCM1602. This is false as it already comes soldered onto the LCD as seen in the above picture. The blue item you see is the contrast adjustment that requires using a phillips head screw driver to see the text on screen. To connect, link the SDA to the Arduino A4 pin and SCL to the Arduino A5 pin, VCC to 5v and ground to the Arduino ground pin. Ensure that the SCL and SDA pins of your DS3231 are connected in the same way.

LCD/RTC Code:

Copy/paste this code into your IDE, verify port, board, and programmer, then upload.

Be Advised! There has been a recent update distinguishing the old boot loader from the new one as seen in the Tools>Processor menu. If your code doesn’t upload despite verifying configuration, select either the new or old bootloader, then upload.