如何在使数据可读的同时将GPS数据传输到另一个屏蔽

时间:2013-08-06 14:06:19

标签: arduino i2c

我正在使用两个连接在I2C中的Arduino UNO。 我正在开发一个项目来记录SD卡上的GPS数据,然后当我的一块板连接到我的网络时,它会打印通过服务器收集的数据。目前我已将GPS数据写入GPS板上的SD卡。我遇到的问题是将数据发送到另一块板上的wifi屏蔽将其写入服务器。现在我想绕过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行是我需要改变的,我不知道我需要做什么。

1 个答案:

答案 0 :(得分:0)

您是否同时拥有两张SD卡?我的意思是,两个盾牌(GPS和WiFi)堆叠?

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