element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Success! GPS with Serial LCD - Arduino Uno
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 2 replies
  • Subscribers 392 subscribers
  • Views 376 views
  • Users 0 members are here
Related

Success! GPS with Serial LCD - Arduino Uno

Former Member
Former Member over 12 years ago

Hello,

  A couple of days ago, I had posted a question at this forum asking how to use a serial LCD with GPS. I have just done this and the code is below...

 

The problem is that when you use SoftwareSerial, you can create multiple (soft) serial ports (like one for the serial lcd and one for the GPS), but only one of them can be active at any given time. There are methods to choose a particular port and read from it, but I found that a simpler solution is to connect the GPS module to the built in hardware serial port on the Uno (digital pins 0 and 1).

  I am using the Sparkfun GPS shield (https://www.sparkfun.com/products/10709) and the Sparkfun Serial LCD (https://www.sparkfun.com/products/9395) with an Arduino Uno.

  The Sparkfun GPS shield has a switch labelled UART - DLINE. To upload any code to the Arduino this switch must be in the DLINE position. If you create a SoftwareSerial port to read GPS data, this switch remains in the DLINE position. If you want to use the built in hardware serial port on pins 0/1, change this to the UART position (after uploading the code).Then the Serial object will read from and write to this hardware post. No connections need to be made for this. The Serial LCD is connected to a SoftwareSerial port. Here is the code - I put an LED on pin 13 to tell me if I could connect to a satellite...

 

 

 

// LED on pin 13, GPS connected to Hardware Serial pins 0/1

// so must be compiled with switch in DLINE position and run with switch in UART position

//

 

#include "TinyGPS.h"

#include <SoftwareSerial.h>

 

TinyGPS gps; // create a TinyGPS object

 

#define pin13 13

 

SoftwareSerial myLCD(4,7); // RX, TX

 

void setup() {

  Serial.begin(4800); // GPS device operates at 4800 baud

  pinMode(pin13, OUTPUT);

  digitalWrite(pin13, LOW); // turn off LED to start

 

  myLCD.begin(9600);

  delay(800);

  clearScreen();

  myLCD.print("Wait...");

 

}

 

void loop() {

  while (Serial.available()) {

    int c = Serial.read();

 

    if (gps.encode(c)) {

 

      float lat, lon;

      gps.f_get_position(&lat, &lon);

      if (lat>18 && lat<19)              // that's where I live...

        digitalWrite(pin13, HIGH);

      else

        digitalWrite(pin13, LOW);

 

      clearScreen();

 

      myLCD.write(0xFE); // command flag

      myLCD.write(128); // write to line 1

      //delay(10);

      //myLCD.print("La = ");

      myLCD.print(lat, DEC);

 

      myLCD.write(0xFE); // command flag

      myLCD.write(192); // write to line 2

      //delay(10);

      //myLCD.print("Lo = ");     

      myLCD.print(lon, DEC);

 

    }

  }

}

 

void clearScreen() {

  myLCD.write(0xFE);

  myLCD.write(0x01);

}

 

/////////////////////////////////////////////////////////

I only had one problem - When I try to print the line "La = ", I get garbage on the serial lcd (instead of the string "La = ") though the rest of the output is fine. Don't know why that happens??? image

 

  Ravi

  • Sign in to reply
  • Cancel
Parents
  • billabott
    billabott over 12 years ago

    You might cure your little problem with printing "La =" by adding the following to the end of setup().

     

      mySerial.write(254); // move cursor to beginning of first line

      mySerial.write(128);

     

      mySerial.write("                "); // clear display

      mySerial.write("                ");

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • billabott
    billabott over 12 years ago

    You might cure your little problem with printing "La =" by adding the following to the end of setup().

     

      mySerial.write(254); // move cursor to beginning of first line

      mySerial.write(128);

     

      mySerial.write("                "); // clear display

      mySerial.write("                ");

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube