Results 1 to 3 of 3
- 02-18-2014, 12:45 PM #1Member
- Join Date
- Feb 2014
- Rep Power
GPS & Bluetooth connection in Arduino
Hello, I am new to Java programming and I am trying to receive GPS coordinates to my phone via Bluetooth.
-My GPS code seems to be working but cant pick up satellite signals
-I'm quite sure if my Bluetooth code is working
-And most importantly I don't have a clue how to put the two together!
Here is my GPD code -
Example GPS Parser based off of arduiniana.org TinyGPS examples.
Parses NMEA sentences from an EM406 running at 4800bps into readable
values for latitude, longitude, elevation, date, time, course, and
For the SparkFun GPS Shield. Make sure the switch is set to DLINE.
Once you get your longitude and latitude you can paste your
coordinates from the terminal window into Google Maps. Here is the
link for SparkFun's location.
Uses the NewSoftSerial library for serial communication with your GPS,
so connect your GPS TX and RX pin to any digital pin on the Arduino,
just be sure to define which pins you are using on the Arduino to
communicate with the GPS module.
changed values to RXPIN = 2 and TXPIN = to correspond with
hardware v14+. Hardware v13 used RXPIN = 3 and TXPIN = 2.
// In order for this sketch to work, you will need to download
// TinyGPS library from arduiniana.org and put them
// into the hardware->libraries folder in your ardiuno directory.
// Define which pins you will use on the Arduino to communicate with your
// GPS. In this case, the GPS module's TX pin will connect to the
// Arduino's RXPIN which is pin 3.
#define RXPIN 2
#define TXPIN 3
//Set this value equal to the baud rate of your GPS
#define GPSBAUD 4800
// Create an instance of the TinyGPS object
// Initialize the NewSoftSerial library to the pins you defined above
SoftwareSerial uart_gps(RXPIN, TXPIN);
// This is where you declare prototypes for the functions that will be
// using the TinyGPS library.
void getgps(TinyGPS &gps);
// In the setup function, you need to initialize two serial ports; the
// standard hardware serial port (Serial()) to communicate with your
// terminal program an another serial port (NewSoftSerial()) for your
// This is the serial rate for your terminal program. It must be this
// fast because we need to print everything before a new sentence
// comes in. If you slow it down, the messages might not be valid and
// you will likely get checksum errors.
//Sets baud rate of your GPS
Serial.println("GPS Shield QuickStart Example Sketch v12");
Serial.println(" ...waiting for lock... ");
// This is the main loop of the code. All it does is check for data on
// the RX pin of the ardiuno, makes sure the data is valid NMEA sentences,
// then jumps to the getgps() function.
while(uart_gps.available()) // While there is data on the RX pin...
int c = uart_gps.read(); // load the data into a variable...
if(gps.encode(c)) // if there is a new valid sentence...
getgps(gps); // then grab the data.
// The getgps function will get and print the values we want.
void getgps(TinyGPS &gps)
// To get all of the data into varialbes that you can use in your code,
// all you need to do is define variables and query the object for the
// data. To see the complete list of functions see keywords.txt file in
// the TinyGPS and NewSoftSerial libs.
// Define the variables that will be used
float latitude, longitude;
// Then call this function
// You can now print variables latitude and longitude
// Same goes for date and time
byte month, day, hour, minute, second, hundredths;
// Print data and time
Serial.print("Date: "); Serial.print(month, DEC); Serial.print("/");
Serial.print(day, DEC); Serial.print("/"); Serial.print(year);
Serial.print(" Time: "); Serial.print(hour, DEC); Serial.print(":");
Serial.print(minute, DEC); Serial.print(":"); Serial.print(second, DEC);
Serial.print("."); Serial.println(hundredths, DEC);
//Since month, day, hour, minute, second, and hundr
// Here you can print the altitude and course values directly since
// there is only one value for the function
Serial.print("Altitude (meters): "); Serial.println(gps.f_altitude());
// Same goes for course
Serial.print("Course (degrees): "); Serial.println(gps.f_course());
// And same goes for speed
Serial.print("Speed(kmph): "); Serial.println(gps.f_speed_kmph());
// Here you can print statistics on the sentences.
unsigned long chars;
unsigned short sentences, failed_checksum;
gps.stats(&chars, &sentences, &failed_checksum);
//Serial.print("Failed Checksums: ");Serial.print(failed_checksum);
Here is my Bluetooth code -
char val; // variable to receive data from the serial port
Serial.begin(9600); // start serial communication at 9600bps
if( Serial.available() ) // if data is available to read
val = Serial.read(); // read it and store it in 'val'
Email me firstname.lastname@example.org
- 02-18-2014, 06:49 PM #2
Re: GPS & Bluetooth connection in Arduino
You're not likely to get help with that code in this forum. Try the Arduino forum.
You didn't mention what kind of phone you have, but assuming it's Android, you could ask about that part of your project in the Android forum here.Get in the habit of using standard Java naming conventions!
- 02-19-2014, 10:55 AM #3Member
- Join Date
- Feb 2014
- Rep Power
- By Anel Murselji in forum Advanced JavaReplies: 8Last Post: 06-22-2011, 01:03 PM
- By veeru541 in forum Advanced JavaReplies: 2Last Post: 06-27-2010, 03:14 AM
- By abhijit in forum NetworkingReplies: 0Last Post: 09-22-2009, 01:10 PM
- By yash2009 in forum CLDC and MIDPReplies: 1Last Post: 08-07-2009, 10:30 AM
- By weber10 in forum CLDC and MIDPReplies: 0Last Post: 02-26-2009, 09:14 PM