Modifications

Sauter à la navigation Sauter à la recherche
1 743 octets ajoutés ,  3 novembre 2025 à 21:48
Ligne 84 : Ligne 84 :     
=== Minimal test ===
 
=== Minimal test ===
 +
The [https://github.com/mchobby/cansat-belgium-micropython/blob/main/test-gps/minimaltest.py minimal test] script:
 +
* Opens and configure the UART (serial port) of the Pico
 +
* Create a GPS object (attached to the UART).
 +
* Wait the GPS to get a Network Fix (NMEA protocol returns the Fix status)
 +
* Display useful information from the GPS
 +
<syntaxhighlight lang="python">
 +
from machine import UART, Pin
 +
import utime as time
   −
:::: indiquer qu'il faut attendre le fix :::
+
from adafruit_gps import GPS
 +
 
 +
# Pyboard (TX=X9, RX=X10)
 +
uart = UART( 0, rx=Pin(1), tx=Pin(0), baudrate=9600, timeout=3000)
 +
 
 +
# Create a GPS instance
 +
gps = GPS(uart)
 +
 
 +
# Turn on the basic GGA and RMC info
 +
gps.send_command( 'PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')
 +
 
 +
# Set update rate to once a second (1hz)
 +
gps.send_command( 'PMTK220,1000')
 +
 
 +
# Main loop runs
 +
last_print = time.ticks_ms()
 +
while True:
 +
    gps.update() # update object with data sent by GPS over uart
 +
 
 +
    current = time.ticks_ms()
 +
    if time.ticks_diff(current, last_print) >= 1000: # Print once a second only
 +
        last_print = current
 +
 
 +
        if not gps.has_fix:
 +
            print('Waiting for fix...')
 +
            continue # restart the While loop
 +
 
 +
        print('=' * 40)
 +
        print('Fix timestamp: {}/{}/{} {:02}:{:02}:{:02}'.format(
 +
            gps.timestamp_utc[1],
 +
            gps.timestamp_utc[2],
 +
            gps.timestamp_utc[0],
 +
            gps.timestamp_utc[3],
 +
            gps.timestamp_utc[4],
 +
            gps.timestamp_utc[5]))
 +
        print('Latitude: {} degrees'.format(gps.latitude))
 +
        print('Longitude: {} degrees'.format(gps.longitude))
 +
        if gps.satellites is not None:
 +
            print('# satellites: {}'.format(gps.satellites))
 +
        if gps.track_angle_deg is not None:
 +
            print('Speed: {} km/h'.format(gps.speed_knots*1.8513))
 +
</syntaxhighlight>
    
{{traduction}}
 
{{traduction}}
32 908

modifications

Menu de navigation