前提・実現したいこと
RaspberryPi3 ModelBでGPSモジュールを使って緯度経度情報を取得したいです。
実行すると以下のエラーが出てしまいます。
発生している問題・エラーメッセージ
pi@raspberrypi:~/Desktop $ sudo python3 01.py
Traceback (most recent call last):
File "01.py", line 6, in <module>
gps = micropyGPS.MicropyGPS(9, 'dd') # MicroGPSオブジェクトを生成する。
AttributeError: module 'micropyGPS' has no attribute 'MicropyGPS'
該当のソースコード
Python
1 2import serial 3import micropyGPS 4import threading 5import time 6 7gps = micropyGPS.MicropyGPS(9, 'dd') # MicroGPSオブジェクトを生成する。 8 # 引数はタイムゾーンの時差と出力フォーマット 9 10def rungps(): # GPSモジュールを読み、GPSオブジェクトを更新する 11 s = serial.Serial('/dev/serial0', 9600, timeout=10) 12 s.readline() # 最初の1行は中途半端なデーターが読めることがあるので、捨てる 13 while True: 14 sentence = s.readline().decode('utf-8') # GPSデーターを読み、文字列に変換する 15 if sentence[0] != '$': # 先頭が'$'でなければ捨てる 16 continue 17 for x in sentence: # 読んだ文字列を解析してGPSオブジェクトにデーターを追加、更新する 18 gps.update(x) 19 20gpsthread = threading.Thread(target=rungps, args=()) # 上の関数を実行するスレッドを生成 21gpsthread.daemon = True 22gpsthread.start() # スレッドを起動 23 24while True: 25 if gps.clean_sentences > 20: # ちゃんとしたデーターがある程度たまったら出力する 26 h = gps.timestamp[0] if gps.timestamp[0] < 24 else gps.timestamp[0] - 24 27 print('%2d:%02d:%04.1f' % (h, gps.timestamp[1], gps.timestamp[2])) 28 print('緯度経度: %2.8f, %2.8f' % (gps.latitude[0], gps.longitude[0])) 29 print('海抜: %f' % gps.altitude) 30 print(gps.satellites_used) 31 print('衛星番号: (仰角, 方位角, SN比)') 32 for k, v in gps.satellite_data.items(): 33 print('%d: %s' % (k, v)) 34 print('') 35 time.sleep(3.0) 36 37
試したこと
"AttributeError"と検索して調べたところ
・ファイル名の変更
というキーワードが引っかかったのでこれをもとに
・Desktop上にある"micropyGPS"というフォルダ名の変更
・上記フォルダ内にある"micropyGPS.py"というファイル名の変更
・"01.py"にある"micropyGPS.MicropyGPS"の"."より後半部の名前の変更
以上を行いましたが相変わらずエラー表示でした。
補足情報(FW/ツールのバージョンなど)
回答1件
あなたの回答
tips
プレビュー