Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 19 of 19

Thread: GPS sensor (GY-NEO 6MV2) with teensy 3.2

  1. #1
    Junior Member
    Join Date
    Aug 2020
    Posts
    10

    GPS sensor (GY-NEO 6MV2) with teensy 3.2

    Hi,
    We have teensy 3.2 and we want to use GPS sensor which have GY-NEO 6MV2. We don't get any data, but it works on arduino.
    Additionally we have pressure/temperature/gyro sensor (10-DOF IMU), SD card module (arduino), wifi module (esp8266), buzzer, voltage divider (we measure with analog input pin). All of these work good (without GPS sensor). But when we add to GPS sensor on circuit, everything goes bad. All sensors don't wor

    We don't understand, where do we go wrong.

    Code:

    Code:
    #include <Wire.h>
    #include <Adafruit_BMP280.h>
    #include <OneWire.h>
    #include "MPU9255.h"
    #include <TinyGPS.h>
    #include <SPI.h>
    #include <SD.h>
    
    int16_t accelCount[3];
    int16_t gyroCount[3];
    int16_t magCount[3];
    int16_t tempCount;
    float f_accelCount[3];
    float f_gyroCount[3];
    float f_magCount[3];
    float AccelScale, GyroScale, MagScale;
    float temperature;
    int doklG = 250; // stopni / sekunde - dokladnosc dla czujnika zyroskopowego
    int doklA = 2; // +- 2g - dokladnosc dla akcelerometru
    int doklM = 6; // 0.6 mGaussa - dokladnosc dla magnetometru
    float approxGndPress;
    
    Adafruit_BMP280 bmp; // inicjalizacja czujnika cisnienia/altymetru + termometru
    MPU9255 mpu(12, doklG, doklA,doklM); // inicjalizacja akcelerometru-zyroskopu-magnetometru
    
    /* START GPS */
    TinyGPS gps;
    
    void gpsdump(TinyGPS &gps);
    String printFloat(double f = 0, int digits = 2);
    
    /* END GPS */
    
    
    /* START WIFI */
    
    String agAdi = "POCOFONE";                 //Ağımızın adını buraya yazıyoruz.    
    String agSifresi = "fener1234";           //Ağımızın şifresini buraya yazıyoruz.
    
    //esp nin rx = 1 - tx = 0
    
    String ip = "184.106.153.149";                                //Thingspeak ip adresi
    float sicaklik, nem;
    
    /* END WIFI */
    
    /* START VOLTAJ BOLUCU */
    int analogInput = 0;
    float vout = 0.0;
    float vin = 0.0;
    float R1 = 100000.0; // 100K ohm direnç
    float R2 = 10000.0; // 10K ohm direnç
    int valueVoltajBolucu = 0;
    /* END VOLTAJ BOLUCU */
    
    /* START SD CARD ADAPTOR */
    Sd2Card card;
    SdVolume volume;
    SdFile root;
    
    const int chipSelect = 4;  
    File myFile;
    /* END SD CARD ADAPTOR */
    
    int buzzerPin = 20;
    
    int paketNo = 1;
    
    
    bool espBuldu = false;
    
    String telemetri = "";
    
    String sdCardFile = "21072020.txt";
    
    boolean sdError = false;
     
    void setup()
    {
      delay(2000);
      
      Serial.begin(115200);
      
      pinMode(analogInput, INPUT); // voltaj bolucu - a0 (14)
      
      pinMode(buzzerPin, OUTPUT); //BUZZER
      
      /* START SD CARD ADAPTOR */
    
      SPI.setCS(4);
    
       Serial.print("\nInitializing SD card...");
    
      pinMode(chipSelect, OUTPUT);     
      
     sdError = false;
     
      if (!card.init(SPI_QUARTER_SPEED, chipSelect)) {
        Serial.println("initialization failed. Things to check:");
        Serial.println("* is a card is inserted?");
        Serial.println("* Is your wiring correct?");
        Serial.println("* did you change the chipSelect pin to match your shield or module?");
        sdError = true;
      } else {
       Serial.println("Wiring is correct and a card is present.");
      }
    
      
      // print the type of card
      Serial.print("\nCard type: ");
      switch(card.type()) {
        case SD_CARD_TYPE_SD1:
          Serial.println("SD1");
          break;
        case SD_CARD_TYPE_SD2:
          Serial.println("SD2");
          break;
        case SD_CARD_TYPE_SDHC:
          Serial.println("SDHC");
          break;
        default:
          Serial.println("Unknown");
      }
     
      // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
      if (!volume.init(card)) {
        Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
        sdError = true;
      }
    
      if (sdError == false)
      {
            
          // print the type and size of the first FAT-type volume
          long volumesize;
          Serial.print("\nVolume type is FAT");
          Serial.println(volume.fatType(), DEC);
          Serial.println();
         
          volumesize = volume.blocksPerCluster();    // clusters are collections of blocks
          volumesize *= volume.clusterCount();       // we'll have a lot of clusters
          volumesize *= 512;                            // SD card blocks are always 512 bytes
          Serial.print("Volume size (bytes): ");
          Serial.println(volumesize);
          Serial.print("Volume size (Kbytes): ");
          volumesize /= 1024;
          Serial.println(volumesize);
          Serial.print("Volume size (Mbytes): ");
          volumesize /= 1024;
          Serial.println(volumesize);
         
          Serial.println("\nFiles found on the card (name, date and size in bytes): ");
          root.openRoot(volume);
         
          // list all files in the card with date and size
          root.ls(LS_R | LS_DATE | LS_SIZE);
         
          delay(2000);
        
           if (!SD.begin(chipSelect)) {
            Serial.println("initialization failed!");
            //return;
            
          } else {
            Serial.println("SD card initialized");
            myFile = SD.open(sdCardFile.c_str(), FILE_WRITE);    // open file for writing
            if (myFile) {  // if file can be opened, write to it
              Serial.print(sdCardFile + " file opened for writing");
              myFile.close();
            } else {  // if not, show an error
              myFile.println("asdwfkq");
              Serial.println("ERROR: not able to open " + sdCardFile);
              myFile.close();
            }
          }
    
      
      }
     
      
      /* END SD CARD ADAPTOR */
      
    	Wire.begin();//inicjalizacja protokolu I2C
    	TWBR = 24;
    	mpu.initMPU9250();//inicjalizacja akcelerometru-zyroskopu
    	float magCalibration[3];
    	mpu.initAK8963(magCalibration);//inicjalizacja magnetometru
    	if (!bmp.begin()) {
    		Serial.println("10 dof imu hatali - Nie mozna nawiazac polaczenia z czujnikiem cisnienia BMP280!");
    		//while (1);
    	}
    	
      for(int i=0;i<5;i++)
      {
        approxGndPress+=bmp.readPressure();
        delay(1000);
        }
        approxGndPress/=5;
    	switch (doklG)
    	{
    	case 250: GyroScale = 131.0; break;
    	case 500: GyroScale = 65.5; break;
    	case 1000: GyroScale = 32.8; break;
    	case 2000: GyroScale = 16.4; break;
    	default: GyroScale = 131.0; break;
    	}
    	switch (doklA)
    	{
    	case 2: AccelScale = 16384.0; break;
    	case 4: AccelScale = 8192.0; break;
    	case 8: AccelScale = 4096.0; break;
    	case 16: AccelScale = 2048.0; break;
    	default: AccelScale = 16384.0; break;
    	}
    	switch (doklM)
    	{
    	case 6: MagScale=0.6; break;
    	case 15: MagScale=0.15; break;
    	default: MagScale =1; break;
    	}
    Serial.println("10 dof imu sensoru ayarlari yapildi.");
    /* START WIFI */
    
     Serial.println("WİFİ Started");
      Serial3.begin(115200);                                          //ESP8266 ile seri haberleşmeyi başlatıyoruz.
      Serial3.println("AT");                                          //AT komutu ile modül kontrolünü yapıyoruz.
      Serial.println("AT Yollandı");
      int espDenemeSayisi = 0;
      while(!Serial3.find("OK") && espDenemeSayisi < 5){                                     //Modül hazır olana kadar bekliyoruz.
        Serial3.println("AT");
        Serial.println("ESP8266 Bulunamadı."); //TODO HASAN (20 kere dene yoksa diğer kodlara geç)
        espDenemeSayisi++;
      }
    
      if (!(espDenemeSayisi >= 5))
      { 
        Serial.println("OK Komutu Alındı");
        Serial3.println("AT+CWMODE=1");                                 //ESP8266 modülünü client olarak ayarlıyoruz.
        espDenemeSayisi = 0;
        while(!Serial3.find("OK") && espDenemeSayisi < 5){                                     //Ayar yapılana kadar bekliyoruz.
          Serial3.println("AT+CWMODE=1");
          Serial.println("Ayar Yapılıyor....");
          espDenemeSayisi++;
        }
        Serial.println("Client olarak ayarlandı");
        Serial.println("Aga Baglaniliyor...");
        Serial3.println("AT+CWJAP=\""+agAdi+"\",\""+agSifresi+"\"");    //Ağımıza bağlanıyoruz.
        espDenemeSayisi = 0;
        while(!Serial3.find("OK") && espDenemeSayisi < 5)
        {
            espDenemeSayisi++;  
        }
        if (!(espDenemeSayisi >= 5))
        {
          Serial.println("Aga Baglandi.");
          espBuldu = true;
          delay(1000);
        }
        else
        {
          /*
            // _reboot_Teensyduino_();       
            */  
          Serial.println("WIFI ESP ağa bağlanmadı");
        }
        
      }
      else
      {
        Serial.println("WIFI ESP CALISMADI");
      }
      
    /* END WIFI */
    
    
      /* START GPS */
      Serial1.begin(9600);
      delay(1000);
      //Serial.println("uBlox Neo 6M");
      //Serial.print("Testing TinyGPS library v. "); Serial.println(TinyGPS::library_version());
      //Serial.println("by Mikal Hart");
      //Serial.println();
      Serial.print("Sizeof(gpsobject) = gps ayarlanacak"); 
      Serial.println(sizeof(TinyGPS));
      Serial.println(); 
      
      /* END GPS */
    
    
    
    
      /* START XBEE */
    
      Serial2.begin(9600);
      
      /* END XBEE */
    }
    void loop()
    {
    
      
      /* START GPS */
    
       long lat, lon;
        float flat = 5.33642, flon = 1.263321;
        unsigned long age1, date, time, chars;
        int year;
        byte month, day, hour, minute, second, hundredths;
        unsigned short sentences, failed;
      
    while(0)
    {
      
      
          bool newdata = false;
        unsigned long start = millis();
        // Every 5 seconds we print an update
        while (millis() - start < 5000) 
        {
          if (Serial1.available()) 
          
          {
            char c = Serial1.read();
            //Serial.print(c);  // uncomment to see raw GPS data
            //Serial.println("gps e bakıyor");
            if (gps.encode(c)) 
            {
              newdata = true;
              break;  // uncomment to print new data immediately!
            }
          }
        }
      
        
        if (newdata) 
        {
          Serial.println("Acquired Data");
          Serial.println("-------------");
          //gpsdump(gps);
          
          gps.get_position(&lat, &lon, &age1);
          Serial.print("Lat/Long(10^-5 deg): "); Serial.print(lat); Serial.print(", "); Serial.print(lon); 
          //Serial.print(" Fix age: "); Serial.print(age); Serial.println("ms.");
          
          // On Arduino, GPS characters may be lost during lengthy Serial.print()
          // On Teensy, Serial prints to USB, which has large output buffering and
          //   runs very fast, so it's not necessary to worry about missing 4800
          //   baud GPS characters.
    
          age1 = 0;
          
          gps.f_get_position(&flat, &flon, &age1);
          Serial.print("Lat/Long(float): "); printFloat(flat, 7); Serial.print(", "); printFloat(flon, 7);
            //Serial.print(" Fix age: "); Serial.print(age); Serial.println("ms.");
        
          age1 = 0;
          
          gps.get_datetime(&date, &time, &age1);
          Serial.print("Date(ddmmyy): "); Serial.print(date); Serial.print(" Time(hhmmsscc): ");
            Serial.print(time);
          //Serial.print(" Fix age: "); Serial.print(age); Serial.println("ms.");
        
          gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &age1);
          Serial.print("Date: "); Serial.print(static_cast<int>(month)); Serial.print("/"); 
            Serial.print(static_cast<int>(day)); Serial.print("/"); Serial.print(year);
          Serial.print("  Time: "); Serial.print(static_cast<int>(hour+8));  Serial.print(":"); //Serial.print("UTC +08:00 Malaysia");
            Serial.print(static_cast<int>(minute)); Serial.print(":"); Serial.print(static_cast<int>(second));
            Serial.print("."); Serial.print(static_cast<int>(hundredths)); Serial.print(" UTC +08:00 Malaysia");
          //Serial.print("  Fix age: ");  Serial.print(age); Serial.println("ms.");
        
          Serial.print("Alt(cm): "); Serial.print(gps.altitude()); Serial.print(" Course(10^-2 deg): ");
            Serial.print(gps.course()); Serial.print(" Speed(10^-2 knots): "); Serial.println(gps.speed());
          Serial.print("Alt(float): "); printFloat(gps.f_altitude()); Serial.print(" Course(float): ");
            printFloat(gps.f_course()); Serial.println();
          Serial.print("Speed(knots): "); printFloat(gps.f_speed_knots()); Serial.print(" (mph): ");
            printFloat(gps.f_speed_mph());
          Serial.print(" (mps): "); printFloat(gps.f_speed_mps()); Serial.print(" (kmph): ");
            printFloat(gps.f_speed_kmph()); Serial.println();
        
          gps.stats(&chars, &sentences, &failed);
          Serial.print("Stats: characters: "); Serial.print(chars); Serial.print(" sentences: ");
            Serial.print(sentences); Serial.print(" failed checksum: "); Serial.println(failed);
        
        
      
          
          Serial.println("-------------");
          Serial.println();
      
    
          break;
        }
    
       
      
    }
      
      /* END GPS */
      
    /* START 10 DOF İMU */
    
    		mpu.readAccelData(f_accelCount);
        
        for(int i=0;i<3;i++)f_accelCount[i]/=AccelScale; // podziel kazda ze skladowych przyspieszenia przez czynnik skali dla akcelerometru
    
          Serial.print("\tax "); Serial.print(f_accelCount[0]);
    		Serial.print("\tay "); Serial.print(f_accelCount[1]);
    		Serial.print("\taz "); Serial.print(f_accelCount[2]);
    
    		tempCount = mpu.readTempData();
    		Serial.print("\tT ");
    		Serial.print(tempCount / 100.0);
    		Serial.print(" *C");
    		Serial.print("\tP = ");
    		Serial.print(bmp.readPressure()/100.0);
    		Serial.print(" hPa");
    		Serial.print("\tApprox alt = ");
    		Serial.print(bmp.readAltitude(1019.0)); // wysokość liczona wzgledem cisnienia przy powierzchni
    		Serial.println(" m");
    
    /* END 10 DOF İMU */
    
    /* START WIFI */
    
        if (espBuldu == true)
        {
             Serial3.println("AT+CIPSTART=\"TCP\",\""+ip+"\",80");           //Thingspeak'e bağlanıyoruz.
              if(Serial3.find("Error")){                                      //Bağlantı hatası kontrolü yapıyoruz.
                Serial.println("AT+CIPSTART Error");
               }
      
              String tweet = "POST /apps/thingtweet/1/statuses/update HTTP/1.1\n";
                  tweet+="Host: api.thingspeak.com\n";
                  tweet+="Connection: close\n";
                  tweet+="Content-Type: application/x-www-form-urlencoded\n";
                  tweet+="Content-Length:51\r\n\r\napi_key=";
                  tweet+=String("9E5QX2123KGHVXLB");                             //ThingSpeak'den aldığımız Twitter API KEY'ini buraya yazıyoruz.
                  tweet+=String("&status=");
                  tweet+=String("#helloesp8266 Try 2");                           // Yollamak istediğimiz tweeti buraya yazıyoruz.
              
               Serial3.print("AT+CIPSEND=");                    //veri yollayacağımız zaman bu komutu kullanıyoruz. Bu komut ile önce kaç tane karakter yollayacağımızı söylememiz gerekiyor.
               delay(100);
               Serial3.println(tweet.length());
               
               if(Serial3.find(">")){                           //eğer sunucu ile iletişim sağlayıp komut uzunluğunu gönderebilmişsek ESP modülü bize ">" işareti ile geri dönüyor.
                                                               // arduino da ">" işaretini gördüğü anda sıcaklık verisini esp modülü ile thingspeak sunucusuna yolluyor.
                 Serial3.println(tweet);
                 Serial3.println("AT+CIPCLOSE=0");
                
                 Serial.println(tweet);
                    Serial.println("tweet gonderildi.");
                    
                }
              
                Serial.println("Baglantı Kapatildi.");
                Serial3.println("AT+CIPCLOSE");                                //Bağlantıyı kapatıyoruz
                
    
        }
        
    /* END WIFI */
    
    
      /* START VOLTAJ BOLUCU */
       valueVoltajBolucu = analogRead(analogInput);
       Serial.print("value= ");
    
        Serial.println(valueVoltajBolucu);
        
       vout = (valueVoltajBolucu * 5) / 1024.0; 
       vin = vout / (R2/(R1+R2)); 
       if (vin<0.09) {
          vin=0.0;
        } 
        Serial.print("VOLTAJ Vout= ");
    
        Serial.println(vout);
        
        Serial.print("VOLTAJ Vin= ");
    
        Serial.println(vin);
        
        /* END VOLTAJ BOLUCU */
    
      telemetri = "3431,";
      
      telemetri += String(paketNo) + ",";
    
      //double vout2 = static_cast<double>(vout);
      //vout2 = 50001.0;
      //String vout3 = String(vout2).substring(0,3);
      //Serial.println(vout3);
      paketNo++;
        telemetri += String(static_cast<int>(day)) + "/" + String(static_cast<int>(month)) + "/" + String(year);
        telemetri += "-" + String(static_cast<int>(hour+3)) + ":" + String(static_cast<int>(minute)) + ":" + String(static_cast<int>(second)) + ",";
        telemetri += "UYDU STATUSU,";
        telemetri += String(bmp.readAltitude(1019.0)) + ","; // yükseklik
        telemetri += String(bmp.readPressure()/100.0) + ","; // basınc
        telemetri += String(tempCount / 100.0) + ","; //sıcaklık
        telemetri += String(vin,2) + ","; //pil gerilimi (voltaj bolucu)
        telemetri += String(f_accelCount[0]) + ","; //yunuslama (ax)
        telemetri += String(f_accelCount[1]) + ","; //yalpalanma (ay)
        telemetri += String(f_accelCount[2]) + ","; //yuvarlanma (az)
        //telemetri += String(printFloat(flat, 5)) + ","; //boylam (latitute)
        //telemetri += String(printFloat(flon, 5)) + ","; //enlem (longitute)
        telemetri += String(flat,7) + ","; //boylam (latitute)
        telemetri += String(flon,7) + ","; //enlem (longitute)
        
        telemetri += String(gps.altitude()) + ",F:"; //gps yukseklik (altitude cm)
        telemetri += String(gps.f_altitude());
    /*
     * 
     * 
     * 
     * <3431>,<13>,<29/08/2020-12:37:48>, <3>, <153.75>, <101900>,<22.3>,<3.7>,<23.44>,<13.89>,<21.03>,<28.539>,<41.02>,<14.5>
    
    
    < Takım Numarası >, < Paket Numarası >, < Gönderme Zamanı >, < Uydu Statüsü >, <Yükseklik>, <Basınç>, < Sıcaklık >, < Pil Gerilimi >, < Yunuslama >, < Yalpalanma >, <Yuvarlanma >, < GPS Boylam >, < GPS Enlem >, < GPS Yükseklik >
    
    
    
     */
        Serial.println("\ntelemetri verisi:");
        Serial.println(telemetri);
    
    
        /* START SD KART */
       myFile = SD.open(sdCardFile.c_str(), FILE_WRITE);            
                      myFile.println(telemetri);
                      Serial.println("SD Karta kaydedildi. Paket: " + String(paketNo)); //Yazılanları ekstra ekranda görmek için..
    
                      myFile.close();
    
        /* END SD KART */
    
        
        /* START XBEE */
    
      Serial2.println(telemetri);//Ending symbol
      
        /* END XBEE */
        
        tone(buzzerPin, 440);
    delay(400);
    
        noTone(buzzerPin);
      
        
    
    
        
    }
    
    
    
    /* START GPS FUNCTIONS */
    
    void gpsdump(TinyGPS &gps)
    {
     
    }
    
    String printFloat(double number, int digits)
    {
      String returnValue = "";
      
      // Handle negative numbers
      if (number < 0.0) 
      {
         Serial.print('-');
         returnValue += "-";
         
         number = -number;
      }
    
      // Round correctly so that print(1.999, 2) prints as "2.00"
      double rounding = 0.5;
      for (uint8_t i=0; i<digits; ++i)
        rounding /= 10.0;
      
      number += rounding;
    
      // Extract the integer part of the number and print it
      unsigned long int_part = (unsigned long)number;
      double remainder = number - (double)int_part;
      Serial.print(int_part);
      returnValue += String(int_part);
    
      // Print the decimal point, but only if there are digits beyond
      if (digits > 0)
      {
        Serial.print("."); 
        returnValue += ".";
      }
      
      // Extract digits from the remainder one at a time
      while (digits-- > 0) 
      {
        remainder *= 10.0;
        int toPrint = int(remainder);
        Serial.print(toPrint);
        returnValue += String(toPrint);
        remainder -= toPrint;
      }
    }
    
    /* END GPS FUNCTIONS */

  2. #2
    Senior Member PaulS's Avatar
    Join Date
    Apr 2015
    Location
    Netherlands
    Posts
    295
    Merhaba!
    What I usually do in these cases is to check whether you can get the GPS device to work with the Teensy exclusively, without any other devices attached.
    Start with the basic GPS test sketch and see if you get that to work on the Teensy 3.2. That way you are sure the hardware/wiring is OK.

    Paul

  3. #3
    Junior Member
    Join Date
    Aug 2020
    Posts
    10
    Merhaba
    Thank you for your answer.
    Actually we used this GPS test skech, but it didn't work. It worked with Arduino Uno, but not Teensy 3.2. Because of this, we don't think it's about hardware or wiring. Also we bought a new gps sensor when the first one did not work.
    Do you have any other ideas as to why this is so?

    Yagmur

  4. #4
    Senior Member PaulS's Avatar
    Join Date
    Apr 2015
    Location
    Netherlands
    Posts
    295
    Can you show us how your wiring is from Teensy 3.2 to the uBlox module, which specific module you purchased and what specific code did not work?
    I saw that 2 pins on the uBlox module need to be set for baudrate, perhaps your module is not set for 9600 baud?
    And perhaps this thread is useful?

    Paul

  5. #5
    Junior Member
    Join Date
    Aug 2020
    Posts
    10
    The module is set for 9600 baud. The picture of wiring is below. When we used test code, data looks like this on serial port:

    **** ******** ******** ********* ****** **** ********** ****** 9864 7496

    The sensor is not with me now, but I'm sure there are many *****

    Click image for larger version. 

