Gps and screen issue (i2c、zed f9p、ssd1302、sd card)

Hi,
I'm working on a project logging gps file and temperature.
And i want a screen to show some information.
After wiring all the chip and coding.
Everything is going well.
But for a while some issue is coming out.
After about 30 seconds.
File is keep logging,but slow,gps time stopped,and screen stop working.
Won't happening when no screen connected.
Only happening when gps get signal(antenna connected)
Add 4.7k or 10k pull-up resistor still the same.
help bro

mcu:teensy 4.0
gps:zed f9p
screen:ssd1306 or lcd1602(also dead)

connection:
vin:usb or 3.7v(18650) to vin pin
vcc:3.3v
gnd:gnd

i2c(f9p、ssd1306):
sda:18
scl:17

spi(sd card):
cs:10
mosi:11
miso:12
sck:13

dht22 out pin:14
ntc10k analog pin:15
hc-12 rx:
hc-12 tx:
hc-12 set:9
led:4

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "DHT.h"
#include <SD.h>
#include <SoftwareSerial.h>
#include <digitalWriteFast.h>
//#include "FS.h"

#include <SparkFun_u-blox_GNSS_v3.h> //Click here to get the library: http://librarymanager/All#SparkFun_u-blox_GNSS_v3
SFE_UBLOX_GNSS myGNSS;

File logFile;

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define NUMFLAKES     10 // Number of snowflakes in the animation example
#define LOGO_HEIGHT   16
#define LOGO_WIDTH    16
static const unsigned char PROGMEM logo_bmp[] =
{ 0b00000000, 0b11000000,
  0b00000001, 0b11000000,
  0b00000001, 0b11000000,
  0b00000011, 0b11100000,
  0b11110011, 0b11100000,
  0b11111110, 0b11111000,
  0b01111110, 0b11111111,
  0b00110011, 0b10011111,
  0b00011111, 0b11111100,
  0b00001101, 0b01110000,
  0b00011011, 0b10100000,
  0b00111111, 0b11100000,
  0b00111111, 0b11110000,
  0b01111100, 0b11110000,
  0b01110000, 0b01110000,
  0b00000000, 0b00110000
};

#define DHTPIN 14     // Digital pin connected to the DHT sensor
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
DHT dht(DHTPIN, DHTTYPE);

int analogPin = 15;
int Vin = 3.3;
double Vout = 0;
double R1 = 995;
double R2 = 0;
float ntc10 = 0;

const int SD_CS = 10;
String logFileName, logFileName2, logdata, flydata,  gpstimedata; // Rotordata;
const int beeper = 4;
long values[10], t[12];
double x[3], y[3], z[3], xm[7], ym[7], zm[7], gx1, gy1, gz1, t0, timee = 0, f, f2, tm[7], tg; //, x1, y1, z1
int maxsize = 31457280;//31457280=30mb 209715200=200mb 262144000=250mb = 250*2^20;
unsigned long i = 0, t1, beepert;
int setpin = 9;
extern float tempmonGetTemp(void);
double tt[10];
long ii = 50; long iii = 100;
int delayy = 0, setF = 20;
int gt[10];
float dh, dt, df;
double accu;

const int sd_cs = 10; //Thing Plus C
#define sdWriteSize 512 // Write data to the SD card in blocks of 512 bytes
#define fileBufferSize 16384 // Allocate 16KBytes of RAM for UBX message storage
uint8_t *myBuffer; // Use myBuffer to hold the data while we write it to SD card
unsigned long lastPrint; // Record when the last Serial print took place
int numSFRBX = 0; // Keep count of how many SFRBX message groups have been received (see note above)
int numRAWX = 0; // Keep count of how many RAWX message groups have been received (see note above)
void newSFRBX(UBX_RXM_SFRBX_data_t *ubxDataStruct)
{
  numSFRBX++; // Increment the count
}
void newRAWX(UBX_RXM_RAWX_data_t *ubxDataStruct)
{
  numRAWX++; // Increment the count
}


