Get GPS information using Raspberry Pi I use Raspberry Pi 4B, but I think that 3 is the same.
--GLOBALSAT BU-353S4 => USB-connected GPS sensor
Install the required packages
sudo apt-get upgrade
sudo apt-get install gpsd gpsd-clients python-gps cu
Plug BU-353S4 into USB and check the connection with the following command
lsusb
# Prolific Technology, Inc.PL2303 Serial Port is ok
ls /dev/ttyUSB*
# => /dev/ttyUSB0
#Check the port used (will be used later)
After confirming the USB connection, create a gpsd configuration file with the following command (add it below if it already exists)
vi /etc/default/gpsd
# vim /etc/default/gpsd
/etc/default/gpsd
#Add the following two lines (device number to DEVICES)
DEVICES="/dev/ttyUSB0"
GPSD_OPTIONS="-n"
#Set automatic start and restart
sudo systemctl enable gpsd.socket
sudo systemctl start gpsd.socket
sudo reboot
Python sample code
install 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
#The output is as follows.
# time : 2020-03-19T13:24:08.000Z
# lat : 35.633116667
# lon : 139.703893333
# alt : 17.1
It was surprisingly easy, but I had a hard time finding a decent commentary and sample code.
https://qiita.com/t2hk/items/572c72fbe99362d92e32
Recommended Posts