Connecting GPS to the BeagleBone Black

First, you'll need to obtain a GPS unit. There are many that are available, with different interfaces. Connecting a device that has a USB interface is very straightforward. When you plug the USB device into the BeagleBone Black, it will automatically try to recognize the new device and install the driver for it. The advantage of this approach is that it is very easy and you won't need to update any driver files. The problem with this approach is that you will need to add a powered USB hub.

Another possible choice that won't require an additional USB hub is a GPS that can connect to the RX/TX GPIO pins of the BeagleBone Black. The VPN1513 GPS Receiver w/ Antenna, marketed by Parallax and available on their online store, is an example of this choice. Here is an image of the device:

Connecting GPS to the BeagleBone Black

You should also purchase an antenna that can connect to the RF (gold) connector on the board. This is type SMA; these are available from electronic online retailers. Here is an image of a possible antenna:

Connecting GPS to the BeagleBone Black

This particular device uses a standard RX/TX (UART) interface, one that your BeagleBone Black supports. In order to connect the device, you'll need to connect to the pins on the board. Here is an image of those pins:

Connecting GPS to the BeagleBone Black

You'll connect your BeagleBone Black using the male-to-female solderless jumper cables. Here are the connections on the BeagleBone Black:

BeagleBone Black pin

GPS cable pin

P9_3

VCC

P9_1

GND

P9_26

TX

P9_24

RX

Now that the two devices are connected, you can access the device via the BeagleBone Black.

Communicating with the GPS

The GPS device will be talking over the RX/TX interface, so you'll need to use the Adafruit libraries that you installed in Chapter 6, A Robot that Can Sail. Now you are going to create a simple Python program that will read the location string from your GPS device. Before you do this however, you may need to add some additional software drivers so that your BeagleBone Black can talk via the RX/TX interface. To find out if you need to add them, type ls /dev/tty* in the prompt. You will be looking for the /dev/tty01 listing. This will be available in some releases, but in many it will not. If it is not available, then do the following:

  1. Go to www.armhf.com/beaglebone-black-serial-uart-device-tree-overlays-for-ubuntu-and-debian-wheezy-tty01-tty02-tty04-tty05-dtbo-files/ and download the ttyO1_armhf.com-00A0.dtbo file. This is an overlay file that defines a hardware interface. The web page has more information on overlay files, how they are created, and why they are important.
  2. Copy this file to the /lib/firmware directory.
  3. Become the root user by typing sudo su and the appropriate passwords.
  4. Now you'll need to issue the echo ttyO1_armhf.com > /sys/devices/bone_capemgr*/slots command.

If you've done these steps correctly, you can type in ls /dev/tty* and you should now see the /dev/tty01 device. Unfortunately, you'll need to type the command listed in step 3 and step 4 every time you boot to enable the device. You can type it in a .*sh script file to be executed at each startup. See http://askubuntu.com/questions/814/how-to-run-scripts-on-start-up for several ways to do this.

Now that your BeagleBone Black can talk via the RX/TX interface, you'll create a program to communicate with the GPS unit. To do this, if you are using Emacs as an editor, type emacs measgps.py. A new file called measgps.py will be created. Then type the following code:

Communicating with the GPS

Let's go through the code to see what's happening:

  • #!/usr/bin/python: As before, the first line simply makes this file available for you to execute from the command line.
  • import Adafruit_BBIO.UART as UART: You'll import the Adafruit UART library. This will allow us to interface with the BeagleBone Black's GPIO pins.
  • import serial: This allows you to import the serial library to interface with the RX/TX port.
  • UART.setup("UART2"): This initializes the interface to the tty01 device.
  • ser = serial.Serial(port = "/dev/ttyO1", baudrate=9600): This command sets up the serial port to use the /dev/ttyO1 device, which is our GPS sensor, using a baud rate of 9600.
  • x = ser.read(1200): This is the next command that reads a set of values from the RX/TX port. In this case, you read 1200 values that will include a full set of GPS data.
  • print x: This is the final command that prints the value.
  • ser.close(): This command closes the serial port.
  • UART.clearup(): This cleans up the UART port.

Once this file has been created, you can run the program and talk to the device. Do this by typing sudo python measgps.py and the program will run. You should see something like the following screenshot:

Communicating with the GPS

The device is providing raw readings back to you, which is a good sign. Unfortunately there isn't much good data here as the unit is inside. How do you know this? Look at one of the lines that start with $GPRMC. This line should tell you your current latitude and longitude values. The GPS is reporting the following command:

$GPRMC,160119.170,V,,,,,,,011013,,,N*

This line of data should show results similar to the following, with each field separated by a comma:

0

$GPRMC

1

220516

2

A

3

5133.82

4

N

5

00042.24

6

W

7

173.8

8

231.8

9

130694

10

004.2

11

W

12

*70

The following is the explanation of each of these fields:

Field

Value

Explanation

1

220516

Timestamp

2

A

Validity—A (OK), V (Invalid)

3

5133.82

Current latitude

4

N

North or south

5

00042.24

Current longitude

6

W

East or west

7

173.8

Speed in knots you are moving

8

231.8

Course—the angle direction in which you are moving

9

130694

Date stamp

10

0004.2

Magnetic variation—variation from magnetic and true North

11

W

East or West

12

*70

Checksum

In this case, field number 2 reports V, which means the unit cannot find enough satellites to get a position. Taking the unit outside, you should get something like this with your measgps.py file:

Communicating with the GPS

Notice that the $GPRMC line now reads this:

$GPRMC,020740.000,A,4349.1426,N,11146.1064,W,1.82,214.11,021013,,,A*7B

The field values are now as follows:

Field

Value

Explanation

1

020740.000

Timestamp

2

A

Validity—A (OK), V (Invalid)

3

4349.1426

Current latitude

4

N

North or south

5

11146.1064

Current longitude

6

W

East or west

7

1.82

Speed in knots you are moving

8

214.11

Course—the angle direction in which you are moving

9

021013

Date stamp

10

 

Magnetic variation—variation from magnetic north to true north

11

 

East or west

12

*7B

Checksum

Now you know where you are. However, it is in the raw form. In the next section, you will learn how to do something with these readings.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.95.38