How to detect if LCD is connected?

I have an LCD connected via I2C, and so when the microcontroller boots up, I do:

    pinMode(Pins::LCD_RESET_LINE, OUTPUT); // Set D4 on Arduino to Output (4D Arduino Adaptor V2 - Display Reset)
    digitalWrite(Pins::LCD_RESET_LINE, 0); // Reset the Display via D4
    delay(100);
    digitalWrite(Pins::LCD_RESET_LINE, 1); // unReset the Display via D4

Then a bit later I do:

    Serial.begin(200000); // Serial0 @ 200000 (200K) Baud
    genie.Begin(Serial); // Use Serial0 for talking to the Genie Library, and to the 4D Systems display

    genie.AttachEventHandler(EventHandler); // Attach the user function event Handler for processing events

I'm trying to figure out how to detect the presence of the LCD. Unfortunately the function "Genie::Begin" returns void and so I don't know if it was successful.

Anyone got any ideas here?

If you are using UNO and have connected the I2CLCD with it, then upload the following scanner program; the detection message will appear on the Serial Monitor.

#include <Wire.h>

void setup()
{
  Serial.begin(9600);
  Wire.begin();
  Serial.println("I2C search");
  Serial.println("-------------------------");

  Wire.begin();
  int i2c = 0b0000000;
  for (int i = 0; i < 127; i++)
  {
    Serial.print("Search at [");
    Serial.print(i2c, HEX);
    Serial.print("]: ");
    Wire.beginTransmission(i2c);
    byte busStatus = Wire.endTransmission();
    if (busStatus == 0)
    {
      Serial.println("FOUND!");
      while(1);
    }
    else
    {
      Serial.println("not found");
    }
    i2c++;
  }
}

void loop() {}

That program will tell him if the I2C adapter is present. I don't see how it will tell him if an LCD is actually attached to the adapter.

Don

1 Like

Yes! The scanner program will never see the actual LCD Unit. It will be able to detect the I2C Controller attached with the LCD.

Once the I2C Controller is detected, the OP may upload the following sketch to see if "Forum" message appears on the Topline of the LCD. This is the proof that the the LCD is physically present in the system.

#include<LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() 
{
  lcd.begin();
  lcd.backlight();
  lcd.setCursor(0, 1);  //DPos (0-15), LPos (0-1)
  lcd.print("Forum"); 
}

void loop() 
{
 
}

Yes, that only detects that an I2C Slave is present. It does not check for PCF8574 or LCD.

Bill Perry's diagnostic programs will detect Slave address, typical model number, whether there is an LCD connected, how the LCD is connected, ...

In other words it is pretty comprehensive.
I suspect that the OP simply wants to know if a known backpack is plugged in.

David.

Hi,
Can you post your code please?

Can you post a schematic of your project?
No a Fritzy picture, a image of a hand drawn circuit will be fine, please include ALL power supplies, component names and pinout labels.

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

Please give us more details.
We can't answer your question until we know what h/w you have.
How to detect the device's presence will vary depending on the h/w you are using.
i.e. what type of LCD device are you using, how is it connected, and what library are you using to talk to it?
For example, Is it some kind of graphic LCD?
Is it a hd44780 type display using a PCF8574 based backpack?
etc...
Or is it something else, perhaps a 4d systems device using the serial port rather than i2c ?

--- bill

The LCD is made by "4D Systems", and the model is "gen4-uLCD-43DCT-CLB-AR".

There are four pins from my microcontroller to the LCD:

PA17 - i2c SDA
PA18 - i2c SCL
PA8 - Rx
PA9 - Tx

The i2c connection isn't used, so we're connect by PA8 and PA9.

I wanted to determine at boot-up if the LCD is connected. If the "genie.WaitForIdle()" member function were public instead of private then I'd be able to use it. I had considered editing "genieArduino.h" to change a few member functions from private to public, but in the end I used a different solution.

At boot up, I use "genie.ReadObject" to provoke a response from the LCD. Next I call "genie.DoEvents()", and then inside the event handler I set a global boolean to say we've received an event. Next I check the global boolean continuously for half a second to see if it becomes true. If it becomes true, the LCD is connected.

Anyone got a better idea?

Which is it ?
Serial comms or I2C comms?
Rx/Tx is not I2C it is serial.

Please a link to data/specs of your LCD?

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

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