Receiving and displaying GPS coordinates on Arduino

Once I had an interest in GPS, and even a little earlier - in the Arduino platform. Therefore, with Sparkfun were ordered, with a difference of a couple of days, Arduino Duemilanove, GPS Shield and GPS receiver EM-406A .
The order came and partially lay on the shelf, and recently hands reached this kit ...

Assembled GPS Shield connected to Arduino



Hardware


  • Arduino duemilanove
  • GPS shield
  • GPS receiver EM-406A
  • LCD WH-0802A

For greater mobility, the platform is powered by a separate battery and connects to the computer only for uploading a new sketch.

Pinout of the GPS module EM-406A



In the presence of a shield, pinout, by and large, is not so important - you just need to insert two connectors. If the shield is missing, then you need to connect the GND pins to GND, Rx to digital pin 2, Tx to digital pin 3, VCC to POWER 5V. Attention, the gray wire is not 1, but 6th!

The GPS module has an LED status indicator:
  • the indicator is constantly on - satellites are being searched and coordinates are being determined
  • the indicator blinks - the coordinates are set, they are being transmitted
  • the indicator is off, power is supplied to the shield - poor contact in the connectors or the module switched to the binary SiRF protocol


UART / DLINE Switch


Using the switch, you can connect the Rx and Tx GPS module to the legs of the Tx and Rx Arduino (UART position) or to pin digital 2 and digital 3 (DLINE position, if you do not remove the jumpers from the solder). You need to make sure that the switch is in the “DLINE” position, otherwise there may be problems with sketching in Arduino.

Connection of a sign-synthesizing LCD indicator

I did not buy a separate shield under the screen and connected an existing indicator - WH-0802A in 4-bit mode. In principle, this way you can connect any other sign-synthesizing indicator. To do this, find the pinout in the datasheet and connect the RS, E, D4, D5, D6, D7 lines to any digital pins (except 0 ... 3) and do not forget to configure where these lines are connected in the code, Vss, R / W - to GND, Vdd - to 5V. The Vo output (contrast setting) needs to be connected to a potentiometer connected between GND and 5V, but I just connected it to GND - the resulting contrast suits me.

Pin assignment for indicator WH-0802A



My version of connecting the indicator to Arduino

  • RS - pin 13
  • E - pin 12
  • D4 - pin 11
  • D5 - pin 10
  • D6 - pin 9
  • D7 - pin 8
  • Vss, R / W, Vo - GND
  • Vdd - 5V

Software part


For work with GPS two libraries TinyGPS and NewSoftSerial are required . Libraries are unpacked in the libraries directory.
#include
#include
#include
TinyGPS gps;
//Tx, Rx
NewSoftSerial nss(2, 3);
//Конфигурация линий, куда подключен lcd: RS, E, D4, D5, D6, D7
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
bool feedgps();
void setup() {
  //4800 скорость обмена с GPS приемником
  nss.begin(4800);
  //8 символов, 2 строки
  lcd.begin(8, 2);
  lcd.print("waiting");
}
void loop() {
  bool newdata = false;
  unsigned long start = millis();
  long lat, lon;
  unsigned long age;
  //задержка в секунду между обновлениями координат
  while (millis() - start < 1000) {
    if (readgps())
       newdata = true;
  }
  if (newdata) {
    gps.get_position(&lat, &lon, &age);
    lcd.setCursor(0, 0);
    lcd.print(lat);
    lcd.setCursor(0, 1);
    lcd.print(lon);
  }
}
bool readgps() {
  while (nss.available()) {
    int b = nss.read();
    //в TinyGPS есть баг, когда не обрабатываются данные с \r и \n
    if('\r' != b) {
      if (gps.encode(b))
          return true;
    }
  }
  return false;
}

After turning on the GPS module and filling in the sketch, you need to wait at least 42 seconds (cold start time) for the module to determine its location and begin to issue valid coordinates. When the module goes into operating mode, it will blink an LED. On my desktop, the module can not always find satellites - you have to transfer it to the window.

A working module with a connected display and received coordinates


To the right of the display is a power source for backlighting.
After determining the satellites, the coordinates appear on the display and are updated once a second.
As a result, experience was gained and the basis for the further development of GPS.

"Used Books"



Also popular now: