LoginSignup
6
4

More than 3 years have passed since last update.

ラズパイ4B+BU-353S4でGPSトラッキング(Python)

Posted at

ラズパイ4 + BU-353S4 + PythonでGPSトラッキング

ラズパイを用いて、GPS情報を取得する
Raspberry Pi 4Bを使いますが、別に3とかでも同じだと思います。

用意するもの

  • GLOBALSAT BU-353S4 => USB接続のGPSセンサー
  • Raspberry Pi 4

手順

必要なパッケージをインストール

sudo apt-get upgrade
sudo apt-get install gpsd gpsd-clients python-gps cu

USBにBU-353S4を差込み、以下のコマンドで接続を確認

lsusb
# Prolific Technology, Inc. PL2303 Serial Portがあればok
ls /dev/ttyUSB*
# => /dev/ttyUSB0
# 使用されているポートを確認(あとで使います)

USBの接続が確認できたら、以下のコマンドでgpsd設定ファイルを作成(既存の場合は下に追加)

vi /etc/default/gpsd
# vim /etc/default/gpsd
/etc/default/gpsd
# 以下の2行を追加(DEVICESには先ほどのデバイス番号)
DEVICES="/dev/ttyUSB0"
GPSD_OPTIONS="-n"
# 自動起動を設定して再起動
sudo systemctl enable gpsd.socket
sudo systemctl start gpsd.socket
sudo reboot

Pythonサンプルコード

gps3をインストール

pip3 install gps3
gps.py
from gps3 import gps3

gps_socket = gps3.GPSDSocket()
data_stream = gps3.DataStream()
gps_socket.connect()
gps_socket.watch()

for new_data in gps_socket:
  if new_data:
    data_stream.unpack(new_data)
    print('time : ', data_stream.TPV['time'])
    print('lat : ', data_stream.TPV['lat'])
    print('lon : ', data_stream.TPV['lon'])
python3 gps.py
# 以下のように出力されます。
# time :  2020-03-19T13:24:08.000Z
# lat :  35.633116667
# lon :  139.703893333
# alt :  17.1

まとめ

意外と簡単だったけど、まともな解説記事やサンプルコードを探すのに苦労した。

参考記事

6
4
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
6
4