Sunday, February 23, 2014

SoftwareSerial and GPS



How to use SofwareSerial library to connect a Serial GPS on the Official Arduino Robot? 

We have chosen for our robot this excellent "Ultimate GPS" module from Adafruit, because it requires only 2 pins (using serial communication) to communicate with and it's plenty of good functionality (autonomous GPS logger, Time RTC, energy safer...).


Wiring

Due to lack of memory on the Control Board, we've decided to connect the GPS to the Motor board.
2 digital pin included one using interrupts are required to connect the GPS to the Motor Board.
We decide to connect the TX pin of the GPS to the SPI/ICSP connector on MOSI pin because it's a Digital pin with interrupt management and connector was not used on this board.


The RX pin of the GPS must be connected to another digital pin, we choose TK3 (B_TK3 on the picture)

Coding

You have to include the SoftwareSerial library to your project but with Arduino IDE 1.5.4 some core arduino header files must be patched to be able to compile.
You have to add these 4 definition (digitalPinToPCICR, digitalPinToPCICRbit, digitalPinToPCMSK, digitalPinToPCMSKbit(p) ) into the pin_arduino.h file in these following directories:

  • ...\Arduino\hardware\arduino\avr\variants\robot_control 
  • ...\Arduino\hardware\arduino\avr\variants\robot_motor


Command must be created on both board to communicate and share GPS request/answers.

Command on the Control Board


Response on the Motor Board

GPS Management has been coded without interrupt due to problem using Interrupt, SoftwareSerial library and Serial.print() function (I still not not have answer for this trouble, any idea?).

How to well understand the GPS information received?

According to the GPS, a location as 4042.6142,N (Latitude 40 degrees, 42.6142 decimal minutes North) & 07400.4168,W. (Longitude 74 degrees, 0.4168 decimal minutes West) To look at this location in Google maps, type +40° 42.6142', -74° 00.4168' into the google maps search box . Unfortunately gmaps requires you to use +/- instead of NSWE notation. N and E are positive, S and W are negative. The code has been adapted in consequence. 

People often get confused because the GPS is working but is "5 miles off" - this is because they are not parsing the lat/long data correctly. Despite appearances, the geolocation data is NOT in decimal degrees. It is in degrees and minutes in the following format: Latitude: DDMM.MMMM (The first two characters are the degrees.) Longitude: DDDMM.MMMM (The first three characters are the degrees.)    

Related link:


No comments:

Post a Comment