材料:树莓派3b(Ubuntu MATE系统),GPS+BD模块,USB转TTL模块,GPS有源天线
步骤:
1. 用杜邦线连接上图三个器件,GPS模块与USB转接头相连时PPS一端不连,两模块TXD和RXD交叉相连,即GPS模块的TXD连接USB转接模块的RXD,连好后将天线放到窗外
2. lsusb 查看是否识别该模块
使用GPS读取软件cgps
安装指令:sudo apt-get install gpsd gpsd-clients Python-gps
如果提示Unable to locate package …,输入sudo apt-get update&& sudo apt-getinstall gpsd gpsd-clients Python-gps
如果还不行,就不要在远程登录的时候这么做,直接在树莓派上操作
如果还是不行,就sudo apt-get update && sudo apt-get upgrade&& sudo apt-get install gpsd gpsd-clients Python-gps
再不行我就没办法了
3. 使用命令:cgps -s
左边就是卫星回来的数据,右边是啥我也不知道
4. 如果第三步能正常实现,我们就可以使用python读取信息为我们所用啦
在选定路径下,执行命令nano getGPSInfoByUSB.py,拷贝如下程序:
- from gps import *
- import time
- session =gps(mode=WATCH_ENABLE)
- try:
- while True:
- report = session.next()
- if report['class'] == 'VERSION':
- print 'connect GPS successfully'
- if report['class'] == 'DEVICES':
- print'searching satellite ....'
- if report['class'] == 'WATCH':
- print'search satellite successfully'
- if report['class'] == 'TPV':
- print 'Latitude: ' , report.lat
- print 'Longitude: ' , report.lon
- if report['class'] == 'SKY':
- print 'satellites NO.',len(report.satellites)
- time.sleep(3)
- exceptStopIteration:
- print "GPSD has terminated"
保存后执行:python getGPSInfoByUSB.py,就可看到位置信息了