Interference between LCD20x4 with I2C & GPS

Project: Arduino with gps logger & Odometer with display

My project has following hardware:

  • arduino MEGA 2560
  • GPS UBLOX NEO 7M
  • LCD Display (2 options: LCD20x4 +I2C or LCD 1602 with keypad)
  • SD card Logger

DeEscription of the issue:

  • the below code works perfectly if I use an lcd1602 display ( with keypad ) using pins D4,D5,D6,D7,D8,D9)

Due that I need to show more information on display I substitute this display with a 20x4 LCD with I2C interface.
This display works correctly, with all typical examples sketches.

With my own project code it also works, but it seems to exists some interference between TinyGps++ library and NewliquidCrystal library, because no GPS informations appears on this lcd display.

I checked GPS led (it blinks) and it seems to acquiring data correctly

Has this something to do with serial Data?

Or maybe with SCL/SDA pins?

the only main differences between both codes are:

//#include <LiquidCrystal.h> // for 1602LCD keypad, works OK
#include <LiquidCrystal_I2C.h>

//LiquidCrystal lcd(8, 9, 4, 5, 6, 7); //// for 1602LCD keypad, works OK

LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // SDA &SCL connected to pins 20/21 of MEGA

void setup()

//lcd.begin(16, 2);
lcd.begin(20, 4);
lcd.backlight();

Any idea how to solve it?

//* Odometer v 15.09.2016 SD & gps.38400*//

#include <SPI.h>
#include <SD.h>
#include <TinyGPS++.h>
#include <EEPROMEx.h>
//#include <LiquidCrystal.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>   
const char UBLOX_INIT[] PROGMEM = {
  0xB5,0x62,0x06,0x08,0x06,0x00,0xC8,0x00,0x01,0x00,0x01,0x00,0xDE,0x6A
  }; //set rate of GPS to 5hz
File myFile;
TinyGPSPlus gps;
const int chipSelect = 53;
//LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
int debounceDelay = 20;
long pulsacion = 0;
long pulsacionB = 0;
int intervalo = 200;
int calibre = 1750;
unsigned int velocidad = 0;
unsigned int vel_0 = 0;
unsigned int vel_1 = 0;
unsigned int vel_2 = 0;
unsigned int vel_3 = 0;
unsigned int vel_4 = 0;
unsigned int vel_5 = 0;
int metros = 0;
int decametros = 0;
int kilom = 0;
unsigned long freeze = 0;
unsigned long contador = 0;
unsigned long contadorprevio = 0;
byte seleccion = 0;
byte resolucion=0;
int masmetros = 0;
byte address = 0;
int lcd_key = 0;
int adc_key_in = 0;
unsigned long ultimotiempo = 0;
char inByte;
double longitud = 0;
double latitud = 0;
int preci= 0;
unsigned long tiempo = 0;
unsigned long tiempoAnt = 0;
unsigned long fecha = 0;
unsigned int vel = 0;
unsigned int numDato = 0; 
unsigned int numDatoB = 0; 
long distancia = 0;
long distanciaAnt = 0;
byte satelites = 0;
int Data = 0;//valor del pulsador
int DataB = 0;



void setup()
{

  Serial.begin(9600);
  delay(10);
  GPS_multiInt();
  //lcd.begin(16, 2);
  lcd.begin(20, 4);
  lcd.backlight();  
  pinMode(3, OUTPUT);
  pinMode(10, OUTPUT); // pin CS 53 del SD,MOSI 51,MISO 50, sck 52
  lcd.setCursor(0, 0);
  lcd.print(F("Verificando SD"));
  lcd.setCursor(0, 1);
  if (!SD.begin(chipSelect)) {
   lcd.print(F("Fallo tarjeta"));
   smartDelay(4000);
   lcd.clear();
    //return;
  }
  lcd.print(F("tarjeta OK"));
  delay(500);

  String StringONE = "waypoint,NumDato,distancia,latitud,longitud,tiempo,vel";
  File dataFile = SD.open("waypoint.txt", FILE_WRITE);
  if (dataFile) {
    dataFile.println(StringONE);
    dataFile.close();    
  }  
  
  calibre = EEPROM.readInt(address);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("C=");
  lcd.setCursor(2, 0);
  lcd.print(calibre);
  lcd.setCursor(0, 1);
  lcd.print("Reset    OK");
  delay(1000);
  attachInterrupt(0, CuentoPulso, FALLING);//(MEGA 5-pin18)
  lcd.clear();
  
}

