乐鑫技术交流
直播中

王秀珍

7年用户 1358经验值
私信 关注
[问答]

如何用8266/esp12e制作GPS记录仪项圈?

代码:全选/*
  GPS Position Logger
  gps-position-logger.ino
  Read GPS data from BN-220 or any serial GPS sensor
  Requires TinyGPS++ Library
  Save to SD or microSD card

  DroneBot Workshop 2021
  
*/

// Include required libraries
#include
#include
#include
#include

// GPS Connections
static const int RXPin = 4, TXPin = 3;

// GPS Baud rate (change if required)
static const uint32_t GPSBaud = 9600;

// SD Card Select pin
const int chipSelect = 8;

// Write LED
//const int recLED = 7;

// String to hold GPS data
String gpstext;

// GPS write delay counter variables
// Change gpsttlcount as required
int gpscount = 0;
int gpsttlcount = 30;

// TinyGPS++ object
TinyGPSPlus gps;

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

void setup()
{
  // Set LED pin as output
  //pinMode(recLED, OUTPUT);

  // Start Serial Monitor for debugging
  Serial.begin(115200);

  // Start SoftwareSerial
  ss.begin(GPSBaud);

  // Initialize SD card
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    //don't do anything more:
    while (1);
  }
  Serial.println("card initialized.");

  // Blink LED so we know we are ready
//  digitalWrite(recLED, HIGH);
// delay(500);
//  digitalWrite(recLED, LOW);
//  delay(500);
//  digitalWrite(recLED, HIGH);
//  delay(500);
//  digitalWrite(recLED, LOW);
//  delay(500);
//  digitalWrite(recLED, HIGH);
//  delay(500);
//  digitalWrite(recLED, LOW);

}

void loop()
{

  // Turn off LED
//  digitalWrite(recLED, LOW);


  // See if data available
  while (ss.available() > 0)
    if (gps.encode(ss.read()))

      // See if we have a complete GPS data string
      if (displayInfo() != "0")
      {

        // Get GPS string
        gpstext = displayInfo();


        // Check GPS Count
        Serial.println(gpscount);
        if (gpscount == gpsttlcount) {

          // LED On to indicate data to write to SD card
//          digitalWrite(recLED, HIGH);

          //Open the file on card for writing
          File dataFile = SD.open("gpslog.csv", FILE_WRITE);

          if (dataFile) {

            // If the file is available, write to it and close the file
            dataFile.println(gpstext);
            dataFile.close();

            // Serial print GPS string for debugging
            Serial.println(gpstext);
          }
          // If the file isn't open print an error message for debugging
          else {
            Serial.println("error opening datalog.txt");
          }

        }
        // Increment GPS Count
        gpscount = gpscount + 1;
        if (gpscount > gpsttlcount) {
          gpscount = 0;
        }

      }


}

// Function to return GPS string
String displayInfo()
{
  // Define empty string to hold output
  String gpsdata = "";

  // Get latitude and longitude
  if (gps.location.isValid())
  {
    gpsdata = String(gps.location.lat(), 6);
    gpsdata += (",");
    gpsdata += String(gps.location.lng(), 6);
    gpsdata += (",");
  }
  else
  {
    return "0";
  }

  // Get Date
  if (gps.date.isValid())
  {
    gpsdata += String(gps.date.year());
    gpsdata += ("-");
    if (gps.date.month() < 10) gpsdata += ("0");
    gpsdata += String(gps.date.month());
    gpsdata += ("-");
    if (gps.date.day() < 10) gpsdata += ("0");
    gpsdata += String(gps.date.day());
  }
  else
  {
    return "0";
  }

  // Space between date and time
  gpsdata += (" ");

  // Get time
  if (gps.time.isValid())
  {
    if (gps.time.hour() < 10) gpsdata += ("0");
    gpsdata += String(gps.time.hour());
    gpsdata += (":");
    if (gps.time.minute() < 10) gpsdata += ("0");
    gpsdata += String(gps.time.minute());
    gpsdata += (":");
    if (gps.time.second() < 10) gpsdata += ("0");
    gpsdata += String(gps.time.second());
  }
  else
  {
    return "0";
  }

  // Return completed string
  return gpsdata;
}



               


                        你用的是哪个GPS模块?

               


                        什么不起作用?

               


                        所以我上传了上面显示的代码,在我将我的 gps 和 sd 卡读卡器连接到它之后,我从串行监视器中得到了这个……gps 是一个 gt-u7,一个非常常见的中国仿制品。当我通过 USB 插入 gps 并打开串行监视器时,我得到了很好的 gps 语句。
20:54:19.498 ->
3,第一个原因:4,引导模式:(3,0)
20:54:19.498 ->
20:54:19.498 -> wdt 重置
20:54:19.498 -> 加载 0x4010f000,len 3460 , room 16
20:54:19.498 -> tail 4
20:54:19.498 -> chksum 0xcc
20:54:19.498 -> load 0x3fff20b8, len 40, room 4
20:54:19.498 -> tail 4
20:54:19.531 -> 校验和 0xc9
20:54:19.531 -> csum 0xc9
20:54:19.531 -> v0004c7a0
20:54:19.531 ->

回帖(1)

李鸿洋

2024-1-4 11:23:29
本问题涉及硬件和代码的制作与实现,如果您没有相关的硬件和编程技能,建议找到专业人员协助完成。以下提供一个可供参考的步骤:

硬件材料:

- ESP8266或ESP12E模块
- BN-220或其他串口GPS模块
- SD卡或microSD卡
- 电池或电源供应模块
- 电线和连接器
- 面包板或PCB板
- 其他工具和附件(如焊接工具)

步骤:

1. 准备好所有硬件材料,并根据需要设计和制作电路板。

2. 下载和安装Arduino IDE软件,安装ESP8266开发板库和TinyGPS++库。

3. 打开Arduino IDE,输入以下代码,并根据具体需要修改参数:

#include
#include
#include

#define rxPin 4
#define txPin 3

TinyGPSPlus gps;
SoftwareSerial ss(rxPin, txPin);
File file;

void setup() {
  Serial.begin(115200);
  ss.begin(9600);
  SD.begin(4);
  file = SD.open("gps.txt", FILE_WRITE);
  file.println("Latitude, Longitude, Time, Date");
  file.close();
}

void loop() {
  while (ss.available() > 0) {
    gps.encode(ss.read());
    if (gps.location.isUpdated() && gps.date.isUpdated() && gps.time.isUpdated()) {
      String dataString = String(gps.location.lat(), 6) + ", " + String(gps.location.lng(), 6) + ", " + String(gps.time.hour()) + ":" + String(gps.time.minute()) + ":" + String(gps.time.second()) + ", " + String(gps.date.day()) + "/" + String(gps.date.month()) + "/" + String(gps.date.year());         
      file = SD.open("gps.txt", FILE_WRITE);
      file.println(dataString);
      file.close();
      Serial.println(dataString);
    }
  }
}

4. 将电路板与计算机连接,上传代码。

5. 在程序中设置的文件夹中插入SD卡或microSD卡,启用GPS模块并连接电源。

6. 等待GPS信号捕获并记录数据到SD卡。

7. 在处理数据时,可以利用Excel等软件打开输出文件,将数据进行进一步处理。

8. 根据需要对程序进行调整和优化,改善记录精度和信号强度等方面。

9. 最后进行批量生产和测试,保证质量和稳定性。

以上是一个大致的流程和思路,具体操作还需要根据实际情况和需求进行调整和实现。
举报

更多回帖

发帖
×
20
完善资料,
赚取积分