Name:	WhatsApp Image 2020-08-13 at 20.05.55.jpg 
Views:	31 
Size:	53.1 KB 
ID:	21365

  6. #6
    Senior Member PaulS's Avatar
    Join Date
    Apr 2015
    Location
    Netherlands
    Posts
    295
    If I see correctly on the photo, only the TX pin of the module is connected to the RX1 pin [pin 0] on the Teensy?
    What about the RX pin on the module connected to the TX1 [pin 1] on the Teensy?
    As far as I understood the module needs to be given a command to do a GPS read for example.
    See also this page.

    Paul

  7. #7
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,452
    The example in msg #2 uses SoftwareSerial on pins 3 and 4 at 4800 baud instead of Serial1 on pins 0 and 1 at 9600 baud.
    Try this code which reads the raw GPS output at 9600 baud on Serial1. It works with a NEO 6M.
    Code:
    #define GPS_SERIAL Serial1
    
    // Very basic sketch to monitor GPS data from GPS_SERIAL 
    void setup() {
      GPS_SERIAL.begin(9600);
      Serial.begin(9600);
    }
    
    void loop() {
      // while there's data from the GPS, send it to the computer
      while(GPS_SERIAL.available() > 0) {
        Serial.write(GPS_SERIAL.read());
      }
      // while there's data from the computer, send it to the GPS
      while(Serial.available() > 0) {
        GPS_SERIAL.write(Serial.read());
      }  
    
    }
    Pete

  8. #8
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,585
    Quote Originally Posted by ymrkrn View Post
    The module is set for 9600 baud. The picture of wiring is below. When we used test code, data looks like this on serial port:

    **** ******** ******** ********* ****** **** ********** ****** 9864 7496

    The sensor is not with me now, but I'm sure there are many *****
    The output you provide suggests the Serial connection is good, but that the GPS is not getting locked in. Does GPS have an LED that flashes when GPS is locked in?
    el_supremo's sketch in post #7 should reveal the NMEA sentences from the GPS and probably will confirm the GPS isn't seeing enough satellites. Maybe move your GPS+antenna closer to a window and away from interferring frequency devices. With an active antenna sitting on window sill I get satellite lock within a few seconds on a u-blox GPS.

    u-blox GPS (3.3v) with no lock on T3.2 Serial1@9600
    Code:
    NMEA from GPS
    $GNRMC,,V,,,,,,,,,,N*4D
    $GNVTG,,,,,,,,,N*2E
    $GNGGA,,,,,,0,00,99.99,,,,,,*56
    $GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*2E
    $GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*2E
    $GPGSV,1,1,00*79
    $GLGSV,1,1,00*65
    $GNGLL,,,,,,V,N*7A
    $GNRMC,,V,,,,,,,,,,N*4D
    $GNVTG,,,,,,,,,N*2E
    $GNGGA,,,,,,0,00,99.99,,,,,,*56
    $GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*2E
    $GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*2E
    $GPGSV,1,1,00*79
    $GLGSV,1,1,00*65
    $GNGLL,,,,,,V,N*7A
    
    output from TinyGPS example
    **** **** ********* ********** **** ********** ******** **** ****** ****** ***** ***   *******  ****** ***   8100  0         0        
    **** **** ********* ********** **** ********** ******** **** ****** ****** ***** ***   *******  ****** ***   8325  0         0        
    **** **** ********* ********** **** ********** ******** **** ****** ****** ***** ***   *******  ****** ***   8550  0         0        
    **** **** ********* ********** **** ********** ******** **** ****** ****** ***** ***   *******  ****** ***   8775  0         0
    Last edited by manitou; 08-15-2020 at 11:31 AM.

  9. #9
    Junior Member
    Join Date
    Aug 2020
    Posts
    10
    Thank you for all answers.
    We managed to operate the GPS sensor alone. But now we are trying to run the GPS sensor and the SD card module together. When we plug in the gnd and vcc of the gps sensor, sd card module doesn't work. There is only the sd card module in the code. We are sure that the GPS sensor sees satellites and trying outdoors. What could this problem be caused by?

    Code:
    #include <SPI.h>
    #include <SD.h>
     
    // set up variables using the SD utility library functions:
    Sd2Card card;
    SdVolume volume;
    SdFile root;
    
    const int chipSelect = 10;  
    File myFile;
    
    int indis = 0;
    
    // set up the speed, mode and endianness of each device
    SPISettings settingsA(2000000, MSBFIRST, SPI_MODE3); 
    SPISettings settingsB(16000000, LSBFIRST, SPI_MODE3); 
    
    void setup()
    {
      delay(2000);
      Serial.begin(9600);
      Serial.print("\nInitializing SD card...");
    
      pinMode(chipSelect, OUTPUT);     
     
      if (!card.init(SPI_QUARTER_SPEED, chipSelect)) {
        Serial.println("initialization failed. Things to check:");
        Serial.println("* is a card is inserted?");
        Serial.println("* Is your wiring correct?");
        Serial.println("* did you change the chipSelect pin to match your shield or module?");
        return;
      } else {
       Serial.println("Wiring is correct and a card is present.");
      }
     
      // print the type of card
      Serial.print("\nCard type: ");
      switch(card.type()) {
        case SD_CARD_TYPE_SD1:
          Serial.println("SD1");
          break;
        case SD_CARD_TYPE_SD2:
          Serial.println("SD2");
          break;
        case SD_CARD_TYPE_SDHC:
          Serial.println("SDHC");
          break;
        default:
          Serial.println("Unknown");
      }
     
      // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
      if (!volume.init(card)) {
        Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
        return;
      }
     
      // print the type and size of the first FAT-type volume
      long volumesize;
      Serial.print("\nVolume type is FAT");
      Serial.println(volume.fatType(), DEC);
      Serial.println();
     
      volumesize = volume.blocksPerCluster();    // clusters are collections of blocks
      volumesize *= volume.clusterCount();       // we'll have a lot of clusters
      volumesize *= 512;                            // SD card blocks are always 512 bytes
      Serial.print("Volume size (bytes): ");
      Serial.println(volumesize);
      Serial.print("Volume size (Kbytes): ");
      volumesize /= 1024;
      Serial.println(volumesize);
      Serial.print("Volume size (Mbytes): ");
      volumesize /= 1024;
      Serial.println(volumesize);
     
      Serial.println("\nFiles found on the card (name, date and size in bytes): ");
      root.openRoot(volume);
     
      // list all files in the card with date and size
      root.ls(LS_R | LS_DATE | LS_SIZE);
     
      delay(2000);
    
       if (!SD.begin(chipSelect)) {
        Serial.println("initialization failed!");
        //return;
        
      } else {
        Serial.println("SD card initialized");
        myFile = SD.open("GPS2.txt", FILE_WRITE);    // open file for writing
        if (myFile) {  // if file can be opened, write to it
          Serial.print("GPS2.txt file opened for writing");
          myFile.close();
        } else {  // if not, show an error
          Serial.println("ERROR: not able to open GPS.txt");
        }
      }
    }
    void loop() {
    
                      int recNum = 0; // We have read 0 records so far
                      
                      myFile = SD.open("GPS2.txt", FILE_WRITE);            
                      myFile.println("Yazdırılacak Veri : " + String(indis));
                      indis++;
                      Serial.println("Yazdırılacak Veri"); //Yazılanları ekstra ekranda görmek için..
    
                      myFile.close();
                      delay(2000);
    
                      myFile = SD.open("GPS2.txt", FILE_READ);  
    
                       //open a file
                       //OpenFile("GPS2.txt");
                      
                       while (myFile.available())
                       {
                          String list = myFile.readStringUntil('\r');
                          Serial.println(list);
                          recNum++; // Count the record
                      
                          if(recNum == 1)
                          {
                             // Hey, we found the one that we want to do something with
                             //Serial.println(recNum);
                          }
                       }
    
                      myFile.close();
                Serial.println("dosya okundu.");
                   delay(2000);
    }
    
    int OpenFile(char Filename[]){
      myFile = SD.open(Filename, FILE_WRITE);
      myFile = SD.open(Filename, FILE_READ);
      delay(500);
      if(myFile)
      {
        Serial.println("File is open");
        return 1;
      }else{
        Serial.println("Error opening file");
        return 0;
      }
    }
    Last edited by ymrkrn; 08-17-2020 at 08:29 AM.

  10. #10
    Senior Member PaulS's Avatar
    Join Date
    Apr 2015
    Location
    Netherlands
    Posts
    295
    Quote Originally Posted by ymrkrn View Post
    When we plug in the gnd and vcc of the gps sensor, sd card module doesn't work.
    What does "doesn't work" exactly mean? Do you see "Initializing SD card..." on the serial monitor? Or do you see another message?

    If you only plug in VCC & GND of the GPS sensor and then it fails, that's very weird. Power supply issue?
    Did you hookup the RX & TX lines of the GPS module to the Teensy 3.2 as well when it failed?

    If possible, can you send a photo of the setup that fails?

    Paul

  11. #11
    Junior Member
    Join Date
    Aug 2020
    Posts
    10
    Quote Originally Posted by PaulS View Post
    Did you hookup the RX & TX lines of the GPS module to the Teensy 3.2 as well when it failed?
    Paul
    Yes.

    What does "doesn't work" exactly mean? Do you see "Initializing SD card..." on the serial monitor? Or do you see another message?
    Message on the serial monitor:
    Initializing SD card...initialization failed. Things to check:

    * is a card is inserted?

    * Is your wiring correct?

    * did you change the chipSelect pin to match your shield or module?


    the file has been read


    the file has been read


    the file has been read


    the file has been read


    like this.

    I can't send a photo right now, because of the wifi problem. sorry.

  12. #12
    Senior Member PaulS's Avatar
    Join Date
    Apr 2015
    Location
    Netherlands
    Posts
    295
    Allright. What happens if you only connect VCC & GND of the GPS module, so without RX & TX wires. Does SD still fail?

    Paul

  13. #13
    Junior Member
    Join Date
    Aug 2020
    Posts
    10
    Yes, we tried it and it's still fail. We saw the same message at the serial monitor.

  14. #14
    Senior Member PaulS's Avatar
    Join Date
    Apr 2015
    Location
    Netherlands
    Posts
    295
    Very strange.
    To make sure the GPS module is working OK, I would try the setup as in the picture below and check if you can run Pete's code in message #7.
    It worked perfect in my setup.

    Paul

    Click image for larger version. 

