3G SIM5320A shield stacked with TFT LCD shield issue

I am trying to finish a project where I have a 3G SIM5320A shield and a TFT LCD shield stacked on an Arduino Mega. When I stack only the LCD shield and only wire power, ground, RX and TX to the SIM shield everything works as expected. But when I stack the SIM shield on the arduino and the LCD on the SIM the LCD only shows a white screen. Any help is appreciated.

#include <Elegoo_GFX.h>
#include <Elegoo_TFTLCD.h>
#include <TouchScreen.h>
#include <Adafruit_FONA.h>
#include <SoftwareSerial.h>
#include <DHT.h>
#include <stdint.h>

#if defined(__SAM3X8E__)
    #undef __FlashStringHelper::F(string_literal)
    #define F(string_literal) string_literal
#endif


// Define the pins used for the touchscreen 
#define YP A3
#define XM A2
#define YM 9
#define XP 8

#define TS_MINX 120
#define TS_MAXX 900

#define TS_MINY 70
#define TS_MAXY 920

TouchScreen ts = TouchScreen(XP,YP, XM, YM, 300);


// Define the pins used for the LCD display
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0
#define LCD_RESET A4


#define  BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

Elegoo_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);


// Define pins for the SIM Shield 
#define FONA_TX 50
#define FONA_RX 51
#define FONA_RST A5

SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
SoftwareSerial *fonaSerial = &fonaSS;

Adafruit_FONA_3G fona = Adafruit_FONA_3G(FONA_RST);

#define DHTPIN 30
#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

// Global variables 
float humidity = 0;
float temp = 0;
char currentNumber[21];
bool alertSent = false;

uint8_t type;

void setup() {

  while(!Serial);
  Serial.begin(115200);
  tft.reset();
  
  uint16_t identifier = tft.readID();
  if(identifier == 0x9325) {
    Serial.println(F("Found ILI9325 LCD driver"));
  } else if(identifier == 0x9328) {
    Serial.println(F("Found ILI9328 LCD driver"));
  } else if(identifier == 0x4535) {
    Serial.println(F("Found LGDP4535 LCD driver"));
  }else if(identifier == 0x7575) {
    Serial.println(F("Found HX8347G LCD driver"));
  } else if(identifier == 0x9341) {
    Serial.println(F("Found ILI9341 LCD driver"));
  } else if(identifier == 0x8357) {
    Serial.println(F("Found HX8357D LCD driver"));
  } else if(identifier==0x0101)
  {     
      identifier=0x9341;
       Serial.println(F("Found 0x9341 LCD driver"));
  }else {
    Serial.print(F("Unknown LCD driver chip: "));
    Serial.println(identifier, HEX);
    Serial.println(F("If using the Elegoo 2.8\" TFT Arduino shield, the line:"));
    Serial.println(F("  #define USE_Elegoo_SHIELD_PINOUT"));
    Serial.println(F("should appear in the library header (Elegoo_TFT.h)."));
    Serial.println(F("If using the breakout board, it should NOT be #defined!"));
    Serial.println(F("Also if using the breakout, double-check that all wiring"));
    Serial.println(F("matches the tutorial."));
    identifier=0x9341;
   
  }

  tft.begin(identifier);
  tft.setRotation(2);

  pinMode(13, OUTPUT);

  drawHomeScreen(); 

  fonaSerial->begin(4800);
  if (!fona.begin(*fonaSerial)) {
    Serial.println(F("Couldn't find FONA"));
    
  }
  type = fona.type();
  Serial.println(F("FONA is OK"));
  Serial.print(F("Found "));
  switch (type) {
    case FONA800L:
      Serial.println(F("FONA 800L")); break;
    case FONA800H:
      Serial.println(F("FONA 800H")); break;
    case FONA808_V1:
      Serial.println(F("FONA 808 (v1)")); break;
    case FONA808_V2:
      Serial.println(F("FONA 808 (v2)")); break;
    case FONA3G_A:
      Serial.println(F("FONA 3G (American)")); break;
    case FONA3G_E:
      Serial.println(F("FONA 3G (European)")); break;
    default: 
      Serial.println(F("???")); break;
  }
  
  // Print module IMEI number.
  char imei[15] = {0}; // MUST use a 16 character buffer for IMEI!
  uint8_t imeiLen = fona.getIMEI(imei);
  if (imeiLen > 0) {
    Serial.print("Module IMEI: "); Serial.println(imei);
  }
  
  dht.begin();
  
}

#define MINPRESSURE 10
#define MAXPRESSURE 1000

void loop() {
  // put your main code here, to run repeatedly:

  // Check for temp/humidity changes and update the view if needed. 
  updateTemp();

  // Get user touches
  digitalWrite(13, HIGH);
  TSPoint p = ts.getPoint();
  digitalWrite(13, LOW);

  pinMode(XM, OUTPUT);
  pinMode(YP, OUTPUT);
  
  if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
    p.x = map(p.x, TS_MINX, TS_MAXX, tft.width(), 0);
    p.y = (tft.height()-map(p.y,  TS_MINY, TS_MAXY, tft.height(), 0));

    // call changeNumber function if the user touches inside the change number button.
    if (p.x > 20 && p.x < 220 && p.y > 150 && p.y < 200) {
      changeNumber();
    }
  }
}


