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.
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() {}
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.
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.
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 ?
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.