1

我正在使用两个以 I2C 连接的 Arduino UNO。我正在做一个在 SD 卡上记录 GPS 数据的项目,然后当我的一个板连接到我的网络时,它会打印通过服务器收集的数据。目前,我将 GPS 数据写入 GPS 板上的 SD 卡。我遇到的问题是将该数据发送到另一块板上的 wifi shield 以将其写入服务器时。现在我想绕过 GPS 屏蔽上的 SD 卡,将数据直接写入 wifi 屏蔽上的 SD 卡。我拥有的代码是来自 Ada-fruit 的示例代码,不是一个优秀的程序员,我不知道如何获取我拥有的代码并做到这一点。

这是GPS盾牌上的代码

#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
#include <SD.h>
#include <avr/sleep.h>
#include <GPSconfig.h>
#include <Wire.h>

SoftwareSerial mySerial(8, 6);
Adafruit_GPS GPS(&mySerial);

// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
// Set to 'true' if you want to debug and listen to the raw GPS sentences
#define GPSECHO  true
/* set to true to only log to SD when GPS has a fix, for debugging, keep it false */
#define LOG_FIXONLY false  

// Set the pins used
#define ledPin 13

// read a Hex value and return the decimal equivalent
uint8_t parseHex(char c) {
  if (c < '0')
    return 0;
  if (c <= '9')
    return c - '0';
  if (c < 'A')
    return 0;
  if (c <= 'F')
    return (c - 'A')+10;
  }


void setup() {
  Serial.begin(9600);
  Serial.println("\r\nUltimate GPSlogger Shield");
  pinMode(ledPin, OUTPUT);


  // make sure that the default chip select pin is set to
  // output, even if you don't use it

  // connect to the GPS at the desired rate
  GPS.begin(9600);

  // uncomment this line to turn on RMC (recommended minimum) and GGA (fix data)           including altitude
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  // uncomment this line to turn on only the "minimum recommended" data
  //GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
  // For logging data, we don't suggest using anything but either RMC only or RMC+GGA
  // to keep the log files at a reasonable size
  // Set the update rate
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);   // 1 or 5 Hz update rate

  // Turn off updates on antenna status, if the firmware permits it
  GPS.sendCommand(PGCMD_NOANTENNA);

  Serial.println("Ready!");
}

void loop() {
  char c = GPS.read();
  if (GPSECHO)
     if (c)   Serial.print(c);

  // if a sentence is received, we can check the checksum, parse it...
  if (GPS.newNMEAreceived()) {
    // a tricky thing here is if we print the NMEA sentence, or data
    // we end up not listening and catching other sentences! 
    // so be very wary if using OUTPUT_ALLDATA and trying to print out data
    //Serial.println(GPS.lastNMEA());   // this also sets the newNMEAreceived() flag to   false

    if (!GPS.parse(GPS.lastNMEA()))   // this also sets the newNMEAreceived() flag to false
      return;  // we can fail to parse a sentence in which case we should just wait for another

    // Sentence parsed! 
    Serial.println("OK");
    if (LOG_FIXONLY && !GPS.fix) {
        Serial.print("No Fix");
        return;
    }

    // Rad. lets log it!
    Serial.println("Log");

    char *stringptr = GPS.lastNMEA();
    uint8_t stringsize = strlen(stringptr);
    if (stringsize != Wire.write((uint8_t *)stringptr, stringsize))    //write the     string     to the SD file
    if (strstr(stringptr, "RMC"))  
     Serial.println();
   }
 }

最后 5 行是数据写入卡的位置。上述设置代码的顶部是用于使 GPS 数据可读的代码。最后 5 行是我需要更改的,我不确定我需要做什么。

4

1 回答 1

0

你有两个SD卡并行吗?我的意思是,两个防护罩(GPS 和 WiFi)堆叠在一起?

在您的情况下,字符串通过 I2C 发送到 GPS Shield... WiFi Shield 和 Arduino 之间的接线如何?你能给我们看看原理图吗?

于 2013-08-06T22:05:32.613 回答