// Function that displays the number pad on the LCD screen
unsigned long drawNumberInputScreen() {
  tft.fillScreen(WHITE);
  unsigned long start = micros();

  tft.setTextColor(BLACK);
  tft.setTextSize(2);
  tft.setCursor(60, 25);
  tft.print(currentNumber);
  
  tft.setTextColor(WHITE);
  tft.setTextSize(2);

  //Row 1
  tft.fillRect(0, 55, 80, 62, BLACK);
  tft.drawRect(0, 55, 80, 62, BLUE);
  tft.setCursor(35,80);
  tft.print("1");
  
  tft.fillRect(80, 55, 80, 62, BLACK);
  tft.drawRect(80, 55, 80, 62, BLUE);
  tft.setCursor(115,80);
  tft.print("2");
  
  tft.fillRect(160, 55, 80, 62, BLACK); 
  tft.drawRect(160, 55, 80, 62, BLUE);
  tft.setCursor(195,80);
  tft.print("3");

  //Row 2
  tft.fillRect(0, 117, 80, 62, BLACK);
  tft.drawRect(0, 117, 80, 62, BLUE);
  tft.setCursor(35,142);
  tft.print("4");
  
  tft.fillRect(80, 117, 80, 62, BLACK);
  tft.drawRect(80, 117, 80, 62, BLUE);
  tft.setCursor(115,142);
  tft.print("5");
  
  tft.fillRect(160, 117, 80, 62, BLACK); 
  tft.drawRect(160, 117, 80, 62, BLUE);
  tft.setCursor(195,142);
  tft.print("6");

  //Row 3
  tft.fillRect(0, 179, 80, 62, BLACK);
  tft.drawRect(0, 179, 80, 62, BLUE);
  tft.setCursor(35,204);
  tft.print("7");
  
  tft.fillRect(80, 179, 80, 62, BLACK);
  tft.drawRect(80, 179, 80, 62, BLUE);
  tft.setCursor(115,204);
  tft.print("8");
  
  tft.fillRect(160, 179, 80, 62, BLACK); 
  tft.drawRect(160, 179, 80, 62, BLUE);
  tft.setCursor(195,204);
  tft.print("9");

  //Row 4
  tft.fillRect(0, 241, 80, 62, BLACK);
  tft.drawRect(0, 241, 80, 62, BLUE);
  tft.setCursor(30,266);
  tft.print("<-");
  
  tft.fillRect(80, 241, 80, 62, BLACK);
  tft.drawRect(80, 241, 80, 62, BLUE);
  tft.setCursor(115,266);
  tft.print("0");
  
  tft.fillRect(160, 241, 80, 62, BLACK); 
  tft.drawRect(160, 241, 80, 62, BLUE);
  tft.setCursor(190,266);
  tft.print("Ent");
}


// Function the displays the Home screen on the LCD screen
unsigned long drawHomeScreen() {
    tft.fillScreen(BLACK);
    unsigned long start = micros();
    tft.setCursor(0,10);
    tft.setTextColor(WHITE);
    tft.setTextSize(3);
    tft.print("Temp: ");
    tft.println(temp);
    tft.print("Humi: ");
    tft.println(humidity);
    tft.fillRect(20,150,200, 50, RED);
    tft.drawRect(20,150,200,50,WHITE);
    tft.setCursor(42, 168);
    tft.setTextSize(2);
    tft.print("Change Number");
    //tft.setTextSize(1);
    tft.setCursor(35,210);
    tft.print("Current Number: ");
    tft.setCursor(60,230);
    tft.print(currentNumber);
    return micros() - start;
}


