HS-S78P GPS 위치 모듈

HS-S78P GPS 위치 모듈

1、소개

ATGM336H-5N 시리즈는 작은 크기의 고성능 BDS/GNSS 전성도 위치 навигация 모듈입니다. 중국 과학기술 대학교 제4세대 저전력 GNSS SOC 단일 칩 AT6558을 기반으로 하며, 다양한 위성 nawigasyon 시스템 및 위성 강화 시스템을 지원합니다. 32개의 추적 채널을 가지고 있으며, 동시에 여섯 시스템 GNSS 신호를 수신하고 통합 위치 nawigasyon 시간授시를 할 수 있습니다. 높은 감도, 저전력, 저비용 장점을 가지고 있으며, 차량 nawigasyon,手持定位, 착용 장치에 적합하며, Ublox MAX 시리즈 모듈을 바로 대체할 수 있습니다.

2、시뮬레이션 그래프

GPS定位模块-HS-S78P 원리도点击查看

3、모듈 매개변수

핀 이름

설명

G

GND(전원 입력 부정极)

V

VCC(전원 입력 정극)

R

시리얼 통신 전송 RX 핀

T

시리얼 통신 전송 TX 핀

  • 전원 공급 전압: 3.3V-5V

  • 연결 방식: PH2.0 4P 핀 라인

  • 安装方式:螺丝固定

4、회로판 크기

5、아두이노 IDE 예제 프로그램

주의: 프로그램을 업로드할 때 라이브러리 파일 오류가 표시되면 먼저 라이브러리 파일을 가져오세요!
Arduino IDE 라이브러리 다운로드 및 导入 가이드:
点击查看

예제 프로그램(UNO 개발 보드):

#include <TinyGPS++.h>
#include <SoftwareSerial.h>

TinyGPSPlus gps;
SoftwareSerial gps_ss(A5, A4);

void setup(){
  gps_ss.begin(9600);
  Serial.begin(9600);
}

void loop(){
  while (gps_ss.available()) {
    if (gps.encode(gps_ss.read())) {
      if (gps.location.isValid()) {
        Serial.println(gps.location.lat());
        Serial.println(gps.location.lng());

      }

    }
  }

}

6、ESP32 Python 예제(Mixly IDE /미스키에 적용됨)

개발 보드를 선택하세요 Python ESP32 【ESP32 Generic(4MB)】를 코드 모드로 전환하여 업로드하십시오

주의: 프로그램을 업로드할 때 라이브러리 파일 오류가 표시되면 먼저 라이브러리 파일을 가져오세요!
미시지(Mixly)IDE ESP32 라이브러리 다운로드 및 가져오기 가이드:
点击查看

예제 프로그램(ESP32-Python):

from machine import UART, Pin
import time
import machine


# 示例程序

class GPSNMEA:
    def __init__(self):
        self._buf = bytearray()
        self._lat = None
        self._lon = None
        self._fix_ok = False
        self._sats = 0
        self._fix_quality = 0
        self._hdop = None
        self._rmc_valid = False
        self._utc_time = None
        self._date = None
    def has_fix(self):
        return bool(self._fix_ok)
    def latitude(self):
        return self._lat
    def longitude(self):
        return self._lon
    def satellites(self):
        return self._sats
    def hdop(self):
        return self._hdop
    def beijing_time(self):
        dt = self.beijing_datetime_tuple()
        if dt:
            y, mo, d, hh, mm, ss = dt
            return f"{y:04d}-{mo:02d}-{d:02d} {hh:02d}:{mm:02d}:{ss:02d}"
        return None
    def beijing_datetime_tuple(self):
        if not self._utc_time or not self._date:
            return None
        day, month, year_2 = self._date
        year_full = 2000 + year_2 if year_2 < 80 else 1900 + year_2
        h, m, s = self._utc_time
        try:
            epoch = time.mktime((year_full, month, day, h, m, s, 0, 0))
            epoch += 8 * 3600
            y, mo, d, hh, mm, ss, _, _ = time.localtime(epoch)
            return (y, mo, d, hh, mm, ss)
        except:
            return None
    def feed(self, data):
        if data is None:
            return
        if isinstance(data, int):
            data = bytes([data])
        elif isinstance(data, memoryview):
            data = bytes(data)
        elif isinstance(data, str):
            data = data.encode('ascii', 'ignore')
        self._buf.extend(data)
        while True:
            idx = self._buf.find(b'\n')
            if idx < 0:
                break
            line = self._buf[:idx + 1]
            self._buf = self._buf[idx + 1:]
            try:
                s = bytes(line).decode('ascii', 'ignore').strip()
            except:
                continue
            if s:
                self._handle_sentence(s)
    def _handle_sentence(self, s):
        if not s.startswith('$') or len(s) < 7:
            return
        if not self._checksum_ok(s):
            return
        fields = s.split('*', 1)[0].split(',')
        tag = fields[0][1:]
        if tag.endswith('RMC'):
            self._parse_rmc(fields)
        elif tag.endswith('GGA'):
            self._parse_gga(fields)
        self._fix_ok = self._rmc_valid or (self._fix_quality > 0)
    @staticmethod
    def _checksum_ok(sentence):
        if not sentence.startswith('$') or '*' not in sentence:
            return False
        try:
            data, cshex = sentence[1:].split('*', 1)
        except ValueError:
            return False
        calc = 0
        for ch in data:
            calc ^= ord(ch)
        try:
            given = int(cshex.strip()[:2], 16)
        except ValueError:
            return False
        return calc == given
    @staticmethod
    def _dm_to_deg(dm, neg):
        if not dm or '.' not in dm:
            return None
        i = dm.find('.')
        head, tail = dm[:i], dm[i:]
        if len(head) < 3:
            return None
        try:
            minutes = float(head[-2:] + tail)
            degrees = float(head[:-2]) if head[:-2] else 0.0
        except ValueError:
            return None
        dec = degrees + minutes / 60.0
        return -dec if neg else dec
    def _parse_rmc(self, f):
        if len(f) < 7:
            self._rmc_valid = False
            return
        if len(f) > 1 and f[1]:
            try:
                hh = int(f[1][0:2]); mm = int(f[1][2:4]); ss = int(f[1][4:6])
                self._utc_time = (hh, mm, ss)
            except:
                pass
        if len(f) > 9 and f[9]:
            try:
                dd = int(f[9][0:2]); mo = int(f[9][2:4]); yy = int(f[9][4:6])
                self._date = (dd, mo, yy)
            except:
                pass
        status = f[2] if len(f) > 2 else 'V'
        self._rmc_valid = (status == 'A')
        if not self._rmc_valid:
            return
        lat = self._dm_to_deg(f[3] if len(f) > 3 else ', (f[4] if len(f) > 4 else ') == 'S')
        lon = self._dm_to_deg(f[5] if len(f) > 5 else ', (f[6] if len(f) > 6 else ') == 'W')
        if (lat is not None) and (lon is not None):
            self._lat, self._lon = lat, lon
    def _parse_gga(self, f):
        if len(f) < 10:
            return
        try:
            self._fix_quality = int(f[6]) if f[6] else 0
        except ValueError:
            self._fix_quality = 0
        try:
            self._sats = int(f[7]) if f[7] else 0
        except ValueError:
            self._sats = 0
        try:
            self._hdop = float(f[8]) if f[8] else None
        except ValueError:
            self._hdop = None
        if self._fix_quality > 0:
            lat = self._dm_to_deg(f[2], f[3] == 'S') if len(f) > 4 else None
            lon = self._dm_to_deg(f[4], f[5] == 'W') if len(f) > 6 else None
            if (lat is not None) and (lon is not None):
                self._lat, self._lon = lat, lon

