Ultimate GPS Adafruit

I am currently working on a GPS unit with the Electric imp. I am getting read out of -1 instead of any real coordinates. The information for the breakout board can be found here http://www.adafruit.com/products/746.

my code is as follows:
`
//Code below is for GPS P6H0171327
//GTPA013

function gpsData() {
local coor = hardware.uart57.read();
imp.sleep(1);
server.log(coor + " coor");
}

//Main Execution loop
function loop() {
//configure hardware
hardware.uart57.configure(9600, 8, PARITY_NONE, 1, NO_CTSRTS, gpsData);

//proof program is working
server.log(“Device Started”);

//do stuff
gpsData();

//Loop Activities - executed once every Wakeup
imp.wakeup(5.0, loop);
}

//Pause 5 Seconds before starting the main loop - adjust to taste
imp.wakeup(5.0, loop);
`

The Device log looks like this:

2014-02-19 17:28:18 UTC-6: [Device] Device Started
2014-02-19 17:28:18 UTC-6: [Device] getting here
2014-02-19 17:28:19 UTC-6: [Device] -1 coor

Does any one know how to read out the data from the GPS properly?

I started working with this board a few months ago… Does your GPS have a lock?

Do you mean has it found a satellite? It has been previously used and has found a signal and it is using a battery to keep information for warm starts.

I checked the document again on the Baud rate and it is 9600. However it is still reading out -1. Just in case it is a hardware issue… I have pin5 connected to TX, pin7 connected to RX, gnd to gnd, and 3v3 to 3v3 (the gps works 3.3 to 5v and is 5v tolerant)

`
gpsline<-"";
function gpsData() {
local b = hardware.uart57.read();
while(b != -1) {
if (b < 32) {
if (gpsline.len() > 0) server.log(“GPS line: “+gpsline);
gpsline=””;
} else {
gpsline += b.tochar();
}
b=hardware.uart57.read();
}
}

//Main Execution loop
function loop() {
//configure hardware
hardware.uart57.configure(9600, 8, PARITY_NONE, 1, NO_CTSRTS, gpsData);
//read out gps data
gpsData();
}

//Pause 5 Seconds before starting the main loop - adjust to taste
imp.wakeup(5.0, loop);
`

Thank you for the help. These forums are filled with so many helpful people.

You need to build up a whole line in the buffer before printing it, and don’t sleep in the handler either.

gpsline<-""; function gpsData() { local b = hardware.uart57.read(); while(b != -1) { if (b < 32) { if (gpsline.len() > 0) server.log("GPS line: "+gpsline); gpsline=""; } else { gpsline += b.tochar(); } b=hardware.uart57.read(); } }

…this code will collect a whole line, then log it. Most GPSes default to 4800bps in my experience too. Sure yours is 9600?

Also, you should not be re-calling the main function in a loop. This isn’t needed - just configure the UART and fall off the end of the code. The receive data callback will be started when data is available. (ie: remove the imp.wakeup in the function).

Pin 5 is TX from the imp. That should be connected to RX on the GPS (and vice versa). It sounds a bit like you have TX to TX and RX to RX?

You also do not need to call gpsData() - it will be called when data arrives. No data is arriving hence you are seeing -1 (though… you’re not seeing it with the above code as it builds a string)

Just curious … why would a GPS feature be useful with an Imp? The Imp is only good within a short distance with WiFi. I would really like to experiment with the Sparkfun GPS modules and such, but with the Imp?

If you have a really cool idea with your GPS, please post your project. I would like to play around with it.

Great question. The imp has the ability to save information in different ways i.e. a separate memory storage. So you could save the information and on the first chance the Imp gets to hook to wifi it could upload that information. Then you could say see your hike or bike ride. At least that’s my hope.

Hugo,
I see people post diagrams of their stuff. Where can I do that? Also maybe I’m confused about this link http://electricimp.com/docs/hardware/imp/pinmux/ because it says UARTs with pins5,7 go to TX,RX respectively. I know a UART LCD I used worked properly but it didn’t even use RX technically. I added if b = -1 in my own code and didn’t put that in my problem question. Thanks for all the help again.

Yep, the convention for serial is the output of the device is labelled TX and the input is labelled RX. This follows for the GPS too - you want the GPS transmissions to be received by the imp hence you connect the GPS TX pin to the imp RX pin.

The UART LCD likely only had one connection (an input) so you’d connect the imp TX to the UART LCD’s input.

Have you tried that wiring?

I took a look at the module on adafruit’s website and this is how you should wire it:

  • Imp GND to GPS GND
  • Imp VIN (assuming you are powering imp with USB) to GPS VIN
  • DO NOT CONNECT GPS 3.3 to imp 3.3! The GPS 3.3 is an OUTPUT, and not very high current. Leave this unconnected.
  • Imp TX to GPS RX
  • Imp RX to GPS TX
  • GPS EN can be left unconnected (it’s high to enable, but pulled high by default)
  • GPS VBAT unconnected (especially if you put a coin cell in there)
  • GPS PPS unconnected

I think the diagrams are from Fritzing. I’ve not used this myself, google it?

I suppose the logging idea with GPS and Imp would be a way to use it. Doesn’t a smart phone do that already?

The important thing about your project is learning how to make it work. The hardware connection challenge between the Imp and GPS (or any other hardware) is where you’ll gain a ton of knowledge. Any failures you encounter will be more beneficial than your final success … and for me, I learn the most by failing, and it smells so nice when I let the smoke out of the components. Some Tantalum Capacitors have purple smoke … I discovered that last weekend.

mlseim :slight_smile: so true. I am learning a lot mostly by failing! Also my phone doesn’t get very good service and the GPS last weekend stop working all together. I’m hoping this will work where my phone doesn’t.

Hugo thank you for all the help. I finally got it working. I thinking switching those pins helped.

`
//Code below is for GPS P6H0171327
//GTPA013 with pins5,7
gpsline<-"";
function gpsData() {
local b = hardware.uart57.read();

while(b != -1) {
if (b < 32) {
if (gpsline.len() > 0) server.log(“GPS line: “+gpsline);
gpsline=””;
} else {
gpsline += b.tochar();
}
b=hardware.uart57.read();
}
}

//Main Execution loop
function loop() {
//configure hardware
hardware.uart57.configure(9600, 8, PARITY_NONE, 1, NO_CTSRTS, gpsData);
//read out gps data
}

//Pause 5 Seconds before starting the main loop - adjust to taste
server.log(“Device On”);
imp.wakeup(5.0, loop);
`

http://eckama11.wordpress.com/2014/02/21/adafruit-ultimate-gps/