Programming problem Tracker MKR1200+neo6m+accelerometer

Hello
I rephrase my message taking into account the comments I received

My goal: realization of a tracker to monitor a hive using the SigFox network
This tracker must be energy efficient and only send its position if it is moving
standby time should be more than 1 year

My gear:
1 MKRFOX1200 card
1 lish3d accellerometer (adafruit)
1 neo6m gps
1 mosfet to manage the GPS power supply
1 LIFEPO 3.2v battery


My code :

#include <TinyGPS++.h>
#define gpsSerial Serial1

char data;
 
float latitude;
float longitude;
uint8_t alt; //altitude
uint8_t vitesse;
uint8_t nbre_sat;
 
TinyGPSPlus gps;

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_LIS3DH.h>
#include <Adafruit_Sensor.h>
#include <ArduinoLowPower.h>
#include <SigFox.h>

// Used for software SPI
#define SLEEPTIME 10 * 60 * 1000 // Set the delay to 1440 minutes (1440 min x 60 seconds x 1000 milliseconds)
#define LIS3DH_CLK 9
#define LIS3DH_MISO 10
#define LIS3DH_MOSI 11

// Used for hardware & software SPI
#define LIS3DH_CS 8
 Adafruit_LIS3DH lis = Adafruit_LIS3DH();
#define CLICKTHRESHHOLD 80

void setup() {
 
  pinMode(5, OUTPUT);//alim neo6m
  //Initialize serial and wait for port to open:
  Serial1.begin(9600);
  Serial.begin(9600);
  // LowPower.attachInterruptWakeup(RTC_ALARM_WAKEUP, dummy, CHANGE);

 
  #ifndef ESP8266
  while (!Serial) yield();     // will pause Zero, Leonardo, etc until serial console opens
  #endif

  Serial.begin(9600);
    Serial.println("Adafruit LIS3DH Tap Test!");
  
     if (! lis.begin(0x18))
     {   // change this to 0x19 for alternative i2c address
       Serial.println("Couldnt start");
       while (1) yield();
     }
  Serial.println("LIS3DH found!");
  
  lis.setRange(LIS3DH_RANGE_2_G);   // 2, 4, 8 or 16 G!
  
  Serial.print("Range = "); Serial.print(2 << lis.getRange());  
  Serial.println("G");

  // 0 = turn off click detection & interrupt
  // 1 = single click only interrupt output
  // 2 = double click only interrupt output, detect single click
  // Adjust threshhold, higher numbers are less sensitive
  lis.setClick(2, CLICKTHRESHHOLD);
  delay(100);
  SigFox.begin();
  SigFox.reset();
  delay(100);
  SigFox.debug();
  delay(3000);
}

    typedef struct __attribute__((packed)) sigFox_Message 
    {    
      float longitude;
      float latitude;
      int8_t vitesse;
      uint8_t nbre_sat;
  
    } 
  
    SigFoxMessage ;
    SigFoxMessage msg;
  
 
void loop() 
{
  
 
  
    uint8_t click = lis.getClick();
    if (click == 0) return;
    if (! (click & 0x30)) return;
    Serial.print("Click detected (0x"); Serial.print(click, HEX); Serial.print("): ");
    if (click & 0x10) Serial.print(" single click");
    if (click & 0x20) Serial.print(" double click");
    Serial.println();
       if (click & 0x10) 
       {
         digitalWrite(5, HIGH);//gate transistor pour alim GPS
         Serial.begin(9600);
         Serial1.begin(9600);
         delay(30000);//delai pour init gps
           while (Serial1.available())
           {
             data = Serial1.read();
             //  Serial.print(data);
             gps.encode(data);
   
             latitude = gps.location.lat();
             longitude = gps.location.lng();
             alt = gps.altitude.meters();
             vitesse = gps.speed.kmph();
             nbre_sat = gps.satellites.value();
 
             Serial1.println("-------- FIX GPS ------------");
             Serial.print("LATITUDE="); Serial.println(latitude,4);
             Serial.print("LONGITUDE="); Serial.println(longitude,4);
             Serial.print("ALTITUDE (m) ="); Serial.println(alt);
             Serial.print("VITESSE (km/h)="); Serial.println(vitesse);
             Serial.print("NOMBRE SATTELLITES="); Serial.println(nbre_sat);
    
             SigFox.begin();
             SigFox.reset();
             delay(100);
             SigFox.debug();
             delay(2000);
             msg.longitude = (float)longitude;
             msg.latitude = (float)latitude;
             msg.vitesse = (uint8_t)vitesse;
             msg.nbre_sat = (uint8_t)nbre_sat;
 
            SigFox.beginPacket();
            SigFox.write((uint8_t*)&msg,sizeof(msg));
            SigFox.endPacket(false);
            SigFox.end();
            delay(100);
            digitalWrite(5, LOW);
            return;
 
 
            //Sleep for 3 minutes:180000 for 11minutes: 660000
             delay(20000);
              //LowPower.sleep(660000);
              // LowPower.deepSleep(uint32_t(SLEEPTIME));
          }

  
  
  
       }
 
  }
// void dummy() {
  
// This function will be called once on device wakeup
// You can do some little operations here (like changing variables which will be used in the loop)
// Remember to avoid calling delay() and long running functions since this functions executes in interrupt context
//} 

The problem: I can't send the variable value latitude, longitude, speed and number of sat
I tested the GPS alone: ​​it works
I tested the accelerometer alone and it also works
The MKRFOX 1200 card does send longitude, latitude, speed and number of satellites variables but their value is always equal to 0.000
I have the impression that in my program there is a conflict which prevents updating the GPS variables but I cannot solve this problem
I hope I was clearer than in my first message and hope that you can bring me a solution
Cordially
Pierre-Yves SEGOT

Few people will download code. Post it, using code tags, as described in the "How to get the best out of the forum" post.

Describe in detail what you have done to debug the problem.

Finally, post a clearly labeled, hand drawn wiring diagram, and links to the components.

Sorry for inaccuracy.
the context: I want to make a tracker transmitting on the SigFox network, allowing to position a hive, to be warned in the event of displacement and to be able to follow this displacement.
This tracker must have an autonomy of 1 year minimum and that is why I use an accelerometer to start the gps only in case of movement.
the equipment is a MKRFOX 1200 card + a neo6m gps and an adafruit lish3d accelerometer.
I add a mosfet to power the gps only in case of movement detected by the accelerometer
the timeline is:
motion scan
if movement detection: gps start, transmission of coordinates on sigfox, pause of xminutes
if no movement, return to movement scanning
the wiring diagram is attached

I uploaded sample code for gps and sample code for accelerometer
each example works with the MKRFOX1200 board
I added the two code examples and added the sigfox code to retrieve the gps data and transmit them on sigfox
Everything works except the gps data which is at 0.0000
The longitude, latitudes, ..... variables of the gps do not feed while the gps flashes in red to indicate that it captures a position
I have the impression that there is a conflict between my components but I cannot determine which one
I hope to have been more precise but do not master English (French)
shema tracker sigfox.pdf (195,2 Ko)

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