How to connect i2c 16x2 LCD instead of the regular 16x2 LCD (without i2c) ?

Hi guys;

I’m working on implementing a Vehicle Tracking System based on GSM and GPS, And I really want to know how to make my code work with i2c LCD. Also I don’t understande the role of using the pin 13 in “digitalWrite(13,HIGH) and digitalWrite(13,LOW)”, I tried many times but I decided to ask my question here.
This is the wiring:

This is the code:

#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include<LiquidCrystal.h>
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);

static const int RXPin = 4, TXPin = 3;
static const uint32_t GPSBaud = 9600;
// The TinyGPS++ object
TinyGPSPlus gps;
int temp=0,i;
// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);
String stringVal = "";
void setup(){
  Serial.begin(9600);
  ss.begin(GPSBaud);
  lcd.begin(16,2);
  pinMode(13,OUTPUT);
  digitalWrite(13,LOW);
  lcd.print("Vehicle Tracking");
  lcd.setCursor(0,1);
  lcd.print("    System      ");
  delay(2000);
  gsm_init();
  lcd.clear();  
  Serial.println("AT+CNMI=2,2,0,0,0");
  lcd.print("GPS Initializing");
  lcd.setCursor(0,1);
  lcd.print("  No GPS Range  "); 
  delay(2000);
  lcd.clear();
  lcd.print("GPS Range Found");
  lcd.setCursor(0,1);
  lcd.print("GPS is Ready");
  delay(2000);
  lcd.clear();
  lcd.print("System Ready");
  temp=0;
}

void loop()
{ 
serialEvent();

      while(temp)
      {
        while (ss.available() > 0)
        {
          gps.encode(ss.read());
                if (gps.location.isUpdated())
                {
                 temp=0;
                 digitalWrite(13,HIGH);
                 tracking();
                } 
          if(!temp)
          break;  
        }
      }
      digitalWrite(13,LOW);
}
void serialEvent()
{
  while(Serial.available()>0)
  { 
    if(Serial.find("Track Vehicle"))
    {
      temp=1;
      break;
    }
    else
    {
    temp=0;
    }
  }
}
void gsm_init()
{
  lcd.clear();
  lcd.print("Finding Module..");
  boolean at_flag=1;
  while(at_flag)
  {
    Serial.println("AT");
    delay(1);
    while(Serial.available()>0)
    {
      if(Serial.find("OK"))
      at_flag=0;
    }
    
    delay(1000);
  }
  lcd.clear();
  lcd.print("Module Connected..");
  delay(1000);
  lcd.clear();
  lcd.print("Disabling ECHO");
  boolean echo_flag=1;
  while(echo_flag)
  {
    Serial.println("ATE0");
    while(Serial.available()>0)
    {
      if(Serial.find("OK"))
      echo_flag=0;
    }
    delay(1000);
  }
  lcd.clear();
  lcd.print("Echo OFF");
  delay(1000);
  lcd.clear();
  lcd.print("Finding Network..");
  boolean net_flag=1;
  while(net_flag)
  {
    Serial.println("AT+CPIN?");
    while(Serial.available()>0)
    {
      if(Serial.find("+CPIN: READY"))
      net_flag=0;
    }
    delay(1000);
  }
  lcd.clear();
  lcd.print("Network Found..");
  
  delay(1000);
  lcd.clear();
}
void init_sms()
{
  Serial.println("AT+CMGF=1");
  delay(400);
  Serial.println("AT+CMGS=\"8825737586\"");   // use your 10 digit cell no. here
  delay(400);
}
void send_data(String message)
{
  Serial.print(message);
 delay(200);
}
void send_sms()
{
  Serial.write(26);
}
void lcd_status()
{
  lcd.clear();
  lcd.print("Message Sent");
  delay(2000);
  lcd.clear();
  lcd.print("System Ready");
  return;
}
void tracking()
{
    init_sms();
    send_data("Vehicle Tracking Alert:");
    Serial.println(" "); 
    send_data("Your Vehicle Current Location is:");
    Serial.println(" "); 
    Serial.print("Latitude: ");
    Serial.print(gps.location.lat(), 6);
    Serial.print("\n Longitude: ");
    Serial.println(gps.location.lng(), 6);

   // https://www.google.com/maps/@8.2630696,77.3022699,14z
   Serial.print("https://www.google.com/maps/@");
   Serial.print(gps.location.lat(), 6);
   Serial.print(',');
   Serial.print(gps.location.lng(), 6);
   Serial.print(",14z");
    send_sms();
    delay(2000);
    lcd_status();
}

Thanks

First off, your LCD's not an I2c device. If it were, all those wires would go to its "backpack" control board, and all you would connect are 2 wires to the I2C bus SDA and SCL.

Arduino pin 13 goes to the LCD's RS pin according to your schematic, and the RS pin is explained here.

I haven't examined your code to see why it needs to switch the LCD between Instruction and Character Modes, but that's what it's for.

blomcrestlight:
I haven't examined your code to see why it needs to switch the LCD between Instruction and Character Modes, but that's what it's for.

Well, "why" is a no-brainer. :grinning:

You need Instruction mode to issue instructions to the LCD controller in order to initialise it, tell it where you want to place characters and how you wish to display them.

You need Character Mode to send the actual data to be displayed. These modes are not in any way, options.

The OP needs to declare whether he has actually made the display work at all. He has not shown connection to the contrast control on pin 3. This should connect to ground via a variable resistor or an approximate value of 330 Ohms and there should be no connection of the potentiometer to 5 V. :astonished:

Obviously pins 1 and 2 go to ground and 5 V. You will need to connect pins 15 and 16 to 5 V and ground if you have a backlight as it most likely does.

Paul__B:
Well, "why" is a no-brainer. :grinning:

...These modes are not in any way, options.

Obviously, and I suspect you're being disingenuous. Perhaps that's what the :slight_smile: is for?

Most sketches that use LCDs don't explicitly (or perhaps I should say, visibly) use RS to change modes, it's hidden from the user by the library. I meant that I hadn't examined the code to see why it was being used at the sketch level, when there is a library #include.

OK, point taken, I hadn't actually examined the code, since I felt that the entire description was lacking in the latter details I queried.

These references to

 pinMode(13,OUTPUT);
  digitalWrite(13,LOW);

and

                digitalWrite(13,HIGH);
...
      digitalWrite(13,LOW);

are clearly spurious and nonsensical, but whether they cause problems is not at all clear to me without further examination - for which I see no present justification. They are nonsense and simply need to be removed entirely.

Perhaps the OP may reveal where he obtained this rubbish? :roll_eyes:

Perhaps the code is a hodge-podge of many sketches, and the pin13 stuff had nothing to do with an LCD's RS but were to use the led as a status indicator.

Perhaps.

In the meantime, I await the OP's explanation. :grinning:

Paul__B:
Perhaps.

In the meantime, I await the OP's explanation. :grinning:

I agree with you that the schematics is not complete and the code is not clear (no documentation, no comments).
After reading your comments guys.
I think the pin 13 is used as an indicator and has nothing to do with the RS pin.
I'll try the system to see if it's working or not after writing a good code taking into consideration your comments.
the refrence to this code: here

Thank you

laminlevrai:
I think the pin 13 is used as an indicator and has nothing to do with the RS pin.

Except that it is connected to the RS pin. :roll_eyes:

I suspect it does work - sort of - as we presume strict control of pin 13 is taken within the LiquidCrystal code and it does not care what happens outside that code. But it does look quite inappropriate, particularly when it acts to set pinMode.