开源硬件集合!从新手入门到工业级项目落地,精选高口碑品牌+实战派产品,本周重点锁定进阶玩家挚爱——赛昉科技 VisionFive 2(昉・星光 2),首款集成3D GPU的量产RISC-V单板计算机,颠覆性升级+限时5折,现在叠加套餐福利,4GB到手299元,8GB到手349元,买摄像头声卡套餐还能再减43元,正品保障+现货速发,闭眼入不踩坑!

本测评由创作者“无垠的广袤”分享,文章介绍了昉·星光2单板计算机结合GPS模块和串口通信功能实现GPS定位的项目设计,原文链接:【昉·星光2 RISC-V 单板计算机】GPS定位。
硬件连接
| GPS module pin name | 40-pin GPIO header pin number | Details |
|---|---|---|
| VCC | 4 | 5V 电压 |
| GND | 6 | GND |
| TXD | 10 | GPIO6 (UART RX) |
| RXD | 8 | GPIO5 (UART TX) |
实物连接

参考:使用昉·星光 2的UART读取GPS数据 .
流程图

代码
import serial
#Set serial port parameters(adjust according to your GPS module)
SERIAL_PORT ="/dev/ttyS0" # It might be /dev/ttyUSB0 or others
BAUDRATE =9600 # Common baud rate for GPS modules is 9600
def read_all_gps_data():
try:
print(f"Starting to read GPS data (Serial port: {SERIAL_PORT}, Baudrate: {BAUDRATE})...")
with serial.Serial(SERIAL_PORT, BAUDRATE, timeout=1) as ser:
while True:
line = ser.readline().decode('ascii', errors='ignore').strip()
if line: # Print only if not an empty line
print(line)
except KeyboardInterrupt:
print("\nStopping GPS data reading")
except Exception as e:
print(f"An error occurred: {e}")
if __name__ =="__main__":
read_all_gps_data()
效果
打印GPS原始数据,包括多套卫星定位系统

解析GPS原始数据
安装NMEA解析库
apt install python3-nmea2
代码
调用pynmea2和serial库函数,实现串口数据读取与时间及坐标转换,并将结果打印至终端。
import serial
import time
from pynmea2 import parse
def parse_gps_data():
try:
ser = serial.Serial("/dev/ttyS0", baudrate=9600, timeout=1)
print("Reading GPS data...")
while True:
line = ser.readline().decode('ascii', errors='ignore').strip()
if not line:
continue
try:
data =parse(line)
#Force extraction of time(return"00:00:00"if it doesn't exist)
time_utc =getattr(data,'timestamp',"0").strftime("%H:%M:%S")ifhasattr(data,'timestamp')else"00:00:00"
#Force extraction of latitude and longitude(return0.0if they don't exist)
lat =getattr(data,'latitude',0.0)
lon =getattr(data,'longitude',0.0)
lat_dir ='N'if lat >=0else'S'
lon_dir ='E'if lon >=0else'W'
lat_deg = f"{abs(lat):.6f} deg {lat_dir}"
lon_deg = f"{abs(lon):.6f} deg {lon_dir}"
#Print a single set of data
print(f"Time (UTC): {time_utc}")
print(f"Latitude: {lat_deg}")
print(f"Longitude: {lon_deg}")
time.sleep(1)
except Exception as e:
continue # Silently ignore parsing errors
except KeyboardInterrupt:
print("\nStopping GPS data reading")
except Exception as e:
print(f"Serial port error: {e}")
finally:
if'ser' in locals():
ser.close()
print("Serial port closed")
if __name__ =="__main__":
parse_gps_data()
保存代码,终端执行指令python3 gps_time_coordinate.py 运行串口数据转换程序;
效果
终端打印时间和经纬度信息,更新的时间间隔为1秒。
本周主推:VisionFive 2
作为开源RISC-V开发板的代表,VisionFive 2凭超强扩展性和开源特性圈粉无数,堪称进阶开发、个性化项目的不二之选!

不止基础版直降,多款套餐精准戳中需求,尤其是摄像头套餐,性价比直接拉满,闭眼冲不亏!
VisionFive 2
4GB+双千兆网口
原价:519
优惠价:299¥
立即购买

VisionFive 2
8GB+双千兆网口
原价:679
优惠价:349¥
立即购买