uart = UART(1, baudrate=9600, tx=Pin(17), rx=Pin(16), timeout=1000)
gps = GPSNMEA()

def get_latitude():
    return gps.latitude()
def get_longitude():
    return gps.longitude()
def get_beijing_time():
    return gps.beijing_time()
def get_beijing_datetime_tuple():
    return gps.beijing_datetime_tuple()
def has_fix():
    return gps.has_fix()

buf = bytearray(256)
# 这个变量必须有,获取时间块使用的这个变量
dt = (0,0,0,0,0,0)
while True:

    # -----------------------串口数据切片处理------------------------------------

    n = uart.any()  # 检查 UART 缓冲区中是否有可读取的字节数量
    if n:
        # 防止读取的数据超过缓冲区长度
        n = min(n, len(buf))
        # 从 UART 中读取 n 个字节到 buf 数组中
        read_bytes = uart.readinto(buf, n)
        if read_bytes:
            # 将实际读取的字节切片,并转换成 bytes 类型,传给 GPS 解析器
            gps.feed(bytes(buf[:read_bytes]))

    #-------------------------------------------------------------------------
    if has_fix():
        WeiDu = get_latitude()
        JingDu = get_longitude()
        dt = get_beijing_datetime_tuple()
        print(('纬度:' + str(WeiDu)))
        print(('经度:' + str(JingDu)))
        time.sleep(1)
        # 需先让GPS获取时间
        if dt:
            print('时间:',end ="")
            print((str(dt[3]) + ' : '),end ="")
            print((str(dt[4]) + ' : '),end ="")
            print(str(dt[5]))
    else:
        print('解析失败')

7、미스키 Mixly 예제 프로그램(그래픽 언어)

예제 프로그램(UNO 개발 보드):다운로드 클릭
주의: 프로그램을 업로드할 때 라이브러리 파일 오류가 표시되면 먼저 라이브러리 파일을 가져오세요!
미스키(Mixly)IDE Arduino 라이브러리 다운로드 및 가져오기 가이드:点击查看

예제 프로그램(ESP32 개발 보드):다운로드 클릭
주의: 프로그램을 업로드할 때 라이브러리 파일 오류가 표시되면 먼저 라이브러리 파일을 가져오세요!
미시지(Mixly)IDE ESP32 라이브러리 다운로드 및 가져오기 가이드:
点击查看

8、테스트 환경 구축

Arduino UNO 테스트 환경 구축

부품 준비:“

  • UNO-R3 개발 보드 *1

  • UNO-R3 EXP 확장판 *1

  • USB type-c 데이터 케이블 *1

  • HS-S78P GPS 모듈*1

  • PH2.0 4P둘쪽 머리 끝 케이블 *1

전기 연결도):

ESP32 테스트 환경 설정

부품 준비:“업데이트 대기 중...

전기 연결도): 업데이트 대기 중...

9、비디오 강의

Arduino UNO 비디오 강의:点击查看

ESP32 Python 비디오 강의:点击查看


10、테스트 결과

Arduino UNO 테스트 결과:

코드를 내려받으면 컴퓨터 시리얼 포트에서 자신의 경도와 위도를 볼 수 있습니다.(주의: 실내에서는 안테나 신호 이유로 경도와 위도를 출력하지 못할 수 있습니다. 가장 좋은 것은 공원 지역에서 테스트하는 것이 좋습니다.)

ESP32 테스트 결과:

업데이트 대기 중...