void setup() {
  Serial.begin(115200); // Initialize serial output via USB
  delay(100);
  Serial.println(F("Serial.begin"));
  Serial.println(F("SPI.begin"));
  SPI.begin();
  delay(100);

  Serial.println(F("Wire.begin"));
  Wire.begin();

  pinMode(beeper, OUTPUT);

  Serial.println(F("DHTxx test!"));

  //dht.begin();
  pinMode(15, INPUT);

  if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
    Serial.println(F("SSD1306 allocation failed"));
  }

  Serial.println(F("SD.begin"));
  if (!SD.begin(SD_CS)) {
    Serial.println(F("Card failed, or not present"));
  }

  while (!SD.begin(SD_CS)) {
    Serial.println(F("Card failed, or not present"));
    digitalWrite(beeper, HIGH);
    delay(500);
    digitalWrite(beeper, LOW);
    delay(500);
  }

 
  ////////////////gps setting/////////////////
  myGNSS.setFileBufferSize(fileBufferSize); // setFileBufferSize must be called _before_ .begin
  if (myGNSS.begin() == false) //Connect to the u-blox module using Wire port
  {
    Serial.println(F("u-blox GNSS not detected at default I2C address. Please check wiring. Freezing..."));
    while (1);
  }
  myGNSS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
  myGNSS.saveConfigSelective(VAL_CFG_SUBSEC_IOPORT); //Save (only) the communications port settings to flash and BBR
  myGNSS.setNavigationFrequency(5); //Produce one navigation solution per second (that's plenty for Precise Point Positioning)
  myGNSS.setAutoRXMSFRBXcallbackPtr(&newSFRBX); // Enable automatic RXM SFRBX messages with callback to newSFRBX
  myGNSS.logRXMSFRBX(); // Enable RXM SFRBX data logging
  myGNSS.setAutoRXMRAWXcallbackPtr(&newRAWX); // Enable automatic RXM RAWX messages with callback to newRAWX
  myGNSS.logRXMRAWX(); // Enable RXM RAWX data logging
  myBuffer = new uint8_t[sdWriteSize]; // Create our own buffer to hold the data while we write it to SD card

  Serial.println(F("done initialize"));
  digitalWrite(beeper, HIGH);
  delay(100);
  digitalWrite(beeper, LOW);
  delay(500);
  digitalWrite(beeper, HIGH);
  delay(100);
  digitalWrite(beeper, LOW);
  delay(2000);
}

