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...