Go Down

Topic: Arduino MKR GSM 1400 + GPS Shield: No GPS available, No satellites (Read 163 times) previous topic - next topic

mikethomasmakes

Hello,
I've been working on a project involving the Arduino MKR GSM 1400, and I've recently added the MKR GPS module as a shield. I have researched test code and have uploaded it successfully. Upon running the code and printing GPS.available() and GPS.satellites(), both read 0 constantly. I have tested this indoors and outside. I am located in a fairly populated and flat area that should have good GPS line of sight. I am using the Arduino_MKRGPS.h library. And I am initializing the GPS module with "GPS.begin(GPS_MODE_SHIELD)"

I've searched for this issue regarding this specific setup, but not found anything. Any help is appreciated, thank you.

Here is my code:
Code: [Select]
// Include the GSM library
#include <MKRGSM.h>
#include <Arduino_MKRGPS.h>
#include <ArduinoLowPower.h>

// initialize the library instance
GPRS gprs;
GSM gsmAccess;
GSM_SMS sms;

#define Input1Pin 2
#define Input2Pin 3
#define VoltagePin A0
#define Output1Pin 0
#define Output2Pin 1

String myLatitude = "0.000000";
String myLongitude = "0.000000";

boolean GeoFence = false;

// Array to hold the number a SMS is retreived from
char senderNumber[20];
//int masterNumber = 6179551873; //hardcode to start (easiest, fastest, cheapest), include country code

//The connectNetwork() function is used for the board data connection
void connectNetwork()
{
  bool connected = false;
  //set global AT command timeout this allow to recover from uart communication
  //freeze between samd module and ublox module.
  //gprs.setTimeout(100000);
  //gsmAccess.setTimeout(100000);
 
  // Start GSM connection
  while (!connected) {
    if (gsmAccess.begin() == GSM_READY) {
      connected = true;
    } else {
      Serial.println("GSM Not connected");
      delay(1000);
    }
  }
}

void setup() {
  // initialize serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  connectNetwork();
  if(!GPS.begin(GPS_MODE_SHIELD)){
    Serial.println("GPS Not Connected.");
    delay(10);
  }
  Serial.println("GPS Connected");
 
  SendSMS("System initialized");
}

void loop() {

  int c;
  String message;
  String command;
  String parameter;

  // If there are any SMSs available()
  if (sms.available()) {
    // Get remote number
    sms.remoteNumber(senderNumber, 20);

    // Any messages starting with # should be discarded
    if (sms.peek() == '#') {
      Serial.println("Discarded SMS");
      sms.flush();
    }
   
    // Read message bytes and print them
    while ((c = sms.read()) != -1) {
        message = message + (char)c;
    }
   
    //Parse out Command & Parameter
    int commaIndex = message.indexOf(',');
    command = message.substring(0, commaIndex);
   
    if (commaIndex != -1){
      parameter = message.substring(commaIndex + 1);
      //Does not account for spaces
      //Double digits work
    }
    else{
      parameter = "None";
    }
   
    //Measure Location
    //if GeoFence true {
    //measureLocation();
    //}

    // Delete message from modem memory
    sms.flush();
  }
  delay(1000);

//Commands
  //Send Command List
  if (command == "Help"){
    //send list of commands
    SendSMS(
      "Command List:\n1. Output,X\n2. Voltage\n");
  }
 
  //Output 1 On
  if (command == "Output"){
    //Turn on Output1, default parameter = 5 minutes?
    digitalWrite(Output1Pin, HIGH);
    SendSMS("Output On");
    if (parameter == "None"){
      delay(300000); //5 minutes default time
    }
    else{
      delay(parameter.toInt() * 60000); //Converted to minutes
    }
    digitalWrite(Output1Pin, LOW);
    SendSMS("Output Off");
  }
   
  //Battery voltage
  if (command == "Voltage"){
    //Send battery voltage
    float voltage = analogRead(VoltagePin) / 74.20; //GND = 0, 5V = 1024 (13.8V Max)
    //Serial.println(voltage);
    SendSMS("Battery Voltage: " + String(voltage) + "V");
  }
 
  //GeoFence
  //if (command == "GeoFence On"){
    //Longitude = GSMlongitude;
    //Lattitude = GSMlatitude;
    //Radius = parameter;
  boolean GeoFence = true;
  measureLocation();
  String myLocation = "https://www.google.com/maps/place/" + myLatitude + "," + myLongitude;
  SendSMS("Location: " + myLocation);
  Serial.println(myLocation);
  //}
 
  //Disable GeoFence
  if (command == "GeoFence Off"){
   
  }

//Automatic Functions

  /*read sensors
  Serial.println("Reading Input");
  int Input2State = digitalRead(Input2Pin);
  // compare the buttonState to its previous state
  if (Input2State != lastInput2State) {
    if (Input2State == HIGH) {
      Serial.println("on");
    }
    else {
      // if the current state is LOW then the button went from on to off:
      Serial.println("off");
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
  bool lastInput2State = Input2State;*/
   
    //if current sense 1 tripped
      //send low bilge switch on
    //if current sense 2 tripped
      //send high bilge switch on
     
  //If Input2 Change
    //Turn on Output2

  //Power Saving
  //gsmAccess.shutdown();
  //LowPower.sleep(60000); //enable the low power for 60 seconds and after retry the board
  //connectNetwork(); //turn on the module and reconect to data network
}

//Send SMS
void SendSMS(String txtMsg){
  sms.beginSMS(senderNumber);
  sms.print(txtMsg);
  sms.endSMS();
}

//Read input serial
int readSerial(char result[]) {
  int i = 0;
  while (1) {
    while (Serial.available() > 0) {
      char inChar = Serial.read();
      if (inChar == '\n') {
        result[i] = '\0';
        Serial.flush();
        return 0;
      }
      if (inChar != '\r') {
        result[i] = inChar;
        i++;
      }
    }
  }
}

void measureLocation() {
  Serial.println("Measuring Location...");
  unsigned long timeout = millis();
  while (millis() - timeout < 45000) {
    Serial.println(GPS.satellites()); //0 satellites, GPS not available, tried outside, didnt work
    if (GPS.available() && GPS.satellites() > 4 ) {
      myLatitude = String(GPS.latitude(), 6);
      myLongitude = String(GPS.longitude(), 6);
      break;
    }
    delay(1000);
  }
}

mstepanek1976

I don't have any good answers for you. Hopefully somebody else knows more, because I'd like to know more as well. Having said that, have you tried any toy examples yet with just GPS functionality (like playing with the examples)? From what I've seen, it likes to be "asked" a lot in order to function correctly. That is, I have to call available() A LOT in order to get anything out of it... and then you might get a reading every second or so. (I'm not messing with standby mode anymore either.) It might be worth playing with it in a more standalone fashion to see if you have some of the same results as I've had. Right now, my toy has just a 1ms delay (checking every time). With that, it actually works fairly well (from an overall user experience standpoint)... but definitely not how I was originally planning on using it. I don't have a good feel for how that will affect battery life (haven't gotten to that yet), but it's a concern I've got in mind. I haven't dug into it more, because I've got a bunch of other things I'm working through at the moment. If others have ideas, though, I'm definitely interested as well.

mikethomasmakes

Thanks for your reply. I will try it with standalone code. I have made it call GPS.available() many times over several minutes to see if it picks anything up, but no luck.

Go Up