GPS REB-5216 и REB-4216. В чём разница?

Тема в разделе "Arduino & Shields", создана пользователем ardurino, 10 янв 2018.

Метки:
  1. ardurino

    ardurino Нерд

    Здравствуйте, есть рабочий код для GPS Shield REB-4216, а уже для REB-5216 он не подходит. Видимо что-то в библиотеках изменено? Можете дать совет? Может кто-то сталкивался?
    Просто REB-4216 снят с производства и его почти не найти.
     
  2. ardurino

    ardurino Нерд

    Нашёл в чём разница. REB-4216 - не популярная модель, вместо неё лучше брать Ublox NEO-6M.
    Разница между REB-4216 и REB-5216, такая же каки между REB-4216 и Ublox NEO-6M - в ОДНОЙ лишь букве в библиотеке. Библиотека TinyGPSPlus-0.94b, в ней TinyGPS++.cpp в нём в районе 26-30 строк есть такая строчка:

    Код (C++):
     #define _GPRMCterm   "GPRMC" // REB-4216 "GPRMC" REB-5216 "GNRMC"
    Для REB-4216 "GPRMC" для REB-5216 "GNRMC", то же верно для Ublox NEO-6M - "GNRMC".

    Сам код выкладываю, но он обременён ещё и GPRS общением с сервером и измерением температуры.

    Ардуино едва справляется.

    Код (C++):
    #include "SIM900.h"
    #include <TinyGPS++.h>
    #include <SoftwareSerial.h>
    #include "inetGSM.h"
    InetGSM inet;
    //#include <math.h>
    #include <avr/wdt.h>
    #include <OneWire.h>
    //#include <DallasTemperature.h>

    #define POWER_MODE  0 // режим питания, 0 - внешнее, 1 - паразитное
    OneWire sensDs (4);  // датчик подключен к выводу 14
    /*
       This sample sketch demonstrates the normal use of a TinyGPS++ (TinyGPSPlus) object.
       It requires the use of SoftwareSerial, and assumes that you have a
       4800-baud serial GPS device hooked up on pins 4(rx) and 3(tx).
    */

    byte bufData[9];
    float temperature;
    static const int RXPin = 2, TXPin = 3;
    static const uint32_t GPSBaud = 9600;
    //double gpslat;
    String double2string(double n, int ndec){
        String r = "";
        int v = n;
        r += v;     // whole number part
        r += '.';   // decimal point
        int i;
        for (i=0;i<ndec;i++) {
            // iterate through each decimal digit for 0..ndec
            n -= v;
            n *= 10;
            v = n;
            r += v;
        }
        return r;
    };
    double temp, tempC;
    String ltd, lnd,t;
    char msg[50];
    int numdata;
    //char inSerial[50];
    int i=0;
    boolean started=false;
    volatile long cntr;

    // The TinyGPS++ object
    TinyGPSPlus gps;

    // The serial connection to the GPS device
    SoftwareSerial ss(RXPin, TXPin);


    void setup()
    {
     
    Serial.begin(9600);
      ss.begin(GPSBaud);

      Serial.println(F("GPS Strated..."));
      Serial.println();
      TCCR2A = 0;
      TCCR2B = 2;
      TCNT2=59;
      TIMSK2 |= (1 << TOIE2);

    }

    void reboot()
    {
      wdt_disable();
      wdt_enable(WDTO_15MS);
      while (1) {}
    }


    /* double Getterm(int RawADC) {
      temp = log(((10240000/RawADC) - 10000));
      temp = 1 / (0.001129148 + (0.000234125 * temp) + (0.0000000876741 * temp * temp * temp));
      temp = temp - 273.15;
      return temp;
    }

    */


    void displayInfo()
    {
       sensDs.reset();  // сброс шины
      sensDs.write(0xCC, POWER_MODE); // пропуск ROM
      sensDs.write(0x44, POWER_MODE); // инициализация измерения
      delay(900);  // пауза 0,9 сек
      sensDs.reset();  // сброс шины
      sensDs.write(0xCC, POWER_MODE); // пропуск ROM
      sensDs.write(0xBE, POWER_MODE); // команда чтения памяти датчика
      sensDs.read_bytes(bufData, 9);  // чтение памяти датчика, 9 байтов

      if ( OneWire::crc8(bufData, 8) == bufData[8] ) {  // проверка CRC
        // данные правильные
        temperature=  (float)((int)bufData[0] | (((int)bufData[1]) << 8)) * 0.0625 + 0.03125;
     
        // вывод измеренной температуры на индикаторы
                   
           
        // передача температуры на компьютер
        Serial.println(temperature);  
      }
       
     
      Serial.print(F("Location: "));
      if (gps.location.isValid())
      {
      //  sensors.requestTemperatures();
        ltd = (double2string (gps.location.lat(), 6));
        lnd = (double2string (gps.location.lng(), 6));
      //tempC = (sensors.getTempCByIndex(0));
    //  Serial.print(tempC);
       
        t = (double2string (temperature, 1));
     
         Serial.println(ltd);
         Serial.println(lnd);
       
    //  ltd = (double2string (44.391922, 5));
    // lnd = (double2string (33.794126, 5));
      //Read for new byte on serial hardware,
      //and write them on NewSoftSerial.
    // serialhwread();
      //Read for new byte on NewSoftSerial.
    // serialswread();
    InetGSM inet;
      Serial.println("GSM Shield testing.");

      //Start configuration of shield with baudrate.
      //For http uses is raccomanded to use 4800 or slower.
      if (gsm.begin(2400)){
        Serial.println("\nstatus=READY");
        started=true;
      }
      else
      {Serial.println("RESTart GSM+DisInfo");
        digitalWrite(9, HIGH);
          pinMode(9, OUTPUT);

      digitalWrite(9,LOW);

      delay(1000);

      digitalWrite(9,HIGH);

      delay(2000);

      digitalWrite(9,LOW);

      delay(3000);

        displayInfo();
        }
      delay(3000);
      Serial.println("\nstatus=IDLE");
      if(started){
        //GPRS attach, put in order APN, username and password.
        //If no needed auth let them blank.
        if (inet.attachGPRS("internet.mts.ru", "mts", "mts"))
          Serial.println("status=ATTACHED");
        else
          Serial.println("status=ERROR");
        delay(1000);
        //Read IP address.
        gsm.SimpleWriteln("AT+CIFSR");
        delay(5000);
        //Read until serial buffer is emapty.
       gsm.WhileSimpleRead();


    String str = "{\"n\":\"1\", \"t\": \"";
      str += t;
      str += "\", \"d\":\"";
      str += ltd;
      str += "\",\"g\":\"";
      str += lnd;
      str += "\", \"i\":\"2";
      //str += 28;
      str += "\"}";
     
       Serial.println(str);

      //int len = str.length()+1;
      //unsigned char* buf = new unsigned char[len];`

    // str.getBytes(buf, len);
    // Serial.println((const char*)buf);
    numdata=inet.httpPOST("site.com", 80, "/temperature ", str.c_str(), msg, 50);
    //delete buf;

        //TCP Client GET, send a GET request to the server and
        //save the reply.
    //numdata=inet.httpPOST("site.com", 80, "/temperature ", "{\"n\":\"2\", \"t\": \"22\", \"d\":\"44.752095\",\"g\":\"34.554844\", \"i\":\"8\"}",msg,50);
        //Print the results.
        Serial.println("\nNumber :");
        Serial.println(numdata);
        Serial.println("\nData :");
        Serial.println(msg);
     
        Serial.begin(9600);
      ss.begin(GPSBaud);

      }
       
       
      }
      else
      {
        Serial.print(F("INVALID"));
      }

      Serial.print(F("  Date/Time: "));
      if (gps.date.isValid())
      {
        Serial.print(gps.date.month());
        Serial.print(F("/"));
        Serial.print(gps.date.day());
        Serial.print(F("/"));
        Serial.print(gps.date.year());
      }
      else
      {
        Serial.print(F("INVALID"));
      }

      Serial.print(F(" "));
      if (gps.time.isValid())
      {
        if (gps.time.hour() < 10) Serial.print(F("0"));
        Serial.print(gps.time.hour());
        Serial.print(F(":"));
        if (gps.time.minute() < 10) Serial.print(F("0"));
        Serial.print(gps.time.minute());
        Serial.print(F(":"));
        if (gps.time.second() < 10) Serial.print(F("0"));
        Serial.print(gps.time.second());
        Serial.print(F("."));
        if (gps.time.centisecond() < 10) Serial.print(F("0"));
        Serial.print(gps.time.centisecond());
          Serial.flush();
      }
      else
      {
        Serial.print(F("INVALID"));
      }


    }
    void loop()
    {
      // This sketch displays information every time a new sentence is correctly encoded.
      while (ss.available() > 0)
      {
        if (gps.encode(ss.read()))
        {
    //    double temp = Getterm(analogRead(4));
          displayInfo();
        }
      }
      if (millis() > 5000 && gps.charsProcessed() < 10)
      {
        Serial.println(F("No GPS detected: check wiring."));
        while(true);
      }
    }


    ISR(TIMER2_OVF_vect) {
      TCNT2=59;//55;
      cntr++;
      if(cntr>2511111)
      {
        cntr = 0;
        Serial.println(F("Q_Reset"));
       // delay (1000);
       // resetFunc();
        reboot();

      }
    }
     
     
    arkadyf нравится это.