-
Notifications
You must be signed in to change notification settings - Fork 34
/
gps.c
30 lines (26 loc) · 855 Bytes
/
gps.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <stdio.h>
#include <stdlib.h>
#include <wiringSerial.h>
// https://pinout.xyz/pinout/uart (Raspberry Pi Pinout, 3V3 <-> VCC, TX <-> RX, RX <-> TX, GND <-> GND)
// https://www.u-blox.com/sites/default/files/PAM-7Q_DataSheet_(UBX-13002455).pdf (GPS Pinout p.11)
// $ sudo raspi-config # Interfacing options > Serial > Disable console > Enable UART
// $ gcc -o gps gps.c -lwiringPi
//#define SERIAL_DEVICE "/dev/ttyAMA0"
//#define SERIAL_DEVICE "/dev/ttyS0"
#define SERIAL_DEVICE "/dev/serial0"
//#define BAUD_RATE 115200
#define BAUD_RATE 9600
int main(void) {
int fd = serialOpen(SERIAL_DEVICE, BAUD_RATE);
if (fd == -1) {
perror("serialOpen");
exit(-1);
}
int ch = serialGetchar(fd);
while(ch != -1) {
putchar(ch);
ch = serialGetchar(fd);
}
perror("serialGetchar");
exit(-1);
}