natti
Posts: 2
Joined: Wed Jan 09, 2013 10:01 pm
Location: Iceland

Reading GPS module via GPIO (uart?) pins

Wed Jan 09, 2013 10:08 pm

Hi,

I'm new to the raspberry (and micro-computer/controllers in generaly) world.
(My wife gave me a RPi for xmas.)

My main agenda is to learn how I can use the GPIO pins (with and without external boards).
So far I've managed to use the GPIO to turn on & off some leds, and read the input from a pir sensor.

I've also aquired a GPS module.
This one to be more specific: https://www.parallax.com/StoreSearchRes ... fault.aspx

I was hoping someone here could point me in the right direction on how I can connect this GPS-module to the Raspberry Pi?

If I understand the documentation correctly, there are only three pins on the GPS module I need to connect.
1(Ground), 2 (5V power) and 4(TX/Transmit)

Pins 1 and 2 I should be able to connect directly to the GND and 5V pins on the Raspberry.

Pin #4 is what I'm not sure about.
The documentation for the module says: "Communication: 3.3 V CMOS asynchronous serial @ 9600 baud default for microcontrollers,"
Without knowing how, my guess would be to use the "UART" on the Raspberry somehow?

Any thoughts?

(For the record, I'm using the Raspbian wheezy as recommended by the Raspberry download page.)

User avatar
scruss
Posts: 2898
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Reading GPS module via GPIO (uart?) pins

Wed Jan 09, 2013 10:36 pm

This shouldn't be too hard, but you will have to edit some system files. If you're not comfortable doing this, there are USB-Serial adapters that make this job less complex. I don't have one of these units, but I'm going from experience of serial devices and the UART ports, and interfacing a USB GPS.

First, you’ll need to edit your Raspberry Pi’s /boot/cmdline.txt and take out the part the part that reads:

Code: Select all

console=ttyAMA0,115200 kgdboc=ttyAMA0,115200
Note that this file should only contain one line, so be careful you don’t add extra line breaks or your Raspberry Pi won’t boot. Save the file and reboot your Raspberry Pi.

I think the wiring you'll want from this module would be:

Code: Select all

Raspberry Pi      GPS
================= =================
5V  (GPIO Pin  2) VCC
GND (GPIO Pin  6) GND
RXD (GPIO Pin 10) TXD
This will now mean that your GPS should be a 9600 baud device on the serial port /dev/ttyAMA0.

Serial GPSs are a bit dull; all they spit out is a bunch of NMEA text. If you want to test whether it's working, install the screen or minicom terminal programs, and then test it like (if you're using screen):

Code: Select all

screen /dev/ttyAMA0 9600
This should start scrolling some complex text staring with the characters $GPRMC or similar. If you know your rough location, you might recognize some of the numbers scrolling up the screen. (To quit screen, type Ctrl-A, then K. Yeah, I always forget how to do that.)

To actually do something with your GPS, you probably want to install the gps system daemon GPSD. It install as bunch of system programs that make your Linux system aware of location. It may automatically pick up that there's a GPS on /dev/ttyAMA0; it's quite good at autosensing.

(one thing you might have to be aware of is that GPSs don't start sending position information until they've got a clear sky view. You might have to move this setup or its antenna near a window for anything to happen at all.)
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

natti
Posts: 2
Joined: Wed Jan 09, 2013 10:01 pm
Location: Iceland

Re: Reading GPS module via GPIO (uart?) pins

Thu Jan 10, 2013 8:26 pm

Hi,

Thanks for the help, this (almost) worked.

The only additional thing I needed was to comment out the following line from /etc/inittab

Code: Select all

T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
Now I get a bunch of data that's somewhat what I was expecting.

Thanks.

repton
Posts: 91
Joined: Sat Mar 17, 2012 6:06 pm
Location: North Yorkshire, UK.
Contact: Website

Re: Reading GPS module via GPIO (uart?) pins

Thu Jan 10, 2013 8:40 pm

Be VERY careful when doing this that you don't damage your RasPi. The GPIO UART port runs at 3.3V and is supposedly NOT 5V tolerant, and it sounds like your module is talking to it at 5V.

Maybe a simple 2 resistor voltage divider between the two would work?

Paul
UK Supplier of 1-Wire components, kits and modules:
http://www.sheepwalkelectronics.co.uk/

User avatar
scruss
Posts: 2898
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Reading GPS module via GPIO (uart?) pins

Thu Jan 10, 2013 9:36 pm

Though the unit takes 5V power, it lists 3V3 logic levels in the specs.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

cabe
Posts: 24
Joined: Sun Jan 08, 2012 2:54 pm

Re: Reading GPS module via GPIO (uart?) pins

Wed Apr 17, 2013 5:28 pm

With the help of this guide I managed to get my serial GPS unit to start spitting out GPS NMEA sentences to the terminal.

The issue is it is a 4800 baud device, which I can open with ttylog or screen, this seems to "set" the baudrate. I can then do cat /dev/ttyAMA0 >> log.txt Until reboot at least.

My cunning plan is to use the Pi as a car black box (along with a I2C 6DOF) so my next task is to make it do it from boot.

I thought I had it with screen but it doesn't seem to want to log the session its self.

screen -m -d -L /dev/ttyAMA0 4800

Any pointers in the right direction would be great, I dont need the GUI at this stage, I might pretty it up later.

User avatar
scruss
Posts: 2898
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Reading GPS module via GPIO (uart?) pins

Sun Apr 21, 2013 8:24 pm

cabe wrote:Any pointers in the right direction would be great
This is really what GPSD is for. Install it, it will start from boot, then you can use a client (like this simple Python example: » Getting GPSd to work with Python and Threading | Things I've Figured Out) to poll it.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

cabe
Posts: 24
Joined: Sun Jan 08, 2012 2:54 pm

Re: Reading GPS module via GPIO (uart?) pins

Wed Apr 24, 2013 1:03 pm

Sounds good, I shall investigate when I get back to my electronics bench this weekend. It looks like it might do some of the processing I was intending to do in the future.

User avatar
topguy
Posts: 6288
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Reading GPS module via GPIO (uart?) pins

Wed Apr 24, 2013 1:44 pm

Code: Select all

stty -F /dev/ttyAMA0 4800


This command should also just change the speed of the serial port and nothing else.

gauravsharma0190
Posts: 125
Joined: Tue Oct 28, 2014 6:36 am

Re: Reading GPS module via GPIO (uart?) pins

Tue Nov 25, 2014 7:28 am

hello sir
i want also interface the gps module with my raspberry pi...with wiringPi library..
i power Raspberry pi and gps module individually with 5 volts and here is a code

Code: Select all

#include<stdio.h>
#include<errno.h>
#include<wiringPi.h>
#include<string.h>
#include<wiringSerial.h>
int main()
{
char gps[65];   //gps string array
int fd, flag;    //handler
char arr[]="$GPGGA";
printf("raspberry gps programme");
if(wiringPiSetup()<0)     //setup wiring pi
return -1;
else
printf("setup is ok\n");
while(1)
{
int i=0;
if((fd=serialOpen("/dev/ttyAMA0",9600))<0)
{
fprintf(stderr,"unable to open serial device%s\n",strerror(errno));
}
else
{
printf("serial UART is Ok\n");
}
if(serialGetchar(fd)==13)
{
for(i=0;i<6;i++)
{
if(serialGetchar(fd)==arr[i])
flag++;
}
}
if(flag==5)
{
for(i=0;i<=65;i++)
gps[i]=serialGetchar(fd);
}
serialClose(fd);
flag=0;
printf("%s",gps);
}
fflush(fd);
}
[code/]
but there is no output on Terminal.
what's wrong with it.

Return to “Interfacing (DSI, CSI, I2C, etc.)”