Help with ic2 and led

Hi all,i have a couple of 1602 led displays both have the ic2 extender board,i need too test them but see no way to do it in the ide,can someone link me a sketch to test them with over ic2?,thanks.

After you install LiquidCrystalI2C library for the 1602 LCD, you will find examples in:

IDE >> FILE >> EXAMPLES >> LiquidCrystalI2C >> (the example sketches)

Also, look on YouTube for examples of I2C displays with Arduino.

See this discussion, I2C is near the end.

1 Like

Here is my LCD test code. It uses the hd44780 library. The advantage of the hd44780 library over the LiquidCrystal_I2C libraries (there are more than one and they are different) is that the hd44780 library will automatically detect the I2C address and the pin mapping between the LCD and the I2C backpack. That makes it very easy to get a display to work.

You will need to install the hd44780 library. It is available for installation via the IDE library manager. How to install a library.

// hd44780 simple "Hello World" by c gounding AKA groundFungus
// hd44780 library see https://github.com/duinoWitchery/hd44780
// the hd44780 library is available through the IDE library manager
// if there are other devices on the I2C bus and one of those devices 
// has a lower I2C address than the LCD, that device could be detected 
// as the LCD. In that case simply put the LCD address in the constructor.

#include <Wire.h>
#include <hd44780.h>                       // main hd44780 header
#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class header

hd44780_I2Cexp lcd; // declare lcd object: auto locate & auto config expander chip

// LCD geometry
const int LCD_COLS = 16;
const int LCD_ROWS = 2;

void setup()
{
   lcd.begin(LCD_COLS, LCD_ROWS);
   lcd.clear();
   lcd.print("Hello World");
   lcd.setCursor(0, 1);
   lcd.print("Millis ");
}

void loop()
{
   updateLCD();
}

void updateLCD()
{
   static unsigned long lcdTimer = 0;
   unsigned long lcdInterval = 500;  // update 2 times per second
   if (millis() - lcdTimer >= lcdInterval)
   {
      lcdTimer = millis();
      lcd.setCursor(8, 1);
      lcd.print("       "); // overwrite old data
      lcd.setCursor(8, 1);  // reset the cursor
      lcd.print(millis());
   }
}

Path to the diagnostic program, the hello world program and the documentation for the hd44780 library.

2 Likes

does this use pins A$+A5 for the coms too the i2c board?

Just need a simple sketch to say anything over i2c to the lcd,its just to see if it works,had it working years ago with a coil winder program but thats long gome,it was using a4 and 5 if i remember ok.

For an Uno or Nano, yes. Mega uses pins 20 and 21. For other boards, consult their datasheets.
Which Arduino do you have?

I posted a simple sketch. If you use a LiquidCrystal library sketch it may not work without some extra effort. The hd44780 library may seem complicated, but in the long run is easier to use.

i have a uno ok.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.