0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Elecrow GPS shield with antenna

0
Posted at

GPSの出力をSDカードに書き込むというのを手軽にやりたい。

Elecrowのシールドが良さそうだった購入してみた。今回はGenuino 101を使用しているが、Genuino 101ボードに搭載されたペリフェラルの機能は使用していない。

Genuino 101

Intel製のArduino互換ボード。CPUにCurie, IMUにBosch BMI160を搭載している。さらに通信はBLEが利用できる。

写真中央の横長の長方形のチップがCrue本体、IMUは…どれだろう(Curieの左下の正方形のチップかな?)、右下の黄色の部分がBLEのアンテナ。

2017-06-15 14.42.33.jpg

Elecrow

Elecrow GPS shield with antennaはublox NEO-6MとSDカードを搭載している。

写真中央の銀色のシールド部分がGPSで、μFLとSMAのアンテナコネクタが実装されている。それから、右下の光が反射している部分がSDカードスロット。microSDが使える。

2017-06-15 21.16.55.jpg

サンプルコード

Elecrowのデモコード (zip注意)を拝借して改造した。

# include<SoftwareSerial.h>
# include<SD.h>

const int chipSelect = 10;        // SDピンセレクタ
SoftwareSerial SoftSerial(6, 7);  // GPS用ソフトウェアシリアルピン

char buffer[256]; // GPSデータ受信バッファ
int count = 0;    // バッファ格納時のカウンタ


void setup() {
  SoftSerial.begin(9600);           // the SoftSerial baud rate
  Serial.begin(115200);             // the Serial port of Arduino baud rate.

  // SDカードのピンセレクタを出力に変更する
  pinMode(10, OUTPUT);
  if (!SD.begin(chipSelect)) {
    return;
  }
}

void loop() {
  if (SoftSerial.available())  {
    // ソフトウェアシリアルからデータが届いたら実行される
    while (SoftSerial.available()) {
      buffer[count++] = SoftSerial.read();   // バッファにシリアルから取得した値を格納する
      if (count == 256) break;
    }
    Serial.write(buffer, count);   // バッファが一杯になったらPC向けのシリアルに送信する

    // SDカードのファイルを開く
    File dataFile = SD.open("datalog.txt", FILE_WRITE);
    if (dataFile) {
      // 開けたら書き込み。他にchar[]をStringに変換する方法がわからなかった…。
      String str(buffer);
      dataFile.print(str);
      dataFile.close();
    }

    // GPSデータ受信バッファとカウンタをクリアする
    clearBufferArray();              
    count = 0;
  }

  if (Serial.available()) {           // if data is available on hardwareserial port ==> data is comming from PC or notebook
    SoftSerial.write(Serial.read());       // write it to the SoftSerial shield
  }
}

void clearBufferArray() {
  // 受信バッファを0フィルする
  for (int i = 0; i < count; i++) {
    buffer[i] = 0;
  }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?