// Function the reads user touches to change the alert number
void changeNumber() {
  drawNumberInputScreen();
  bool stillEntering = true;
  int index = 0;

  // Stay in the function until the user touches the "Ent" or "<-" buttons.
  while (stillEntering) {
    
    digitalWrite(13, HIGH);
    TSPoint p = ts.getPoint();
    digitalWrite(13, LOW);
  
    pinMode(XM, OUTPUT);
    pinMode(YP, OUTPUT);
  
    if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
      p.x = map(p.x, TS_MINX, TS_MAXX, tft.width(), 0);
      p.y = (tft.height()-map(p.y,  TS_MINY, TS_MAXY, tft.height(), 0));

      if (p.x >= 0 && p.x <= 79 && p.y >= 55 && p.y <= 116) {
        currentNumber[index] = '1';
        drawNumberInputScreen();
        index += 1;
        
      } else if (p.x >= 80 && p.x <= 159 && p.y >= 55 && p.y <= 116) {
        currentNumber[index] = '2';
        drawNumberInputScreen();
        index += 1;
        
      } else if (p.x >= 160 && p.x <= 239 && p.y >= 55 && p.y <= 116) {
        currentNumber[index] = '3';
        drawNumberInputScreen();
        index += 1;
        
      } else if (p.x >= 0 && p.x <= 79 && p.y >= 117 && p.y <= 178) {
        currentNumber[index] = '4';
        drawNumberInputScreen();
        index += 1;
        
      } else if (p.x >= 80 && p.x <= 159 && p.y >= 117 && p.y <= 178) {
        currentNumber[index] = '5';
        drawNumberInputScreen();
        index += 1;
        
      } else if (p.x >= 160 && p.x <= 239 && p.y >= 117 && p.y <= 178) {
        currentNumber[index] = '6';
        drawNumberInputScreen();
        index += 1;
        
      } else if (p.x >= 0 && p.x <= 79 && p.y >= 179 && p.y <= 240) {
        currentNumber[index] = '7';
        drawNumberInputScreen();
        index += 1;
        
      } else if (p.x >= 80 && p.x <= 159 && p.y >= 179 && p.y <= 240) {
        currentNumber[index] = '8';
        drawNumberInputScreen();
        index += 1;
        
      } else if (p.x >= 160 && p.x <= 239 && p.y >= 179 && p.y <= 240) {
        currentNumber[index] = '9';
        drawNumberInputScreen();
        index += 1;
        
      } else if (p.x >= 0 && p.x <= 79 && p.y >= 241 && p.y <= 302) {
        stillEntering = false;
        
      } else if (p.x >= 80 && p.x <= 159 && p.y >= 241 && p.y <= 302) {
        currentNumber[index] = '0';
        drawNumberInputScreen();
        index += 1;
  
      } else if (p.x >= 160 && p.x <= 239 && p.y >= 241 && p.y <= 302) {
        stillEntering = false;
      }
    }
  }
  drawHomeScreen();
}

unsigned long sendingAlert() {
    tft.fillScreen(BLACK);
    unsigned long start = micros();
    tft.setCursor(57,70);
    tft.setTextColor(WHITE);
    tft.setTextSize(3);
    tft.print("Sending");
    tft.setCursor(45,100);
    tft.print("Alert To:");
    tft.setCursor(60,150);
    tft.setTextSize(2);
    tft.print(currentNumber);
    return micros() - start;
}


// Function that is responsable for sending the alert
void sendAlert(){
  char message[141] = {'T','e','m','p','e','r','a', 't','u', 'r', 'e', 'i', 's', '8','0',' ','d','e','g','r','e','e','s'};
  while (!alertSent) {
     sendingAlert();
     if (!fona.sendSMS(currentNumber, message)){
       alertSent = false;
     } else {
       alertSent = true;
     }
     delay(500);
   }
   drawHomeScreen();
}



/* Function that updates the home display is the tempature or humidity has changed and sends the alert if the temperature 
 *  is at the desired temperature
 */
 
void updateTemp() {
  float currentTemp = dht.readTemperature(true);
  float currentHumidity = dht.readHumidity();

  if (currentTemp == 80.0) {
    sendAlert();
  }

  if ((currentTemp - temp) >= 0.5 || (currentTemp - temp) <= -0.5) {
    temp = currentTemp;
    humidity = currentHumidity;
    drawHomeScreen();
  }

  if ((currentHumidity - humidity) >= 0.5 || (currentHumidity - humidity) <= -0.5) {
    temp = currentTemp;
    humidity = currentHumidity;
    drawHomeScreen();
  }
  
}```

Compare the shield pinouts. You have a pin conflict.

I can't find a conflict. All the pins seem to line up accordingly. I was thinking that it was an issue in my code but even the LCD's example code doesn't work when stacked with the Sim shield.

Please post all the pin information for both shields.

3G Shield Datasheet.pdf (2.6 MB)

This is all I was able to find on the 3G SIM Shield.

Both shields.

Sorry the LCD one didn't upload but it should be there now

What pins are you using for software serial?

I'm using pins 50 and 51.

The SIM shield can't see those. Only D0-D5 via the jumper selection.

Not for the Arduino Mega.

You need to find a complete, accurate pin out for the 3G shield. I can't help until you do. Just to fill in some blanks, you have some jumper wires in addition to the stacking, apparently. You should avoid invoking guesswork, by posting a diagram or photos of how you have it connected (in the non-working configuration).

But, it is almost certain, some undocumented pins on the 3G shield are interfering with the pins dedicated to the display (and there are many of those).

Ok I will try and find out more on the pin out for the 3G shield. Thank you for your help!

So I found out that the 3G shield also uses digital pin 9 as its reset and that is where the conflict is. But when I try and set a different pin for the reset in my code it still uses pin 9.

It's great that you've taken on the task of troubleshooting this! It saves the trouble of posting details. Good luck.

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