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:
// 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);
}
}