Combining GPS and Arduino WiFi Shield

I’m working on a project that will read GPS co-ordinates from a GPS shield periodically and then use WiFi to transmit these co-ordinates.

I have the Arduino WiFi Shield and the ITEAD Arduino GPS Shield. I’ve managed to use each of them separately, but cannot get the two to co-operate at all. I’m assuming there is a pin conflict, but I can not determine which pins may be causing the issue.

At the minute, I’ve set the headers on the GPS shield so that RxD is on 3 and TxD is on 2 (see the below picture), both of which should be unused by the WiFi Shield as far as I can tell.

My code is as follows:

#include <SoftwareSerial.h>
#include <TinyGPS.h>
#include <SPI.h>
#include <WiFi.h>

/*
GPS Variables
*/
const int GPS_RXPIN = 2;
const int GPS_TXPIN = 3;

TinyGPS gps;
SoftwareSerial ss(GPS_RXPIN, GPS_TXPIN);

/*
WiFi Variables
*/
char ssid[] = "SSID";
char pass[] = "HIDDEN_PASS";

const char server[] = "SERVER ADDRESS";
const int port = 8081;

int status = WL_IDLE_STATUS;

WiFiClient client;

void setup()
{
  Serial.begin(9600);
  ss.begin(38400);
  
  // Deselect SD card
  pinMode(4, OUTPUT); 
  digitalWrite(4, HIGH);
      
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present"); 
    // don't continue:
    while(true);
  }  
  
  // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) { 
    Serial.write("Connecting to WiFi...\n");
    
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:    
    status = WiFi.begin(ssid, pass);
  
    // wait 10 seconds for connection:
    delay(10000);
  } 
    
  Serial.write("Connected to WiFi\n");
}

void loop()
{
    while (ss.available())
    {
      char c = ss.read();
      
      //Serial.println(c);
      
      if (gps.encode(c)) {
        Serial.println("Got valid GPS data, connecting to server...");
        
        if (client.connect(server, port)) {
          float flat, flon;
          unsigned long age;
          gps.f_get_position(&flat, &flon, &age);
        
          Serial.println("connected to server");
          
          client.print("LAT=");
          client.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6);
          client.print(" LON=");
          client.print(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6);
          client.print(" SAT=");
          client.print(gps.satellites() == TinyGPS::GPS_INVALID_SATELLITES ? 0 : gps.satellites());
          client.print(" PREC=");
          client.println(gps.hdop() == TinyGPS::GPS_INVALID_HDOP ? 0 : gps.hdop());
      
          client.stop();
        }
        
        // Delay 10 seconds rather than sending constantly
        delay(10000);
      }
    }
}

Whenever I run this, however, all that is printed to the serial console is “WiFi shield not present”.

Any help working out where I’m going wrong would be brilliant. I’m sure it’s something simple…

Anybody got any ideas? Help would be greatly appreciated.

Is the wifi shield connected directly to the Arduino and the GPS shield on top of it?

SurferTim: Is the wifi shield connected directly to the Arduino and the GPS shield on top of it?

Yep, both are stacked directly, with no other connections (apart from the Arduino USB for programming and monitoring the serial log).

euantorano: Yep, both are stacked directly, with no other connections (apart from the Arduino USB for programming and monitoring the serial log).

How are both stacked directly? The wifi shield needs the ICSP pins for the SPI bus data lines.

SurferTim: How are both stacked directly? The wifi shield needs the ICSP pins for the SPI bus data lines.

They're just one on top of the other, which I had assumed would work. Obviously not. Which pins are the ICSP pins? How else could I combine them?

euantorano: They're just one on top of the other, which I had assumed would work. Obviously not. Which pins are the ICSP pins? How else could I combine them?

Obviously not. The wifi shield must be directly connected to the Arduino. The ICSP pins are labelled on the Arduino. They are the pins on the center of the board. Look at the bottom of the wifi shield. It has a 6 pin connector (socket) that must connect to the ICSP pins.

SurferTim: Obviously not. The wifi shield must be directly connected to the Arduino. The ICSP pins are labelled on the Arduino. They are the pins on the center of the board. Look at the bottom of the wifi shield. It has a 6 pin connector (socket) that must connect to the ICSP pins.

Yes, the WiFi shield is directly connected, with the GPS stacked on top of the WiFi. The WiFi requires many more pins than the GPS shield has on board, so it has to be that way round anyway.