7
12

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.

EdisonでGPSを使う

Posted at

Edison UARTに接続したGPSをpythonを使って読み出すテスト。

前提

インストールするモジュール

ハードウェア

試してみる

UARTとの接続はmraaで行い、取得した値はpynmea2で処理する。

import mraa
import serial
import pynmea2

# UARTポートの指定
uart = mraa.Uart(0)

# Serialオブジェクトの生成。ボーレートは9600bps
ser = serial.Serial(uart.getDevicePath(), 9600)

while 1:
	# 行単位でパースする
    msg = pynmea2.parse(ser.readline())
    
    # センテンスがGGAのものを処理
    if msg.sentence_type == 'GGA':  # Global Positioning System Fix Data
        print {
            'gps.number_of_satellites': msg.num_sats,
            'gps.latitude': msg.latitude,
            'gps.longitude': msg.longitude,
            'gps.altitude': msg.altitude,
        }

こんなのが取れる。

{
    'gps.altitude': -12.8,
    'gps.longitude': 139.77447469,
    'gps.number_of_satellites': '11',
    'gps.latitude': 35.700290937
}

感想

回路が繋がってさえいれば、python + mraa + pynmea2ですごく簡単に処理できる。
NMEAに定義されているsentenceはいくつかあるので、正しく使うにはNMEAの理解が必要そう。

参考

7
12
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
7
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?