void loop() {
  if (!logFile) {
    logFile = SD.open("gps.ubx", FILE_WRITE);
  }
  if (logFile) {
    //Serial.println("writing logFileName2");
  }
  else {
    Serial.println(F("error opening logFileName2"));
  }



  myGNSS.checkUblox(); // Check for the arrival of new data and process it.
  myGNSS.checkCallbacks(); // Check if any callbacks are waiting to be processed.

  // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

  while (myGNSS.fileBufferAvailable() >= sdWriteSize) // Check to see if we have at least sdWriteSize waiting in the buffer
  {
    //Serial.println(F("myGNSS.fileBufferAvailable(ng..."));
    myGNSS.extractFileBufferData(myBuffer, sdWriteSize); // Extract exactly sdWriteSize bytes from the UBX file buffer and put them into myBuffer

    logFile.write(myBuffer, sdWriteSize); // Write exactly sdWriteSize bytes from myBuffer to the ubxDataFile on the SD card

    // In case the SD writing is slow or there is a lot of data to write, keep checking for the arrival of new data
    myGNSS.checkUblox(); // Check for the arrival of new data and process it.
    myGNSS.checkCallbacks(); // Check if any callbacks are waiting to be processed.
  }
  logFile.close();

  gt[0] = myGNSS.getYear();
  gt[1] = myGNSS.getMonth();
  gt[2] = myGNSS.getDay();
  gt[3] = myGNSS.getHour();
  gt[4] = myGNSS.getMinute();
  gt[5] = myGNSS.getSecond();

  gt[6] = myGNSS.getSIV();
  gt[7] = myGNSS.getPositionAccuracy();
  accu = gt[7];
  accu = accu / 1000;

  gt[3] = gt[3] + 8;
  if (gt[3] >= 24) {
    gt[2] = gt[2] + 1;
    gt[3] = gt[3] - 24;
  }

  dh = dht.readHumidity() - 6;
  // Read temperature as Celsius (the default)
  dt = dht.readTemperature() - 2.8;
  // Read temperature as Fahrenheit (isFahrenheit = true)
  df = dht.readTemperature(false);

  // Check if any reads failed and exit early (to try again).
  if (isnan(dh) || isnan(dt) || isnan(df)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }

  // Compute heat index in Fahrenheit (the default)
  float hif = dht.computeHeatIndex(df, dh);
  // Compute heat index in Celsius (isFahreheit = false)
  float hic = dht.computeHeatIndex(dt, dh, false);

  gottemp();
  oled(); //display oled

  gpstimedata =  String(gt[0]) + "-" +  String(gt[1]) + "-" +  String(gt[2]) + " " +  String(gt[3]) + ":" +  String(gt[4]) + ":" +  String(gt[5]) + ", " + String(gt[6]) + ", " + String(accu, 3);
  logdata = gpstimedata + ", " +  String(timee, 3) + ", " + String(ntc10, 3) + ", " + String(dt, 3) + ", " + String(dh, 2) ;
  Serial.println(logdata);

  if (!logFile) {
    logFile = SD.open("log.csv", FILE_WRITE);
  }

  if (logFile) {
    logFile.println(logdata);
    timee=millis();
  }
  else {
    Serial.println("error opening logFileName");
  }
  logFile.close();

  delay(1);
}


void gottemp() {
  Vout = (analogRead(analogPin) * Vin) / 1024.0;
  R2 = R1 * ((Vin / Vout) - 1) / 1000;
  //ntc10=0.000001310376*R2^6 - 0.0001344363*R2^5 + 0.005704832*R2^4 - 0.1302487*R2^3 + 1.758585*R2^2 - 15.24158*R2 + 86.897; //擬合公式
  ntc10 = 0.000001310376 * pow (R2, 6 ) - 0.0001344363 * pow (R2, 5 ) + 0.005704832 * pow (R2, 4 ) - 0.1302487 * pow (R2, 3 ) + 1.758585 * pow (R2, 2 ) - 15.24158 * R2 + 86.897;
  ntc10 = ntc10 - 2.8;
}

void oled() {
  display.clearDisplay();
  display.setTextSize(1); // Draw scale text
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 0);
  display.println("Temp:");
  display.setCursor(0, 10);
  display.println(ntc10, 2);
  display.setCursor(32, 10);
  display.println("C");
  display.setCursor(0, 20);
  display.println("SIV:");
  display.setCursor(0, 30);
  display.println(gt[6]);
  display.setCursor(32, 30);
  display.setCursor(0, 40);
  display.println("Accu(m):");
  display.setCursor(0, 50);
  display.println(accu, 3);
  //// gps
  display.setCursor(60, 0);
  display.println(String(gt[0]) + "-" +  String(gt[1]) + "-" +  String(gt[2]));
  display.setCursor(60, 10);
  display.println(String(gt[3]) + ":" +  String(gt[4]) + ":" +  String(gt[5]));
  display.setCursor(60, 30);
  display.println("File:");
  display.setCursor(60, 40);
  display.println(logFileName);
  display.setCursor(60, 50);
  display.println(logFileName2);

  display.setCursor(60, 20);
  display.println(f2);
  display.setCursor(90, 20);
  display.println("hz");

  display.display();      // Show initial text
}

Maybe i should try ssd1306 spi version?

Your picture is cluttered and impossible to follow. I recommend you post an annotated schematic showing exactly how you have wired it, be sure to show all connections, power, ground, and power sources. You need to add links to technical information on each of the modules you used. What Arduino are you using.

Sorry I do not do well with word problems or frizzies.

my bad ,i edited.

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