Device : Tinyduino, Tinyduino WiFi module, Tinyduino GPS module, Tinyduino USB module.
Hi, My name is SunChel Ha
I have a problem issue with using WiFi and GPS same time.
It works fine when i use them separately. But when i used it at the same time. Problem occurs.
I thought that is the problem with sharing A3 pin. Used by ADAFRUIT_CC3000_VBAT A3 for WiFi, GPS_ONOFFPin = A3 for GPS.
I'm not getting anything from GPS. i waited for 30 minutes to make sure this is working.
What we are trying to do is connect open Wifi, then send gps information via wifi.
Wifi module is working but GPS doesn't.
How can i solve this problem?
#include <TinyGPS++.h>
//#include <SD.h>
#include <SPI.h>
#include <SoftwareSerial.h>
#include <Adafruit_CC3000.h>
#include "utility/debug.h"
#include <string.h>
#include <ccspi.h>
#define ADAFRUIT_CC3000_IRQ 2 // MUST be an interrupt pin!
// These can be any two pins
#define ADAFRUIT_CC3000_VBAT A3
#define ADAFRUIT_CC3000_CS 8
/*
This sample code demonstrates the normal use of a TinyGPS++ (TinyGPSPlus) object.
It requires the use of SoftwareSerial, and assumes that you have a
4800-baud serial GPS device hooked up on pins 4(rx) and 3(tx).
*/
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
SPI_CLOCK_DIV2); // you can change this clock speed
// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
char openssid[34];
// Test server configuration
const uint8_t SERVER_IP[4] = { 218,150,182,172 };
const uint16_t SERVER_PORT = 9000;
// The Arduino pins used by the GPS module static const int GPS_ONOFFPin = A3; static const int GPS_SYSONPin = A2; static const int GPS_RXPin = A1; static const int GPS_TXPin = A0; static const int GPSBaud = 9600;
String SD_date = "invalid";
String SD_time = "invalid";
String SD_lat = "invalid";
String SD_lon = "invalid";
String SD_sat = "invalid";
String dataString = "";
// The TinyGPS++ object
TinyGPSPlus gps;
static char dtostrfbuffer[20];
// The serial connection to the GPS device SoftwareSerial ss(GPS_RXPin, GPS_TXPin);
void setup()
{
Serial.begin(115200);
ss.begin(GPSBaud);
pinMode(GPS_SYSONPin, INPUT);
pinMode(GPS_ONOFFPin, OUTPUT);
digitalWrite( GPS_ONOFFPin, LOW );
delay(5);
if( digitalRead( GPS_SYSONPin ) == LOW )
{
// Need to wake the module
digitalWrite( GPS_ONOFFPin, HIGH );
delay(5);
digitalWrite( GPS_ONOFFPin, LOW );
}
pinMode(8, OUTPUT);
Serial.println(F("\nInitializing..."));
if (!cc3000.begin())
{
Serial.println(F("Couldn't begin()! Check your wiring?"));
while(1);
}
// see if the card is present and can be initialized:
Serial.println(" ");
Serial.println("card initialized.");
Serial.println();
Serial.println(F("Sats Latitude Longitude Date Time "));
Serial.println(F(" (deg) (deg) "));
Serial.println(F("--------------------------------------------"));
}
void loop()
{
listSSIDResults();
if (!cc3000.connectOpen(openssid)) {
Serial.println(F("Failed!"));
while(1);
}
Serial.println(F("Connected!"));
Serial.println(F("Request DHCP"));
while (!cc3000.checkDHCP())
{
delay(100); // ToDo: Insert a DHCP timeout!
}
while (! displayConnectionDetails()) {
delay(1000);
}/*
Adafruit_CC3000_Client client = cc3000.connectTCP(cc3000.IP2U32(SERVER_IP[0], SERVER_IP[1], SERVER_IP[2], SERVER_IP[3]),
SERVER_PORT);
if (!client.connected()) {
Serial.println(F("Couldn't connect to server! Make sure listener.py is running on the server."));
while(1);
}*/
while(1)
{
printInt(gps.satellites.value(), gps.satellites.isValid(), 5);
printFloat(gps.location.lat(), gps.location.isValid(), 11, 6, 1);
printFloat(gps.location.lng(), gps.location.isValid(), 12, 6, 2);
printDateTime(gps.date, gps.time);
Serial.println();
smartDelay(2000);
if (millis() > 5000 && gps.charsProcessed() < 10)
Serial.println(F("No GPS data received: check wiring"));
dataString = SD_date + "," + SD_time + "," + SD_lat + "," + SD_lon + "," + SD_sat;
// client.println(dataString);
}
/* If the file was created ok then add come content */
}
// This custom version of delay() ensures that the gps object // is being "fed".
static void smartDelay(unsigned long ms) {
unsigned long start = millis();
do
{
while (ss.available())
gps.encode(ss.read());
} while (millis() - start < ms);
}
static void printFloat(float val, bool valid, int len, int prec, int SD_val) {
char sz[32];
if (!valid)
{
while (len-- > 1)
Serial.print('*');
Serial.print(' ');
}
else
{
Serial.print(val, prec);
if (SD_val == 1) SD_lat = dtostrf(val,10,5,dtostrfbuffer);
else if (SD_val == 2) SD_lon = dtostrf(val,10,5,dtostrfbuffer);
int vi = abs((int)val);
int flen = prec + (val < 0.0 ? 2 : 1); // . and -
flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1;
for (int i=flen; i<len; ++i)
Serial.print(' ');
/*
if (SD_val == 1)
{
sprintf(sz, "%f", val * 100);
SD_lat = sz;
}
else if(SD_val == 2)
{
sprintf(sz, "%f", val * 100);
SD_lon = sz;
}
*/
}
smartDelay(0);
}
static void printInt(unsigned long val, bool valid, int len) {
char sz[32];
if(valid)
{
// if number of satelites are bigger than 3, write GPS data on the SD card. (testing..)
if(val > 3)
{
sprintf(sz, "%ld", val);
SD_sat = sz;
}
}
sz[len] = 0;
for (int i=strlen(sz); i<len; ++i)
sz[i] = ' ';
if (len > 0)
sz[len-1] = ' ';
Serial.print(sz);
smartDelay(0);
}
static void printDateTime(TinyGPSDate &d, TinyGPSTime &t) {
if (!d.isValid())
{
Serial.print(F("********** "));
}
else
{
char sz[32];
sprintf(sz, "%02d%02d%02d", d.month(), d.day(), d.year());
Serial.print(sz);
SD_date = sz;
}
if (!t.isValid())
{
Serial.print(F("******** "));
}
else
{
char sz[32];
sprintf(sz, "%02d%02d%02d", t.hour() + 9, t.minute(), t.second());
Serial.print(sz);
SD_time = sz;
}
smartDelay(0);
}
static void printStr(const char *str, int len) {
int slen = strlen(str);
for (int i=0; i<len; ++i)
Serial.print(i<slen ? str[i] : ' ');
smartDelay(0);
}
bool displayConnectionDetails(void)
{
uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;
if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv))
{
Serial.println(F("Unable to retrieve the IP Address!\r\n"));
return false;
}
else
{
Serial.print(F("\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress);
Serial.print(F("\nNetmask: ")); cc3000.printIPdotsRev(netmask);
Serial.print(F("\nGateway: ")); cc3000.printIPdotsRev(gateway);
Serial.print(F("\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv);
Serial.print(F("\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv);
Serial.println();
return true;
}
}
void listSSIDResults(void)
{
uint8_t valid, rssi, sec, index;
char ssidname[33];
uint8_t Hirssi=0, Hisec=0;
char Hissidname[33];
index = cc3000.startSSIDscan();
Serial.print(F("Networks found: ")); Serial.println(index);
Serial.println(F("================================================"));
while (index) {
index--;
valid = cc3000.getNextSSID(&rssi, &sec, ssidname);
if(sec==0)
{
if(Hirssi < rssi)
{
strcpy(Hissidname,ssidname);
Hirssi = rssi;
}
}
}
Serial.print(F("SSID Name : ")); Serial.print(Hissidname);
Serial.println();
Serial.print(F("RSSI : "));
Serial.println(Hirssi);
Serial.println(F("================================================"));
strcpy(openssid,Hissidname);
cc3000.stopSSIDscan();
}