Tuesday, October 1, 2013

GPS for the Beaglebone Black: Sparkfun Copernicus II DIP Module

Note (06/20/2014) - For an updated and improved version tested on the Beaglebone Black Rev. C running Ubuntu, see this post.

Earlier in the summer, I posted about using the D2523T 50 Channel Helical GPS Receiver with the Beaglebone Black.  I have also found the Copernicus II DIP Module from Sparkfun to be a very good GPS option. At $74.95, the price is similar to the D2532T.  To help with reception indoors at my desk while doing development, I am using this antenna.

The Python code below is very similar to my earlier post, but I have added a line showing how easy it is to write configuration commands to the module using the PySerial library.

For more information on the NMEA configuration commands, see Appendix C of the Copernicus II manual. The command must include a 2-digit checksum after the asterisk.  See this page for an online tool to calculate the checksum.

Connections


GPS Module  Beaglebone Black
VCC         P9 3
GND         P9 1
TX-B        P9 26
RX-B        P9 24

See this post for the configuration needed to use the Beaglebone Black's pins for serial (UART) communication.


Python Code



import serial
import time
import datetime
import re
import os

os.system("echo uart1 > /sys/devices/bone_capemgr.9/slots")

# Adjust the connection speed as needed. 
# You can use Triimble Studio on your PC to detect/set speed
# if you can't figure it out. 
serial = serial.Serial("/dev/ttyO1", baudrate=115200)

# Send NMEA config cmd to output only $GPRMC message every second
nmeaCmd = "$PTNLSNM,0100,01*56\r\n"
serial.write(nmeaCmd)

resp = ""

while True:
        while (serial.inWaiting() > 0):
                resp += serial.read()
                if "\r\n" in resp:
                        if "$GPRMC" in resp:
                                data = resp.split(',')
                                info = "UTC: %s  Date: %s  N Lat: %s  W Long: %s" % (
                                        data[1], data[9], data[3], data[5])
                                print info
                        resp = ""

No comments:

Post a Comment