GPS – Global Positioning System

The GPS module features the u-blox receiver platform, which provides multi-band GPS/GNSS to high-volume industrial applications in a compact form factor.

Methods

class Gps(gps_id, uart_baudrate, uart_rxbuf=4096)

The Gps class is used to create an object that can access the UART1 port of the GPS/GNSS receivers mounted on the SBC.

The class needs to be initialized with the following parameters:

Parameter name

Value

Description

gps_id

1, 2, 3

GPS/GNSS receiver id.

Notice that your SBC may not have

all 3 GPS/GNSS receivers mounted.

uart_baudrate

9600, 19200, 38400, 57600,

115200, 230400, 460800,

921600

GPS/GNSS receiver UART1 baudrate

uart_rxbuf

any, default value is 4096

RX buffer size.

We recommend to leave the default value

unless you know how to deal with

UART RX buffers

read(size=None)

Read data from Gps

Args:

size: number of bytes to receive. Use read() to read all available data.

Return:

Received data

Example to read GPS/GNSS data:
>>> import sbc
>>> gps = sbc.Gps( 1, 115200 )
>>> print(gps.read())
$GPGGA,092750.000,5321.6802,N,00630.3372,W,1,8,1.03,61.7,M,55.2,M,,*76

Note

The ouput messages from the GPS/GNSS receiver UART1 are being stored in the Gps uart_rxbuf buffer.
The default buffer size (4096 bytes) should be enough to read continuously, but be aware that if you don’t read the buffer during a long time, the buffer will be completed and the new messages from the GPS/GNSS receiver will be lost, and by the time you read the buffer you will read “old” messages.
If your application won’t be reading messages continuously you can configure your GPS/GNSS receiver UART1 to don’t output any messages and request the ones your are interested in, see for more details about the request method.
As an alternative, you can empty the buffer with uart_init() method.

write(data)

Write data to the Gps

Args:

data: data to send

Return:

Number of bytes written

Example to write data to the GPS/GNSS receiver:
>>> import sbc
>>> gps1 = sbc.Gps( 1, 115200 )
>>> buf_tx = bytes( [ 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x03 ] )
>>> bytes_sent = gps1.write( buf_tx )
>>> print('Bytes sent: ', bytes_sent)
Bytes sent: 13
uart_init()

Initializes GPS/GNSS receiver UART port and empties UART RX buffer.

Example:
>>> import sbc
>>> import time
>>> gps1 = sbc.Gps( 1, 115200 )
>>> time.sleep(10)
>>> gps1.uart_init()
>>> time.sleep(1)
>>> print( gps1.get_uart_id().read() )
$GPGGA,092750.000,5321.6802,N,00630.3372,W,1,8,1.03,61.7,M,55.2,M,,*76
forward_to(uart_fwd=None)

Fordwards GPS/GNSS data to a peripheral with UART

Args:

uart_fwd: peripheral object (Gps, XBee, RS232)

Note

Note that GPS1 UART2 is already interconnected by hardware with RS232#2, GPS2 UART2 and GPS3 UART2. For these you don’t need to enable software forwarding.

Example to forward information received on GPS1 UART1 to GPS2 UART1:
>>> import sbc
>>> pm = sbc.Power_Module()
>>> pm.gps2and3_on()
>>> gps1 = sbc.Gps( 1, 115200 )
>>> gps2 = sbc.Gps( 2, 115200 )
>>> gps1.forward_to( gps2 )
forward_disable()

Disables GPS/GNSS fordwarding

get_uart_id()

Gets GPS/GNSS receiver UART port

Return:

GPS/GNSS receiver UART port

Note

Since the get_uart_id() method of the Gps class returns a microPython UART object, it has all its methods.
To do not duplicate the documentation, we suggest to take a look at the official microPython project documentation to see what methods you can additionaly use.

Example of additional methods:
>>> import sbc
>>> gps1 = sbc.Gps( 1, 115200 )
>>> print('There are: ',gps1.get_uart_id().any(),' characters to be read')
There are:  1580  characters to be read
>>> print(gps1.get_uart_id().readline())
b'$GNGGA,142222.00,4136.52091,N,00036.70322,E,2,10,1.27,203.6,M,49.8,M,,0000*4D\r\n'