GPS+ IMU problem

good morning,
My original language is Italian, this is a machine translation.
I use a MKRWAN 1310 but I cannot use the MKR GPS and MKR IMO shields at the same time.
when I load the Arduino code it doesn't even execute a line of code, is it possible that the two shields are not compatible?
as libraries I use MKRIMU.h and Arduino_MKRGPS.h
I am attaching the code:


#include <LoRa.h>
#include <MKRIMU.h>
#include <Arduino_MKRGPS.h>

unsigned long previousMillis = 0;
unsigned long currentMillis ;
const long interval = 300;
float heading, roll, pitch;
float latitude;
float longitude;
float altitude;
float speed;
float satellites;
float longitudine;
byte localAddress = 0xBB;  //address of this device
byte destination = 0xFF;   //where we are sending data to

void setup() {
  // initialize serial communications and wait for port to open:
  Serial.begin(9600);
    if (!LoRa.begin(868E6)) {
    Serial.println("Starting LoRa failed!");  
  }

  if (!GPS.begin(GPS_MODE_SHIELD)) {
    
    Serial.println("Failed to initialize GPS!"); 
  }
  
  if (!IMU.begin()) {
    Serial.println("Failed to initialize IMU!");
  }
  Serial.println("qua3");
}

void loop() {
 currentMillis = millis();


  // check if there is new GPS data available
  if (GPS.available()) {

    // read GPS values
    latitude   = GPS.latitude();
    longitude  = GPS.longitude();
    altitude   = GPS.altitude();
    speed      = GPS.speed();
    satellites = GPS.satellites();
    longitudine=GPS.longitude();
  }
  //read IMU values
   if (IMU.eulerAnglesAvailable()) {
    IMU.readEulerAngles(heading, roll, pitch);
     }
    //send data
  if (currentMillis - previousMillis >= interval) {
      previousMillis = currentMillis; 
      LoRa_send();
      printValues();
    }
}

//function to send information over LoRa network
void LoRa_send() {
    LoRa.beginPacket();  //creates a LoRa packet
    LoRa.write(destination);  //destination address
    LoRa.print("LAT: ");
    LoRa.print(latitude,7);
    LoRa.print(" LONG: ");
    LoRa.print(longitudine,7);
    LoRa.print("pitch:");
    LoRa.print(pitch);
    LoRa.print(" roll: ");
    LoRa.print(roll);
    LoRa.endPacket(); //sends the LoRa packet
    

}

//function that prints all readings in the Serial Monitor
void printValues() {
  Serial.print("Location: ");
  Serial.print(latitude, 7);
  Serial.print(", ");
  Serial.println(longitude, 7);
  Serial.print("Altitude: ");
  Serial.print(altitude);
  Serial.println("m");
  Serial.print("Ground speed: ");
  Serial.print(speed);
  Serial.println(" km/h");
  Serial.print("Number of satellites: ");
  Serial.println(satellites);
    Serial.print(heading);
    Serial.print('\t');
    Serial.print(roll);
    Serial.print('\t');
    Serial.println(pitch);
}

can anyone solve?

How do you know that ?

A good idea is to have your code startup with a message so you can at least tell if its started running. For example, change setup to be something like;

void setup() {
  // initialize serial communications and wait for port to open:
  Serial.begin(9600);
  Serial.println("My Program has started");
1 Like

yes i put in the messages during the code.
currently it would appear that the code is being executed but GPS.available () always returns 0

The forum has an Italian section.

probably writing in the Italian section I would not get any answer as already happened .. they tell me to write in the section dedicated to MKR

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.