Connect to a Serial GPS

This are just some notes (that may eventually be useful to someone) on how to connect Bifferboard to a serial GPS receiver.


- 1 Bifferboard

- 1 USB Pen Drive

- 1 Serial GPS module powered from 3.3VDC, 5Hz of data sampling (LS20031)

Pinouts for Serial Connection:

- Bifferboard:

- GPS LS20031:

Please note: Bifferboard TX (pin9) will connect to GPS RX (pin2) and BB RX (pin8) with GPS TX (pin3). VCC and GND will connect directly between each other.

Preparing Bifferboard system for serial connection to GPS

Bifferboard Serial port by default will be attached to the operating system and in order to free up this port it is required to follow this steps (already described in other tutorial):

Step 1.a), 1.c) and 1.d)

Sending GPS configuration commands (5Hz data output)


Note: run only once, gps module will then be configured with the selected settings.

Create a script called gpsconfig and give it execution permissions (chmod u+x gpsconfig):

# --------------------------------------------------------------------------------------

# gpsconfig

# --------------------------------------------------------------------------------------

stty ispeed 4800 ospeed 4800 -F /dev/ttyS0

sleep 5

echo -n -e "$PMTK251,38400*27\r\n">/dev/ttyS0

sleep 5

stty ispeed 38400 ospeed 38400 -F /dev/ttyS0

sleep 5

echo -n -e "$PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28\r\n">/dev/ttyS0

sleep 5

stty ispeed 57600 ospeed 57600 -F /dev/ttyS0

sleep 5

echo -n -e "$PMTK220,200*2C\r\n">/dev/ttyS0

sleep 5

# --------------------------------------------------------------------------------------

run the configuration script:

> ./gpsconfig

Getting GPS data in text mode (to use with command line)

> stty ispeed 57600 ospeed 57600 -F /dev/ttyS0

> cat /dev/ttyS0

Note1: after messing around with my gps module configurations I'm only able to connect @38400bps and so use:

> stty ispeed 38400 ospeed 38400 -F /dev/ttyS0

> cat /dev/ttyS0

Note2: you should only connect (physically) the GPS module after setting the BB serial port speed. When booting BB with GPS module attached it gets confused and defaults into factory mode (Binary data @unknown_speed). Will require some extra tests to detect the specific problem and find a workaround.

Getting and parsing GPS data from custom application (based on C code)

There are already several applications/libraries that implement this functionality, but I wanted to test my C skills into Linux Embedded devices (X86 compatible) and so forced myself to make this very simple example that I will use as basis for future projects.

For the initial tests I was using gcc compiler with the -static option to create a binary (statically linked) that would run on Bifferboard OS (tested on OpenWrt but will work on others too). Since the binary was getting a bit huge, around 570Kb, I decided to test it with dietlibc alternative libraries with the objective of getting a final binary a bit smaller! Dietlibc was a success, final binary is now getting compiled around 25Kb and will run on Bifferboard OSs without the need of external libraries.

Dietlibc project:

To get it running you will need:

1- install gcc

2- install dietlibc (follow the instructions from dietlibc website)

note: from my Linux Ubuntu 9.04 it was only required to:

> sudo apt-get update

> sudo apt-get install dietlibc dietlibc-dev dietlibc-doc

3- download the application source code from this page (gpsparser.tar.gz)

4- extract the source code: tar -zxvf gpsparser.tar.gz

5- compile binary with:

> cd gpsparser

> make clean; make;

6- copy the compiled binary from gpsparser/src/gpsparser to bifferboard

7- set bifferboard serial port speed

8- attach gps module

9- run gpsparser app.

Source code available at: gpsparser/src/gpsparse.c

Binary also attached to this page (for quicker tests - if possible build your own binaries).

At the present moment gpsparser application is parsing the GPS data and converting it into internal structures that can be used for other purposes. It will also output data to screen just for debug purpose! The sequence of the data output is similar to the NMEA code, so for better comprehension please consult:

Latitude and Longitude data was converted into numeric format so that it could be proper saved into a double variable. (Also good to test coordinates, just put it directly into google maps and it will give you the correct location).

Getting GPS data from a TCP/IP interface (based on C code with thread implementing the tcp/ip interface)

Decided to expand the previous application and add tcp/ip interface to serve gps data on request. Since my main() routine was already busy getting data from Serial Port and parsing it to the global structures it was necessary to create a thread that would then implement the tcp/ip interface (sockets will lock cpu until next request arrives, so thread is really mandatory here). Found some Linux examples on how to create a threads here: (html-ls-server.c)

This excellent example will use tcp/ip thread to respond a http request (useful to get data from browsers).

Algo got this compiling with dietlibc, so binary will also be portable between X86 based OSs.

Please follow the previous steps to compile the new binary and send it to Bifferboard. Use the gpsparserhttpd.tar.gz file instead.

You can run it with debug info:

> gpsparser /debug

But normally you should launch it with no debug info (& to launch it in background - require latter to 'ps -ax' to search for the PID and use kill to terminate):

> gpsparser&

By default the thread will create the tcp/ip interface on port 3090.

To request GPGGA data it is necessary to use the following url, place it on the browser (IP referent to bifferboard):

Browser Output: GPGGA|234340.794000|37.034711|-8.040168|0|Invalid|0|0.000000|100.6|49.5|0.0

To request GPRMC use:

Browser Output: GPRMC|705.794000|V|Void|37.034711|-8.040168|0.0|0.0|40909|0.0|0

note: instead of the browser you can also use the netcat command:

> echo 'GET /gpgga HTTP' | nc 3090

> echo 'GET /gprmc HTTP' | nc 3090

TODO: display a google map with the device actual location. (use a netbook with mobile broadband internet access to show google maps and get gps data from bifferboard over http request and update current position on the browser - greasmonkey script should be +- easy) - That's what I can a real car navigator system, live images from satellite :P.

Bifferboard with GPS module attached

// NN