The first example given in the Arduino IDE (BasicExample.ino) worked fine (once I had reduced the Serial Monitor baud rate from 115200 to 9600.)
Now I'm trying the next example (DeviceExample.ino). I made no changes to the sketch.
void setup works: I get the header texts out.
However, gps.encode( ss.read() ) stays at 0. So, I get no location info out.
The GPS module connected is a u-blox 6M.
Its LED flashes, signaling that it has locked satellites.
When I connect it directly to PC (via USB), u-center shows that it works correctly.
I suppose TX pin on the module must be connected to RX pin (4) on the Arduino and
the RX pin on the module must be connected to TX pin (3) on the Arduino. Right?
(I tried switching them around with no luck.)
I have tested that the connections are intact and that there is no connection between the pins on the GPS module.
Now, I can't think of any more error possibilities and would appreciate any advice.
Try this simple program, if you see nothing from the GPS reverse the RX and TX pins.
#define RXpin 4 //this is the pin that the Arduino will use to receive data from the GPS
#define TXpin 3 //this is the pin that the Arduino can use to send data (commands) to the GPS - not used
#include <SoftwareSerial.h>
SoftwareSerial GPS(RXpin, TXpin);
void loop()
{
while (GPS.available())
{
Serial.write(GPS.read());
}
}
void setup()
{
GPS.begin(9600);
Serial.begin(115200);
Serial.println("GPS_Echo Starting");
}
Which controller are You using?
Note that the GPS is a 3.3 volt logic device. UNO, Mega, ... are 5 volt logic devices. Do not connect such a controller Tx to the GPS. It runs fine without it.
Please post the code You're trying. No IDE in the phone...
The GPS module is a u-blox NEO-6M-0-001.
The description I have says, among other things:
"When using with an microcontroller, you will need to connect 5V power and ground to the module. The NEO-6 device operates at 3.3V and the module includes a 3.3V regulator. It will not operate from 3.3V power.
Communication with the module is via the serial TX/RX lines. The TX of the module connects to the RX pin on the MCU and the RX pin on the module connects to the TX pin on the MCU. For basic operation which simply reads the data stream coming from the device, only the TX pin of the module needs to be connected to an RX pin on the MCU. This can be a direct connection whether the MCU is 3.3V or 5V.
If you want to configure the module by writing to it, the RX pin can also be connected. If using with a 3.3V MCU, this can be a direct connection, but if using with a 5V MCU, a level shifter must be used to avoid possible damage to the module."
The last paragraph: Isn't that what you are saying?
I do not plan to write to the GPS module and so I should not connect the Arduino pin 3 (used as TX) to the GPS module's RX pin. Right?
Here is the code taken from Arduino IDE; Examples.
I changed:
Serial.begin(115200);
to Serial.begin(9600);
to not get crap on the Serial Monitor.
/Niels
#include <TinyGPSPlus.h>
#include <SoftwareSerial.h>
/*
This sample sketch demonstrates the normal use of a TinyGPSPlus (TinyGPSPlus) object.
It requires the use of SoftwareSerial, and assumes that you have a
4800-baud serial GPS device hooked up on pins 4(rx) and 3(tx).
*/
static const int RXPin = 4, TXPin = 3;
static const uint32_t GPSBaud = 4800;
// The TinyGPSPlus object
TinyGPSPlus gps;
// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);
void setup() {
Serial.begin(115200);
ss.begin(GPSBaud);
Serial.println(F("DeviceExample.ino"));
Serial.println(F("A simple demonstration of TinyGPSPlus with an attached GPS module"));
Serial.print(F("Testing TinyGPSPlus library v. ")); Serial.println(TinyGPSPlus::libraryVersion());
Serial.println(F("by Mikal Hart"));
Serial.println();
}
void loop() {
// This sketch displays information every time a new sentence is correctly encoded.
while (ss.available() > 0) {
if (gps.encode(ss.read())) {
displayInfo();
}
}
if (millis() > 5000 && gps.charsProcessed() < 10) {
Serial.println(F("No GPS detected: check wiring."));
while(true);
}
}
void displayInfo() {
Serial.print(F("Location: "));
if (gps.location.isValid()) {
Serial.print(gps.location.lat(), 6);
Serial.print(F(","));
Serial.print(gps.location.lng(), 6);
} else {
Serial.print(F("INVALID"));
}
Serial.print(F(" Date/Time: "));
if (gps.date.isValid()) {
Serial.print(gps.date.month());
Serial.print(F("/"));
Serial.print(gps.date.day());
Serial.print(F("/"));
Serial.print(gps.date.year());
} else {
Serial.print(F("INVALID"));
}
Serial.print(F(" "));
if (gps.time.isValid()) {
if (gps.time.hour() < 10) Serial.print(F("0"));
Serial.print(gps.time.hour());
Serial.print(F(":"));
if (gps.time.minute() < 10) Serial.print(F("0"));
Serial.print(gps.time.minute());
Serial.print(F(":"));
if (gps.time.second() < 10) Serial.print(F("0"));
Serial.print(gps.time.second());
Serial.print(F("."));
if (gps.time.centisecond() < 10) Serial.print(F("0"));
Serial.print(gps.time.centisecond());
} else {
Serial.print(F("INVALID"));
}
Serial.println();
}
It would be better to set the serial monitor baud rate to 115200, instead of changing the sketch to 9600. Running both the GPS Rx and Serial at 9600 baud can lead to problems because of the delay introduced when the Serial transmit buffer is full.
Good!
You're not the first guy being tricked by the faulty baudrate. It looks like Chinese filosophy, upgrading the hardware but thinking the documentation is still good. Or the guy making the library died and couldn't keep up with the development...
Using the library function telling if data is changed can save display updates and less flickering.
It might have helped me if I had understood the program better.
I wonder where I can find descriptions of the methods that are performed internally in the TinyGPSplus library? So that I better understand what's going on in the sketch.