Name:	IMG_20200817_143828.jpg 
Views:	16 
Size:	77.5 KB 
ID:	21405

  15. #15
    Junior Member
    Join Date
    Aug 2020
    Posts
    10
    Yes, we tried code in message #7 and it didn't work. then we fix the problem and gps sensor worked on teensy. Now we are trying to run the GPS sensor and the SD card module together, with the code at the message #9. it didn't work.

  16. #16
    Senior Member PaulS's Avatar
    Join Date
    Apr 2015
    Location
    Netherlands
    Posts
    295
    Good to hear the GPS module is working now.
    I assume that the SD card error is still Initializing SD card...initialization failed ?
    What SD card shield are you exactly using and how is it connected?

    Paul

  17. #17
    Junior Member
    Join Date
    Aug 2020
    Posts
    10
    Yes, it' same error still.
    We use arduino sd card module and the wiring is below.

  18. #18
    Senior Member PaulS's Avatar
    Join Date
    Apr 2015
    Location
    Netherlands
    Posts
    295
    If I see the photo correctly than CS [green wire] is connected to Teensy pin 15. That should be pin 10. Your code states const int chipSelect = 10;

    Paul

  19. #19
    Junior Member
    Join Date
    Aug 2020
    Posts
    10
    Hi, finally we solved the problem. By the way I sent old code, we changed it to pin 10.

    The main problem is that the current is not enough. Because we suplly the system with usb, but GPS sensor needs 5 V. We used battery and everything is ok!

    Thanks for all the help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •