Run GPS On Beaglebone Black
Connect the GPS Module to BBBlack
Enable UART in Beaglebone Black
The BeagleBone Black has six on-board serial ports. On
the BeagleBone Black, it's only the /dev/ttyO0 that is enabled by
default, and it is coupled to the serial console. The other serial ports
must be enabled before they can be used.
| RX | TX | CTS | RTS | Device | Remark | |
| UART0 | J1_4 | J1_5 | /dev/ttyO0 | BeagleBone Black only | ||
| UART1 | P9_26 | P9_24 | P9_20 | P9_19 | /dev/ttyO1 | |
| UART2 | P9_22 | P9_21 | P8_37 | P8_38 | /dev/ttyO2 | |
| UART3 | P9_42 | P8_36 | P8_34 | /dev/ttyO3 | TX only | |
| UART4 | P9_11 | P9_13 | P8_35 | P8_33 | /dev/ttyO4 | |
| UART5 | P8_38 | P8_37 | P8_31 | P8_32 | /dev/ttyO5 |
Since we connect the gps to pin P9_26 and P9_24, UART1 must be enabled.
To enable it, the root user should be used by typing
debian@beaglebone:sudo su
Then follow these steps below:
root@beaglebone:/home/debian# echo > BB-UART1 > /sys/devices/bone_capemgr.9/slots
root@beaglebone:/home/debian# cat /sys/devices/bone_capemgr.9/slots
0: 54:PF---
1: 55:PF---
2: 56:PF---
3: 57:PF---
4: ff:P-O-L Bone-LT-eMMC-2G,00A0,Texas Instrument,BB-BONE-EMMC-2G
5: ff:P-O-L Bone-Black-HDMI,00A0,Texas Instrument,BB-BONELT-HDMI 7: ff:P-O-L Override Board Name,00A0,Override Manuf,BB-UART1
debian@beaglebone:~$ ls -l /dev/ttyO*
crw-rw---- 1 root tty 248, 0 May 15 2014 /dev/ttyO0
crw-rw---T 1 root dialout 248, 1 Mar 24 05:17 /dev/ttyO1
You can enable the UART during boot directly by configure uEnv.txt as
root@beaglebone:/dev# nano /boot/uboot/uEnv.txt
##Example
#cape_disable=capemgr.disable_partno=
#cape_enable=capemgr.enable_partno=BB-UART1
Test GPS data with minicom
Start the serial debugging assistant, and set the serial port as below:
- Select the corresponding serial port in the Port no option. In this example, /dev/tty01 is selected.
- Baud rate: 9600(default).
- 8 data bits, 1 stop bit, no parity and no flow control.
Install minicom in BBBlack by typing
root@beaglebone:apt-get install minicom
Then test the incoming data by accessing /dev/tty01 with minicom with the baud rate 9600
root@beaglebone:minicom -b 9600 /dev/tty01
$GPRMC,105733.00,V,,,,,,,110817,,,N*70
$GPVTG,,,,,,,,,N*30
$GPGGA,105733.00,,,,,0,00,99.99,,,,,,*65
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30
$GPGSV,2,1,05,01,,,25,09,,,26,10,,,26,18,,,28*72
$GPGSV,2,2,05,28,,,25*71
$GPGLL,,,,,105733.00,V,N*49
$GPRMC,105734.00,V,,,,,,,110817,,,N*77
$GPVTG,,,,,,,,,N*30
$GPGGA,105734.00,,,,,0,00,99.99,,,,,,*62
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30
$GPGSV,1,1,04,04,,,25,09,,,25,18,,,26,28,,,24*71
$GPGLL,,,,,105734.00,V,N*4E
$GPRMC,105735.00,V,,,,,,,110817,,,N*76
$GPVTG,,,,,,,,,N*30
$GPGGA,105735.00,,,,,0,00,99.99,,,,,,*63
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30
$GPGSV,2,1,05,04,,,24,09,,,25,12,,,27,18,,,25*7B
$GPGSV,2,2,05,28,,,23*77
$GPGLL,,,,,105735.00,V,N*4F
$GPRMC,105736.00,V,,,,,,,110817,,,N*75
$GPVTG,,,,,,,,,N*30
After waiting for a while, if the serial debugging assistant lists similar data inits window as the figure shows below, it means GPS has performed positioning.And you can see that the LED on the module, which remains on when GPS is unable to perform the positioning, is flickering now.
$GPGGA,110656.00,XXXXXXXXX,N,XXXXXXXX,E,1,04,4.29,131.4,M,-6.0,M,,*44
$GPGSA,A,3,20,13,05,02,,,,,,,,,6.06,4.29,4.27*0B
$GPGSV,3,1,12,02,37,082,16,05,16,029,24,06,05,116,,12,23,192,*71
$GPGSV,3,2,12,13,48,032,34,15,77,325,,18,12,279,,20,30,343,27*75
$GPGSV,3,3,12,21,00,320,,24,34,170,,25,21,230,15,29,52,312,*72
$GPGLL,0313.69879,N,10143.56969,E,110656.00,A,A*66
$GPRMC,110657.00,A,XXXXXX,N,XXXXXXX,E,5.725,14.75,110817,,,A*59
$GPVTG,14.75,T,,M,5.725,N,10.603,K,A*3B
$GPGGA,110657.00,XXXXX,N,XXXXXXX,E,1,04,4.29,132.3,M,-6.0,M,,*44
$GPGSA,A,3,20,13,05,02,,,,,,,,,6.06,4.29,4.27*0B
$GPGSV,3,1,12,02,37,082,17,05,16,029,24,06,05,116,,12,23,192,*70
$GPGSV,3,2,12,13,48,032,34,15,77,325,,18,12,279,17,20,30,343,27*73
$GPGSV,3,3,12,21,00,320,,24,34,170,,25,21,230,,29,52,312,*76
$GPGLL,XXXXXXX,N,1XXXXXXXX,E,110657.00,A,A*62
$GPRMC,110658.00,A,XXXXXXX,N,XXXXXXXX,E,4.772,15.51,110817,,,A*53
Notice: For its first positioning after cold starts, GPS module normally takes 1-3 minutes to finishing this positioning successfully in the open air with a good weather. So, please be patient. Moreover, if there is a bad weather, it may take more time for positioning, or even unable to perform positioning sometimes.
Start Program the Code
To start coding we need to install all dependency libraries such as serial to get serial output from GPS and pynmea2 to parse the GPS information
sudo apt-get install python-serial
Install pymea2 from https://github.com/Knio/pynmea2 to parse information of NMEA 0183 sentence.
pip install pynmea2
After finish the installation create a python file for example gps_log.py then copy the code below:
1: import serial
2: import pynmea2
3: def parseGPS(str):
4: if str.find('GGA') > 0:
5: msg = pynmea2.parse(str)
6: print "Timestamp: %s -- Lat: %s %s -- Lon: %s %s -- Altitude: %s %s" % $ % (msg.timestamp,msg.lat,msg.lat_dir,msg.lon,msg.lon_dir,msg.altitude,msg.altitude_units)
7: ser= serial.Serial("/dev/ttyO1", 9600)
8: while True:
9: str = ser.readline()
10: parseGPS(str)
Then you will get gps position results as below:
Timestamp: 11:14:38 -- Lat: XXXXXXXX N -- Lon: XXXXXXXXX E -- Altitude: 18.8 M
Timestamp: 11:14:39 -- Lat: XXXXXXXX N -- Lon: XXXXXXXXX E -- Altitude: 22.4 M
Timestamp: 11:14:40 -- Lat: XXXXXXXX N -- Lon: XXXXXXXXX E -- Altitude: 31.4 M


Comments
Post a Comment