void loop()



    {
      distancia = (contador * calibre / 1000);
      decametros = distancia / 10;
      kilom = decametros / 100;
      metros = distancia - (decametros * 10);
      decametros = decametros - (kilom * 100);
         
      while (Serial.available() > 0)
      if (contador != contadorprevio) {          
          Serial.println(velocidad);
          contadorprevio = contador;
      }

      while (Serial1.available() > 0)
        gps.encode(Serial1.read());
      if (gps.location.isValid())

          {
      satelites = gps.satellites.value();
      longitud = gps.location.lng();
      latitud = gps.location.lat();
      tiempo = (gps.time.value());
      fecha=(gps.date.value());
      preci=(gps.hdop.value()); 
      vel = (gps.speed.kmph());
     
        }
          lcd.setCursor(0, 0);
          lcd.print(latitud,6);
          lcd.setCursor(0, 1);
          lcd.print(longitud,6);         
          lcd.setCursor(10, 0);
          lcd.print(F("S"));
          lcd.print(satelites);
          lcd.setCursor(13, 0);
          lcd.print(vel);
          lcd.print("   ");
          lcd.setCursor(10, 1);      
          lcd.print("D");
          lcd.print(kilom);
          lcd.print(".");          
          numDato = numDato + 1;
          String StringONE = String("W");
          StringONE += String(",");
          StringONE += String(numDato);
          StringONE += String(",");
          StringONE += String(distancia);
          StringONE += String(",");
          StringONE += String(latitud, 6);
          StringONE += String(",");
          StringONE += String(longitud, 6);
          StringONE += String(",");
          StringONE += String(tiempo / 10);
          StringONE += String(",");
          StringONE += String(vel);
          File dataFile = SD.open("waypoint.txt", FILE_WRITE);
          if (dataFile) {
            dataFile.println(StringONE);
            dataFile.close();
          }
       }        
   
 
 

void CuentoPulso() {

  if ( (millis() - ultimotiempo) > debounceDelay) {
    contador ++;
    vel_3 = (calibre * 3.6) / (millis() - ultimotiempo);
    vel_0 = vel_1;
    vel_1 = vel_2;
    vel_2 = vel_3;
    velocidad = (vel_0 + vel_1 + vel_2 ) / 3;
    ultimotiempo = millis();

  }
}

static void smartDelay(unsigned long ms)
{
  unsigned long start = millis();
  do 
  {
    while (Serial1.available())
      gps.encode(Serial1.read());
  } while (millis() - start < ms);
}

void GPS_multiInt()
{
  Serial1.begin(9600);
  delay(10);
  Serial1.print("$PUBX,41,1,3,3,38400,0*24\r\n");//set baud of gps to 38400
  delay(200);
  Serial1.begin(38400);
  for(uint8_t i=0; i<sizeof(UBLOX_INIT); i++){
    Serial1.write(pgm_read_byte(UBLOX_INIT+i));
    delay(5);
  }
}

. . . because no GPS informations appears on this lcd display.

Since your first sentence mentions an odometer as well as a GPS this statement implies that the odometer display is still working but the GPS display is not. Please clarify.

Don

Sorry!
I didn't explain at all, the way of work of my project.
I have a Magnetic switch connected to my MEGA BOard. This acts as a odometer.
I log some data on a SD card.That works also.

But all who's related to GPS data do not work if I use a 20x4 I2C display, even the display works for all other functions.
No problem is with the sketch if the lcd is a simple lcd 1602 keypad

Thanks in advance for your help.

Best regards

PD: Some uninteresting stuff has been removed from the above code.