UART - 檢索 GPS 位置
材料準備
AmebaD [AMB21 / AMB22 / AMB23 / BW16] x 1
Adafruit Ultimate GPS Breakout x 1 (可参考 官方文件))
範例説明
市面上常看到的GPS模組大多都是UART介面,資料格式也大多遵循NMEA sentence。這邊介紹使用Adafruit Ultimate GPS Breakout。它的資料格式是文字介面,所以可以直接接在USB to TTL Adapter上直接看GPS內容:
的格式使用NMEA sentence,詳細內容可以參考http://aprs.gids.nl/nmea/ 但在室內不太容易收到GPS訊號,上一張圖尚未收到訊號,稱之為還沒“fix”。帶GPS模組到室外做測試,等到fix有訊號的內容長的像這樣:
In this example we are only interested in the “$GPRMC (Global Positioning Recommended Minimum Coordinates)”: $GPRMC,032122.000,A,2446.8181,N,12059.7251,E,0.39,78.89,270116,,,A*53 Each field is separated by a comma.
第1欄是GMT(Greenwich Mean Time), 這邊的例子是032122.000, 格式為HH:MM:SS.SSS, 也就是03:21:22.000。時區與日光節約需要自行調整
第2欄是status code
V: Void (Invalid)
A: Active, 這個狀態下GPS可以fix
3~6欄是地理位置定位(geolocation)
例子中,2446.8181,N 表示北半球緯度24度46.8181分,12059.7251,E 表示東半球經度120度59.7251分,
我們可以在google map的搜尋欄輸入+24 46.8181′, +120 59.7251′ 就可以檢查位置是否正確
AMB21 / AMB22 接線圖如下:
AMB23 接線圖
BW16 Wiring Diagram:
BW16-TypeC Wiring Diagram:
Open the example in “Files” → “Examples” →
“AmebaSoftwareSerial” → “Adafruit_GPS_parsing”
.
Compile and upload to Ameba, then press the reset button. The result will be output to Serial Monitor: