Gps Tracker Full Project

42
The Open GPS Tracker is a small device which plugs into a $20 prepaid mobile phone to make a GPS tracker. The Tracker responds to text message commands, detects motion, and sends you its exact position, ready for Google Maps or your mapping software. The Tracker firmware is open source and user-customizable. The current supported hardware platform is: * Tyco Electronics A1035D GPS module * Motorola C168i AT&T GoPhone prepaid mobile phone * Atmel ATTINY84-20PU AVR microcontroller Project requires no interface chips! All you need is a GPS module, a phone, an ATTINY84, a voltage regulator, a PNP transistor, and a few passive components. This is a commercial grade tracker and is currently a second-generation stable beta V0.17. This version stores messages while out of GSM coverage, and forwards them when it regains coverage.

Transcript of Gps Tracker Full Project

Page 1: Gps Tracker Full Project

The Open GPS Tracker is a small device which plugs into a $20 prepaid mobile phone to make a GPS tracker. The Tracker responds to text message commands, detects motion, and sends you its exact position, ready for Google Maps or your mapping software. The Tracker firmware is open source and user-customizable.

The current supported hardware platform is:

* Tyco Electronics A1035D GPS module* Motorola C168i AT&T GoPhone prepaid mobile phone* Atmel ATTINY84-20PU AVR microcontroller

Project requires no interface chips! All you need is a GPS module, a phone, an ATTINY84, a voltage regulator, a PNP transistor, and a few passive components. This is a commercial grade tracker and is currently a second-generation stable beta V0.17.

This version stores messages while out of GSM coverage, and forwards them when it regains coverage. 

Page 2: Gps Tracker Full Project

 

Page 3: Gps Tracker Full Project

Introduction

Welcome to the Open GPS Tracker site. The Open GPS Tracker is a small device which

plugs into a $20 prepaid mobile phone to make a GPS tracker. The Tracker responds to text message commands, detects motion, and sends you its exact position, ready for Google Maps or your mapping software. The Tracker firmware is open source and user-customizable.

Project status: Current build is 0.17 assembled 04/24/2008We currently have second-generation stable firmware and a reference hardware design. All parts are available from Mouser Electronics, and the phone is available from Target, Walmart, or Radio Shack. This site provides the firmware with source code, theory of operation, parts list, and exact assembly and checkout instructions. If you can solder, this is a one-sitting project. No PC board or surface-mount capability is required.

Programmed parts will be available as soon as the firmware is out of beta. We intend to have kits and assembled units available for purchase shortly thereafter. Commercial products are planned, but the firmware will remain open source.

The current supported hardware platform is:

Tyco Electronics A1035D GPS module Motorola C168i AT&T GoPhone prepaid mobile phone Atmel ATTINY84-20PU AVR microcontroller

We intend to support more phones and GPS devices in the future.The Tracker's features are competitive with, or better than, many commercial products:

SiRFstar III receiver gets a fix inside most buildings. Sends latitude, longitude, altitude, speed, course, date, and

time. Sends to any SMS-capable mobile phone, or any email address. Battery life up to 14 days, limited by mobile phone. Longer life

possible with external batteries. GoPhone costs $10 per month for 1000 messages per month. Configurable over-the-air via text message commands. Password security and unique identifier.

Page 4: Gps Tracker Full Project

Manual locate and automatic tracking modes controlled via text message.

Automatic tracking mode sends location when the tracker starts moving,when it stops moving, and at programmable intervals while moving.

Alerts when user-set speed limit is exceeded. Retains tracking messages if out of coverage, and sends when

back in coverage. Retains and reports last good fix if it loses GPS coverage. Remote reporting of mobile phone battery and signal status. Extended runtime mode switches phone on and off to save

battery life. Watchdog timer prevents device lockup. Firmware is user-customizable with a $35.91 programmer

and free software.

In addition to being a GPS tracker, the firmware is easily modified to monitor and control anything from a weather station to a vending machine via text messaging. Please contact me for custom development.

Contact email: mike <at> opengpstracker <dot> org or use the forum. 

 

How to build the Open GPS Tracker

The tracker is easy to build on a perfboard. I used a basic one-pad-per-hole perfboard

and 26-gauge wire, but 30-gauge would probably be better. All the electronic parts are available from Mouser Electronics. Radio Shack sells the perfboard and the 2.5mm plug for the phone. You could also buy these from Mouser.

If you are building a tracker, please post in the user forum. I am looking for bug reports, pictures, and information about how the tracker works for you. I will provide technical support to people who are building units.

The Mouser Electronics (http://www.mouser.com) order is listed below. This order includes an AVRISP2, which you may not need if you already have an AVR programmer. I've included two each of all the small parts, and three of the GPS module connectors. This connector is the only tricky part of the build. It is easy to ruin one, as I did. For testing, you can just insert the 26-

Page 5: Gps Tracker Full Project

gauge wire into the socket on the GPS module, but for permanent assembly you need the connector. The connector has one extra pair of pins, which you should cut off. You will be soldering to the long side and plugging the short side into the GPS unit.

You need to solder to four pins on the GPS header, three of which are right next to each other. Clamp the header with a small vice or a "third hand" clip. Bend the wire into a loop with pliers and attach it to the pin, then carefully solder it. I solder pin 3 and pins 7 and 11 first, putting the wires down low near the plastic separator, then solder pin 9 with the wire up high away from pins 7 and 11. Check for shorts with a meter.

 

 

I superglued the IC socket and the two rows of three pins for the programming port, then wired those together and installed the rest of the components. Put the 0.1uF capacitor right next to the IC socket. The GPS module is attached to the board with 2-32 size screws, nuts, lock washers, and 1/4 inch spacers, which are not quite long enough. Get 3/8 inch spacers if you mount it this way.

 

Mouser Part # Description Quantity Price Each

556-ATTINY84-20PU Atmel AVR microcontroller 2 $2.90

827-AME8811AEATZ 3.3 volt regulator 2 $0.69

522-ZTX1151A PNP transistor with low saturation voltage 2 $1.51

581-SA105E104M 0.1 uF ceramic capacitor 10 $0.08

581-TAP106K006SCS 10 uF tantalum capacitor 4 $0.50

Page 6: Gps Tracker Full Project

855-M50-3501242 1.27mm M50 connector for GPS device 3 $1.45

171-0025-EX 2.5mm stereo plug for phone 2 $1.35

571-1-390261-3 or571-26415994

14 pin IC socket 2 $0.15

604-WP937EGW Two-color red/gren LED 2 $0.34

604-WP132XID Red LED 2 $0.12

660MF1/4DC3321F Resistor 3.32K ohm 5 $0.03

660MF1/4DC4700F Resistor 470 ohm 5 $0.03

755-1N4148T-77 Switching diode 5 $0.03

12BH431-GR 3 AAA battery holder 1 $0.89

571-41032390 Pin header 40-pin breakaway 1 $1.57

340-V23993-A1035D Tyco GPS receiver module 1 $61.50

556-ATAVRISP2 AVRISP2 USB AVR programmer 1 $35.91

Microcontroller schematic (scanned from notes)

 

Page 7: Gps Tracker Full Project

Power supply schematic for 4.5V battery

Page 8: Gps Tracker Full Project

Programming plug

GPS module socket, module facing antenna down

Page 9: Gps Tracker Full Project

Checkout process

When you finish building the project, perform these checks. This will prevent destruction of components and verify that the circuit is built correctly.

Unpowered checks with no batteries, MCU, phone, or GPS installed:

Check continuity from the negative battery terminal to MCU pin 14, phone jack ground, regulator center pin, and GPS header pin 9.

Check continuity from the positive battery terminal to the input pin of the regulator.

Check continuity from MCU pin 1 to the output of the regulator. Check for shorts between all adjacent pins of the MCU,

programming header, phone jack, and GPS module. There should be no continuity between any adjacent pins.

Check continuity from each pin of the programming header to the corresponding MCU pin.

Check continuity from each pin of the phone jack to the corresponding MCU pin.

Page 10: Gps Tracker Full Project

Check continuity from pin 3 of the GPS header to pin 11 of the MCU.

Place the GPS header over the GPS module and make sure you have wired the right pins.The plug is very small and mistakes here are expensive. All the wires should be on the inside row of pins, closer to the metal shield. No wires should be on the outside row closer to the edge of the GPS module.

Powered checks with batteries but no MCU, phone, or GPS installed:

Measure voltage between pin 1 and pin 14 of the MCU socket. You should have 3.3V with pin 1 positive.

Measure voltage between pins 9 and 11 of the GPS header. You should have close to 3 volts with pin 11 positive.

Place a jumper between pins 5 and 14 on the MCU socket. The red "GPS active" LED should light.

With the jumper in place, measure voltage between pins 7 and 9 of the GPS header. You should have 3.3V with pin 9 positive.

Remove the jumper, and place it between pins 1 and 2 of the MCU socket.

Place another jumper between pins 3 and 14 of the MCU socket. The two-color status LED should light red.If it lights green, it is installed backward and all status codes will be reversed in color.

 

Reading status codes

The two-color status LED blinks to provide status codes. Status codes are two-digit numbers which assist in debugging. The first digit is always shown in green, and the second digit in red. For example, one green blink followed by three red blinks is code 13. Three green blinks followed by two red blinks is code 32. The status codes are displayed one at a time from a queue, so the event that caused a status code may be over by the time the code is displayed.

Code Description

11 phone polled

12 send message failed

13 phone poll failed

14 no phone number defined

Page 11: Gps Tracker Full Project

21 invalid password

31 power on or reset

32 watchdog reset

33 eeprom initialized from defaults

34 remove jumper to reinit

 

Final checkout and setup

Remove one battery, install the Atmel MCU, and put the battery back in.

If your MCU is unprogrammed, connect the AVRISP2 to the computer and to the board via the programming header. Both lights in the AVRISP2 should be green.

Download the appropriate HEX file for the units (feet, meters, MPH, KPH) you want from the Download link at the top of this page.

Program and verify the MCU using AVR Studio or other PC software.

The status LED will begin blinking shortly after the programming completes. With no phone attached, you should get codes 31 (power on or reset), 11 (polling phone), and 13 (phone poll failed.) A freshly programmed chip will also display code 33 (EEPROM initialized) once.

Charge the Motorola C168i mobile phone. Install the SIM card and activate the prepaid service using the instructions included. Call the interactive voice response system at 1-800-901-9878 and activate a messaging plan (200 messages for $5.00, keywords: buy features, messaging, 200, yes, buy it) to avoid being charged 15 cents per message. You should be able to send and receive SMS messages from the phone keypad.

Configure the phone for short (10 second) display backlight (Settings, Initial Setup, Backlight, 10 seconds.)

Set the phone to silent mode (Settings, Ring Styles, Style, Silent.)

Set message delivery to Phone first (Message, Options, Memory Meter, Select SMS Memory, Phone First.) If you do not do this, Powersave mode will not work!

Remove a battery from the tracker's battery pack. Connect the Tyco GPS unit to the header, checking against the diagram to make sure it is plugged in correctly.

Page 12: Gps Tracker Full Project

Install the removed GPS battery, and then plug the 2.5mm plug into the mobile phone's headphone jack. The headphone jack is also the data port on this phone.

You should get code 11 (polling phone) but no code 13 (poll failed.) If so, your microcontroller is communicating with the phone.

If you get code 13, reset the microcontroller by momentarily shorting pins 5 and 6 on the programming header. If you still get code 13, unplug the phone and power cycle it.

Removing the GPS battery with the phone connected is not recommended, and will not reset the microcontroller. The phone will partially power the microcontroller through the output line and a protection diode in the chip.

When you get code 11, and no code 13, your unit is ready for setup.

Please post to the user forum. I want to hear about working trackers, and will provide support for anyone having trouble with one.

Setting the reply address

The GPS tracker stores a reply address, and always sends messages to the reply address. It does not care where the messages come from, because messages sent from email do not include the From address (using AT&T GoPhone service.) The reply address can be a mobile phone number or an email address. Regardless of where commands are sent from, replies go to the reply address.

To set the reply address to a mobile phone number, use a mobile phone to send a text message to the tracker's phone number:GPS SETADDRESS 8185551212where 8185551212 is the mobile number you want tracker messages sent to. The "GPS" must be uppercase. The SETADDRESS can be upper or lower case. After sending the message, the tracker's phone display should light, the tracker status light should blink code 11, and you should receive a reply saying "COMMAND EXECUTED".

To set the reply address to an email account, you need your carrier's Email Gateway number, which is a special phone number used to route text messages to an email account. For AT&T the Email Gateway number is 121. For other carriers, go into the phone's SMS settings (Messages, Options, Message Setup, Text Messages, Email Gateway) and look up the Email Gateway number. Send a text message to the tracker:GPS SETADDRESS 121 [email protected]

Page 13: Gps Tracker Full Project

where "GPS" is in uppercase, 121 is the Email Gateway, and [email protected] is the email address. For AT&T service, you can send an email to [email protected] ([email protected]) to send a text message. For other carriers, you will have to look up the correct email address. The tracker will reply "COMMAND EXECUTED."

 

Requesting a locate

Once you have set your reply address, you can request a locate. Send the message:GPS LOCATEwhere GPS is in uppercase. The tracker's phone display will light, the status LED should blink code 11, and the GPS power LED should come on. For the first locate, it will usually stay on for a minute or more. When the GPS light goes out, the status LED will blink code 11 again, and you should receive a reply:LOCATE POS 34 05.8779 N 118 20.6368 W ALT 377 FT SPEED 0.0 MPH COURSE 11.05 AT 08/04/05 22:31:51 UTC SATS 04This is a location report from the tracker. The fields are:

LOCATE - the report is the result of a manual locate request. There are other types of reports in tracking mode.

POS 34 05.8779 N 118 20.6368 W - latitude and longitude in degrees and decimal minutes. You can type or paste everything after POS right into Google Maps (http://maps.google.com) to see a map or satellite view of the location.

ALT 377 FT - measured GPS altitude, only accurate for 4 or more satellites (see below)

SPEED 0.0 MPH - speed of the GPS unit when the fix was taken. A unit sitting still often reports up to 2 mph.

COURSE 11.05 - course in degrees if the unit was moving AT 08/04/05 22:31:51 UTC Year, month, day, hour, minute,

second Universal Coordinated Time that the fix was taken SATS 04 - number of satellites providing the fix. Four or more

indicates a 3D fix (altitude valid) while three satellites indicates a less-accurate 2D fix.

If you get a valid location report, your tracker works. If you get "GPS TIMED OUT WAITING FOR FIX" the tracker is not in GPS coverage. Although the A1035 gets a fix inside most buildings, steel construction can block the signal. Take the device outside and try again.

Page 14: Gps Tracker Full Project

If you get "NO DATASTREAM FROM GPS DEVICE" your GPS module is not sending any data to the microcontroller. Check for faulty connections and verify that power is applied to the GPS module when the GPS power LED is lit. Dead GPS batteries can also cause this error, since the microcontroller needs less power than the GPS module.

 

Securing your tracker

The "GPS" prefix you have been putting before commands is actually a default password. You can and should change it. Anyone who knows your password can change it and take control of the tracker. Unlike commands, the password is case sensitive. To change it, send a text message like:GPS SETPASSWORD newpass newpassWhere "newpass" is the new password you want to set. It must be between three and sixteen characters, and must be repeated twice after SETPASSWORD. You should get back "PASSWORD CHANGED." You would then have to send "newpass LOCATE" to request a locate, for example. If you lose your password, you need physical access to the tracker to clear the configuration (see the command reference.) Messages sent without the correct password will be ignored.

 

Other things the tracker can do

So far you have seen the normal mode, in which the tracker replies immediately to requests. The tracker has two other modes: tracking and powersave.

In tracking mode, the tracker automatically takes GPS fixes, and sends you a message when it starts moving, when it stops moving, when it goes out of GPS coverage, and periodically while it is moving. You can plot the fixes on Google Maps or a similar service to follow the tracker's movements. You can configure how often the tracker takes a fix and how often it alerts you. You can also set a speed limit and receive an alert if it is exceeded.

In powersave mode, the tracker turns the phone power on and off periodically, allowing the phone battery to last longer than its typical standby time. For example, the phone may be off for an hour and on for ten minutes. In this case, it can take up to an hour for the tracker to reply to messages. You can remotely take the tracker out of powersave mode when

Page 15: Gps Tracker Full Project

you need location reports. Tracking and powersave modes are mutually exclusive; setting one mode clears the other.

The tracker has several configurable options, and a status command that reports the current settings, the phone battery status, the phone signal strength, and the firmware revision. You can set a name which will be prefixed to all tracker replies, so several trackers can report to the same destination. See the command reference for details.

 

Commands for build 0.17

Commands are sent to the tracker as SMS messages (not EMS/MMS/picture messaging.) All commands must be prefaced by the correct password, or they will be ignored without reply. One command per message. Commands can be upper or lower case, but passwords are case sensitive. All time values are approximate, because the tracker uses a fairly inaccurate clock. Timing values are intended to adjust power versus tracking resolution, not for precise timekeeping. Units of measurement for speed and altitude are set when the firmware is assembled, and cannot be changed without an AVR programmer.

Click here for old Build 0.14 commands

SETADDRESS phone-number optional-email-addressSets the reply address. Phone-number is sent as the destination in the SMS message, and can be up to 32 digits. Email-address is prefixed to the message, and can be up to 64 characters. To send to a mobile phone, provide only the phone number. To send to an email address, provide the Email Gateway as the phone number, followed by a space and the email address. The Email Gateway for AT&T is 121.

LOCATERequests an immediate location report from the tracker. Tracking mode also generates location reports. In POWERSAVE mode, the locate will not occur until the next power-on interval.Example location report:LOCATE POS 34 05.8779 N 118 20.6368 W ALT 377 FT SPEED 0.0 MPH COURSE 11.05 AT 08/04/05 22:31:51 UTC SATS 04 

LOCATE - event that caused the report to be sent. POS 34 05.8779 N 118 20.6368 W - latitude and longitude in

degrees and decimal minutes. You can type or paste everything

Page 16: Gps Tracker Full Project

after POS right into Google Maps (http://maps.google.com) to see a map or satellite view of the location.

ALT 377 FT - measured GPS altitude, only accurate for four or more satellites (see below)

SPEED 0.0 MPH - speed of the GPS unit when the fix was taken. A unit sitting still often reports up to 2 mph.

COURSE 11.05 - course in degrees if the unit was moving AT 08/04/05 22:31:51 UTC Year, month, day, hour, minute,

second Universal Coordinated Time that the fix was taken. This is satellite time and is accurate.

SATS 04 - number of satellites providing the fix. Four or more indicates a 3D fix (altitude valid) while three satellites indicates a less-accurate 2D fix. 

Report causes (first parameter of location report) - all but LOCATE and timeout are tracking mode only. 

LOCATE - manual locate request. STARTED - the tracker has started moving. MOVING - the tracker was moving and continues moving. SPEEDING - the tracker is exceeding the speed limit (whether

started or previously moving.) STOPPED - the tracker was moving and has stopped for the

specified number of intervals. MOVED - the tracker was not moving when the fix was taken,

but has been displaced since the previous fix. Setting the minimum displacement too short will generate spurious MOVED reports.

GPS TIMED OUT WAITING FOR FIX, LAST GOOD FIX ... indicates the GPS receiver did not receive a valid satellite signal. Setting the fix wait too short will cause this error. The receiver needs at least 35 seconds, and often two minutes, to receive ephemeris if it has been off for over an hour. Steel and concrete buildings, including parking garages, block the signal. If the last good fix is all dashes, no valid fix was received since the tracker was powered up or rebooted.

NO DATASTREAM FROM GPS DEVICE indicates the GPS module is not sending data. This is likely either a loose connection or a dead GPS battery.

SALOCATE phone-number optional-email-addressSets the reply address and requests an immediate locate. The reply address remains changed to the new value. This is equivalent to SETADDRESS followed by LOCATE.

Page 17: Gps Tracker Full Project

SETPASSWORD new-password new-passwordChanges the tracker's password. The same password must be repeated twice. It is case sensitive. Range: 3-16 characters.

SETNAME tracker-nameSets an identifier up to 16 characters that will be prefixed before all messages. This is useful when many trackers are reporting to the same address. SETNAME with no value removes the identifier.

TRACKONActivates TRACKING mode, and takes the device out of POWERSAVE mode if set. The device will respond with a tracking report, and will send unsolicited reports based on its motion. Tracking mode uses a lot more power than normal mode.

TRACKOFFTakes the device out of TRACKING mode and puts it in NORMAL mode. This command also cancels POWERSAVE mode if set.

POWERSAVEActivates POWERSAVE mode and takes the device out of TRACKING mode if set. The device will immediately go off the air, and will not accept additional commands until the next power-on interval. Set message delivery to Phone First (Message, Options, Memory Meter, Select SMS Memory, Phone First.) If you do not do this, powersave mode will not work, and you will lose remote control of the device.

POWERONTakes the device out of POWERSAVE mode and puts it in NORMAL mode. This command also cancels TRACKING mode if set.

STATUSRequests the status page. The SETTRACK and SETPOWER commands also return a status page showing the new settings.Example status page:SPDLMT=0 STOPD=120/2 BLKD=600/2 MOVNG=120/5 PSV=3600/600 3D/FIX/BLKD=72/136/96 MD/MS=200/20/100 BAT=78 SIG=19 WDR=0 V=0.17 Open GPS Tracker 

SPDLMT=0 Speed limit, or 0 if disabled. STOPD=120/2 Stopped fix interval and notify delay. BLKD=600/2 Blocked fix interval and notify delay. MOVNG=120/5 Moving fix interval and notify frequency. PSV=3600/600 Powersave on/off intervals.

Page 18: Gps Tracker Full Project

3D/FIX/BLKD=72/136/96 Four-satellite wait, fix wait, and blocked fix wait. Rounded down to a multiple of four seconds.

MD/MS=200/20/100 Moved report distance in 1/1000 of a minute of longitude/latitude. Minimum speed to treat as moving, in tenths of a unit. Minimum speed to accept on first report, in tenths of a unit.

BAT=78 Phone battery charge, reported by +CBC command. Range: 0-100

SIG=19 Phone signal strength, reported by +CSQ command. Range: 0-31 ?

WDR=0 Watchdog reset count. Should remain zero. If the count is nonzero, the processor hung and was restarted by protective hardware. The most likely cause is either a software fault or electrical interference. This should not happen, but I need to know about it if it does. Watchdog reset cancels tracking and powersave modes. Range: 0-255 and will not roll over from 255 to 0. Cleared by reboot.

V=0.17 Open GPS Tracker Tracker firmware revision.

SETSPEED <up to three parameters> 

1. Speed limit, in the same units used to report speed. If this speed is exceeded in tracking mode, the device sends a SPEEDING report. The first time the speed limit is exceeded, and each time the current fastest speed (above the limit) is exceeded, the device sends an immediate report. Otherwise, reports are sent at normal MOVING intervals, but with the tag SPEEDING. Current fastest speed is cleared by TRACKON. Range: 0-255, and 0 disables speed checking.

2. Minimum moving speed, in tenths of a speed unit. (20 = 2 speed units) Increase this to prevent spurious moving reports. Range: 0-255.

3. Minimum moving speed to accept on first fix, in tenths of a speed unit. Speeds between minimum moving speed and this setting are double-checked. Ranger: 0-255.

SETTRACK <up to seven parameters> 

1. Stopped fix interval, in seconds. Sets how often the device takes GPS fixes in tracking mode, while stopped and in GPS coverage. Range: 0-65535

2. Stopped notify delay, in fix intervals. This determines for how many fixes in a row the device must be stopped, before sending

Page 19: Gps Tracker Full Project

a stopped report and switching to the stopped fix interval. Range: 0-255

3. Blocked fix interval, in seconds. Sets how often the device attempts to take GPS fixes in tracking mode, and with no GPS coverage. Setting this too short can drain the GPS battery. Range: 0-65535

4. Blocked notify delay. This determines for how many fixes the device must be blocked, before sending a blocked report and switching to the blocked fix interval. Range: 0-255

5. Moving fix interval, in seconds. Sets how often the device takes GPS fixes in tracking mode, while moving. Range: 0-65535

6. Moving notify frequency. Sets how often, in moving fix intervals, the device sends a MOVING report. Range: 0-255

7. Minimum displacement for MOVED report. Sets how far the device must be displaced to send a MOVED report. 1000 means one minute of longitude/latitude. Setting this too short will cause spurious MOVED reports. Range: 0-65535

Example: SETTRACK 70 120 2 600 2 120 5 200Parameters not specified will be left unchanged. The command returns a STATUS report.Stopped and moving fix intervals can be set short without excessive battery drain, because the GPS module takes a fix in just a few seconds once it has ephemeris. Blocked fix interval should be set longer to prevent battery drain.

SETPOWER <up to five parameters> 

1. Powersave phone off interval, in seconds. Sets how long to leave the phone off for, when in POWERSAVE mode. The device will not respond to commands during this interval. Range: 0-65535

2. Powersave phone on interval, in seconds. Sets how long to leave the phone on for, when in POWERSAVE mode. The phone must stay on long enough to receive pending commands from the network. If this interval is set too short, you can lose remote control of the tracker, requiring a manual reset. Each incoming command restarts the power-on interval. Range: 0-65535

3. Four-satellite wait time, in seconds. Determines how long the tracker will wait for a four-satellite (3D) fix, before accepting a less accurate three-satellite (2D) fix. This should be less than fix wait time. Range: 0-1023, granularity 4 seconds.

4. Fix wait time, in seconds. Determines how long the tracker will wait for a fix before giving up and reporting a timeout. Range: 0-1023, granularity 4 seconds, lowest useful value is 64 seconds.

Page 20: Gps Tracker Full Project

5. Blocked fix wait time, in seconds. Determines how long the device will wait for a fix before giving up, while in blocked state. This can be set shorter than the fix time above to prevent battery drain when the tracker is blocked. Setting it too short causes the device to stay in blocked mode after it moves into coverage. Range: 0-1023, granularity 4 seconds.

Example: SETPOWER 3600 600 72 136 96Parameters not specified will be left unchanged. The command returns a STATUS report.

REBOOTReboots the tracker, and if phone rebooting is enabled in the firmware, also reboots the phone. This clears working memory but does not erase saved settings. Equivalent to shorting pins 5 and 6 on the programming connector, or unplugging the phone and removing the batteries.

REINITErases all settings and puts the device into "new chip" state. This wipes out the reply address and password, so the next command must be GPS SETADDRESS. Equivalent to the hardware reinit procedure. Also reboots the phone if phone rebooting is enabled in firmware.

Hardware reinitThis manual procedure erases all settings if you are unable to communicate with the device over the air (usually because you lost the password.) Make sure you are electrically grounded to prevent static damage. You need a jumper of the type used on CD-ROM and hard drives to set master/slave modes. Put the jumper between pins 3 and 4 (middle two pins) on the programming header (bridge MCU pins 7 and 9.) Reboot the device by either applying power with no phone attached, or momentarily shorting pins 5 and 6 on the programming header.

The status LED should blink code 34. When it stops blinking, remove the jumper. The LED will now blink 33 and 31. The device is cleared and ready for a GPS SETADDRESS. The clearing occurs when you remove the jumper.

Status codes - first digit blinks green, second digit blinks red. 

Code Description

11 phone polled

12 send message failed

13 phone poll failed

Page 21: Gps Tracker Full Project

14 no phone number defined

21 invalid password

31 power on or reset

32 watchdog reset

33 eeprom initialized from defaults

34 remove jumper to reinit

 

Open GPS Tracker: how it works and how to modify it

Too many open source projects give you a pile of code with no explanation. That makes it difficult for newcomers to work on the code. This page will explain how the Tracker works, from general principles to a walkthrough of the source code.

 

GPS and the Tyco A1035 receiver

Wave energy, such as sound, radio signals, and light, travels at a known speed in a known medium. This allows measurement of distance to the energy source by measuring the time required for the signal to arrive.

Suppose you have a long straight track, like a dragstrip or a runway. Put a speaker at each end of the track, a known distance apart. Simultaneously at regular intervals, each speaker generates a short tick. By comparing the arrival times of the ticks, you can find your position along the track.

If you hear the left speaker's tick two units before the right speaker, then you are one unit to the left of center. If you hear the right speaker's tick four units before the left speaker, you are two units to the right of center.

You can also determine the exact time the sounds were sent. If it takes ten units of time for sound to go from one speaker to the other, and you are two units to the right of center, there are three more units of time to the right speaker, so the sound was sent three units of time before you heard the right speaker tick.

This is the trivial one-dimensional case: with two speakers you can solve for one spatial dimension plus time. With three speakers (arranged in a triangle, for example) and more complex math, you can solve for two spatial

Page 22: Gps Tracker Full Project

dimensions plus time. And with four speakers, you can find your position in three-dimensional space.

In GPS, the "speakers" are satellites sending radio signals. All the satellites send on the same channel using spread-spectrum techniques, so one radio receiver can receive all the satellites in view, and a chip can sort out the signals. When you read about a "20-channel" GPS, like the A1035 used in the Tracker, it only has one radio. It has 20 decoder channels on the chip, so it can listen to 20 satellites at the same time. If at least four satellites are in view, the GPS receiver can solve for your position in three-dimensional space. With only three satellites, the receiver can get an approximate two-dimensional fix by essentially assuming you are close to the ground relative to the satellites.

In order to find your position, the receiver needs to know exactly where the satellites are. Each satellite transmits its position, called ephemeris, every 30 seconds in a continuous loop. The ephemeris is good for one hour. If the GPS has been off for an hour, it will take at least 30 seconds to get a fix. If the signal drops out, and a few bits are lost, you have to wait another 30 seconds for the data to repeat. So the first fix takes some multiple of 30 seconds. Additional fixes arrive one per second.

The A1035 receiver used in this project is one of the best GPS modules available, but it stil requires a substantial amount of battery power - around 50 ma at 3.3V. It has a microwave radio and a CPU faster than the AVR microcontroller. Leaving the module on would drain the battery in a few hours. The Tracker uses a PNP transistor to switch the module's power on and off. When off, the module retains its ephemeris data in static RAM, powered by the Vbak wire and the diode. The Tracker can switch the GPS on, get a fix within a few seconds, and switch it off again. After an hour, the ephemeris expires and there will be another 30-second or longer delay.

The A1035 outputs serial data at 4800 bps. This is similar to a PC's serial port but inverted and at a lower voltage. You can connect the A1035 to a PC using a MAX3232 chip as explained under Development below. The format, called NMEA, is a continuous stream of comma-delimited ASCII lines. The receiver starts outputting as soon as you apply power, although no position numbers appear until it obtains a valid fix.

Other GPSes should also work. I interfaced a Garmin ETrex Vista to the development board through a MAX3232 chip and it worked fine.

Tyco A1035 short datasheet PDFTyco A1035 long datasheet PDFTyco A1035 firmware/NMEA PDF

Page 23: Gps Tracker Full Project

 

Short Message Service and the Motorola C168i phone

The GSM wireless standard includes SMS, more commonly known as text messaging. SMS sends 160-byte messages between mobile phones. The network will store and forward messages for a phone which is off or out of coverage. There is a standard set of commands, based on the old Hayes AT command set, for sending and receiving SMS under program control.

SMS is designed to communicate between phones. To send email from SMS, you send to an email gateway, and prefix the email address before your message. Long email addresses limit the length of the message you can send. SMS coming in from email comes from a random-looking number, with no reliable way to reply to it. This requires the Tracker to have a preset reply address, rather than parsing each incoming message and figuring out the reply address.

Most mobile phones today have USB interfaces on proprietary connectors. GSM modules are available with serial interfaces, but they are expensive. The C168i is a welcome exception - a $20 phone with a serial interface on a standard 2.5mm headset jack. The serial interface is CMOS level like the A1035, and can be connected directly to a microcontroller. It can also be connected to a PC with a MAX3232 chip.

The C168i is perfect for microcontroller interfacing, but GoPhone service has a few downsides. One is that it sends a "balance remaining" message to the phone after every message. Some phones, like the Samsung A437, can be set to ignore this, but the C168i cannot. The messages accumulate but appear to cause no harm. To prevent this and other memory leaks, the microcontroller reboots the phone periodically using the AT*SWRESET command. This can be disabled with a #define directive in the program.

Another nuisance is the annoying voice response system I have to use to buy the monthly SMS plan. Hopefully it will be available on the website soon.

The C168i can, in theory, be switched on and off by a +CFUN command. In practice, the +CFUN=0 command does a fine job of switching the transceiver off, but the +CFUN=1 command does not turn it back on. Powersave mode currently uses the AT*SWRESET command to turn the phone back on. This can be changed to +CFUN=1 with a #define, for use with other phones.

Page 24: Gps Tracker Full Project

Other phones should work as long as they support AT commands on a serial interface. GSM modules should also work, but I don't have any to test.

 

Atmel ATTINY84 AVR microcontroller

The ATTINY84 is a small but complete computer in a 14-pin integrated circuit. It works well for this application because it has a self-contained clock accurate enough for serial communication, interrupt timers, and nonvolatile memory. The development tools are free and the programmer is cheap. The AVR requires only a battery to run. The board includes the standard 6-pin connector for programming AVR processors.

The Tracker need two serial ports, one for the phone and one for the GPS. The smallest AVR processor with two hardware UARTs is a 40-pin chip, so the Tracker uses software UARTs, setting programmable timers to clock bits in and out. This works fine as long as you only need to communicate with one device at a time.

The AVR can be put into a low-power stop mode and can wake itself up when a timer expires, or can be woken by external input from the phone receiving a SMS. The processor spends most of its time in this state, waking up only to process a message or take a GPS fix. The processor runs at 1MHz for 4800-baud communication. It could run at 8MHz, if you need faster serial I/O. All the timing values would have to be adjusted. There is a setting or "fuse" bit to select the speed.

ATTINY84 datasheet PDFAVR instruction set PDF

 

The circuit

The ATTINY84 runs fine on unregulated battery power, but the GPS module requires a 3.3 volt regulated power supply. The AME8811 is a good regulator for this device because it has a low dropout voltage, has a low standby current, and is available as a TO-92 leaded part. It needs the capacitors to stabilize it against oscillation.

The Tracker needs to switch the power to the module with a PNP transistor. The ZTX1151 is overkill, but I had some around and they have a low

Page 25: Gps Tracker Full Project

saturation voltage. There is also a two-color LED for status, another LED connected to the switched GPS power, and resistors for the LEDs and transistor base. That's all there is to the circuit.

AME8811 regulator datasheet PDFZTX1151 datasheet PDF

 

The program

 

The code is 5K bytes of assembly language, text strings, and control strings. There is a main program and four interrupts. The four interrupts are:

1. Timer 1 compare A: bit clock for serial send and receive. 2. Pin change interrupt 0: detects start bit of incoming byte. 3. Timer 0 overflow: four-per-second interrupt for countdown

timers and blink codes. 4. Watchdog timer overflow: wakes the processor from sleep

mode. Returns immediately, and is just used as a wakeup.

Serial receiver

 

There is a 256-byte serial receive buffer from 0x100 to 0x1ff in SRAM. The serial receiver is activated by the SERIAL_RECEIVE_ENABLE_FROM_{GPS,PHONE} functions. Once activated, the interrupt receives characters and adds them to the buffer at the position set by SERIAL_POINTER. The pin change interrupt detects a start bit, starts the Timer 1, and disables itself. The timer clocks the bits into SERIAL_DATA, writes the finished byte into RAM, increments the pointer, turns off the timer interrupt, and re-enables the pin change interrupt.

The main program calls GET_NEXT_CHAR after setting RECEIVE_TIMEOUT. GET_NEXT_CHAR returns a pending character, waits for a character, or returns with the T flag set if the receiver timed out. The Y pointer keeps track of the main program's position in the buffer. The program often saves the Y pointer, looks ahead, and then resets the Y pointer. Parsing of the buffer is done "live" while characters are coming in.

Page 26: Gps Tracker Full Project

This works fine as long as the main program stays ahead of the incoming data.

 

Serial transmitter

SERIAL_PORT selects the I/O line that will transmit data. Calling SERIAL_SEND_BYTE sends one character from SERIAL_DATA. Although the timer interrupt sends the bits, SERIAL_SEND_BYTE waits for completion before returning.

SERIAL_SEND_STRING_TO_PHONE is the string output function, and is analogous to printf() in C. It accepts a control string containing text and a series of special-function codes. The codes can insert SRAM or EEPROM fields, call substrings in program memory, or print numbers in decimal. All the special function codes are documented at the top of the function.

 

Text and numeric parsing

The functions for parsing text are BRANCH_ON_STRING, PARSE_NMEA_OR_COMMAND_LINE, and PARSE_DECIMAL. BRANCH_ON_STRING takes a control string giving a list of program addresses and strings, scans the input buffer for matching strings, and jumps to the corresponding program label. This is used to identify user commands, phone responses, and NMEA strings.

PARSE_NMEA_OR_COMMAND_LINE parses space or comma delimited fields into SRAM. The flag FLAG_PARSE_NMEA makes it handle the NMEA format with checksum, $ and * characters, and empty fields. With this flag clear, it parses command lines and phone responses. This function also accepts a control string to determine which fields to save and where in SRAM to save them. There is a 64-byte area in memory reused for all such parsing.

PARSE_DECIMAL reads a string containing a decimal number, and returns the 16-bit number. It is used to parse user input and NMEA values where these need to be processed numerically. There are options for integer or dot-one format.

Page 27: Gps Tracker Full Project

The GPS provides speed in knots and altitude in meters. We need to convert to other units (KPH, MPH, feet) and this is done by UNITS_CONVERT. The function multiplies a 16-bit number by a 16-bit conversion constant, keeping only the high-order 16 bits of the product. This scales the input down, so there are prefix entry points that double or quadruple the input before applying the constant.

All strings in SRAM and EEPROM are null-terminated and have a maximum field length. An eight-character field can hold eight characters of text, or if the string is shorter, it will be null-terminated.

 

GPS locate

The function GPS_LOCATE turns on the GPS module, receives serial data until it gets a valid fix or times out, and then turns off the GPS module and returns with the fix status. It will wait a (shorter) time for a 3D fix, then will wait a (longer) time for any fix including a 2D fix, and then will return failure if no fix is obtained. It parses the GPRMC and GPGGA sentences.

The function waits a preset number of lines after the first valid fix to allow the data to smooth out. It takes a second look if it gets a speed between 2 and 10 knots, or if it gets a position displaced more than MIN_DISPLACEMENT from the last good fix. Without this additional filtering, the tracker generated a lot of spurious MOVED and STARTED messages.

 

Phone operations

The function DO_PHONE_OPERATION takes a list of phone commands and runs them. Each command is null-terminated and there is a double null at the end of the last command. After each command, the function waits for a phone response and branches according to PHONE_MATCH_PATTERN. Each response has a handler, OK goes on to the next command, and ERROR retries from the beginning. Specific messages are sent using SEND_STRING_OFFSET_0.

Sleep mode

Page 28: Gps Tracker Full Project

When no commands are pending, the MCU goes into a sleep mode where it stops the processor and main oscillator. Only the watchdog timer continues to run. The MCU will be woken by either a watchdog timeout or a message from the phone. The phone is configured to send a message if it receives a SMS. This message is not actually parsed; it just wakes the MCU and the MCU then polls the phone. The poll interval depends on mode; in tracking mode it is configurable, and in normal mode it polls every 15 minutes if no messages are coming in.

 

Main loop

Repeat forever If tracking mode, Get a location fix. Decide on the basis of fix status and tracking state whether to send a tracking message. Update tracking state if it has changed. Poll the phone for incoming messages. If messages found, If not previous failures (CMGL_SAFETY_COUNT) Get first message. If password valid, Call message-handling function based on command. Delete first message. Set FLAG_NEED_TO_POLL_MESSAGES. else (no message found), Clear FLAG_NEED_TO_POLL_MESSAGES. If phone reset enabled and time to reset phone, Reset phone. Wait for it to come back online. Clear PHONE_RESET_COUNT. If callback command pending from message above, Execute the callback command. Clear the callback pointer. Wait for blink codes to finish. If FLAG_NEED_TO_POLL_MESSAGES set, Go to top of main loop. Sleep for POLL_INTERVAL or until interrupt wakes up. If wakeup was an interrupt, Set FLAG_NEED_TO_POLL_MESSAGES. Go to top of main loop. else (wakeup was timer expired) If in powersave and phone was off, Turn on the phone. Set state to waking up. Set the powersave waking up poll interval. Go to top of main loop. else if in powersave and phone was waking up, Set state to power on. Set the power on poll interval. Go to top of main loop.

Page 29: Gps Tracker Full Project

else if in powersave and phone was on, Turn off the phone. Set state to power off. Go back to sleep. else (not in powersave), Go to top of main loop.

Download firmware

The current build is 0.17, supporting the ATTINY84, Motorola C168i and Tyco A1035.Right-click the file and choose Save As...Note: if you are upgrading from build 0.14, you must change the phone configuration:Message/Options/Memory Meter/Select SMS Memory/Phone First

Intel hex firmware image, speed in MPH, altitude in feetIntel hex firmware image, speed in KPH, altitude in feetIntel hex firmware image, speed in KPH, altitude in metersSource code in AVRASM2 format

Old version - source code in AVRASM2 format

To assemble from source, you need AVR Studio 4, available here:http://www.atmel.com/dyn/products/tools_card.asp?tool_id=2725

Assembly command:"C:\Program Files\Atmel\AVR Tools\AvrAssembler2\avrasm2.exe" -fI -l OPENGPS_016.LST OPENGPS_016.ASM

 

Open GPS Tracker: modification and development

Level converter

The serial port on a PC uses high voltages (+/- 8 volts) with idle negative, start bit positive, and data inverted. CMOS level serial communication among the Tracker components is 0 - 3.3 volts, and inverted relative to a PC's serial port. To customize and debug the Tracker, you need a serial level converter. The chip is a MAX3232 (Mouser Part No. 511-ST3232EBN, 16-pin DIP, $3.15)

Page 30: Gps Tracker Full Project

MAX3232 Datasheet PDF

Install a 16-pin socket on a perfboard and attach the five capacitors as shown on the datasheet. The chip requires 3.3 volts in, and generates the high voltages using a charge pump. One chip provides two transmitters and two receivers, but you only need one each for most purposes. I installed screw terminals on mine for easy connection, and LEDs on the outputs of the MAX3232 chip. If I built another one, I would have multiple ground terminals to make it easier to connect everything.

Connect the RS232 side of the converter to your PC serial port. [give pinout] USB serial adapters work fine. Connect power to the converter, go into Hyperterminal or Minicom on the PC, and connect to the COM port directly. Use 4800 baud, 8, N, 1, no flow control. Type a few characters and nothing should appear. Now bridge the CMOS IN and OUT lines on the converter, and type again. Your characters should echo. If this works, the converter is good.

 

Connecting to the phone or GPS

If you connect the phone through the level converter, you can interact with the AT command interface. When trying to send AT commands manually, this phone suffers from character loss. At first I thought the AT interface is just broken on the C168i, but it works fine if you send a continuous data stream. It has a very short timeout before it stops listening, so you have to

Page 31: Gps Tracker Full Project

type fast and continuously. This is probably excessive power management in the phone. The Tracker frequently gets no response to its first ATE0, but the second attempt works.

Connecting the GPS to the level converter will display the NMEA strings. I used this to try out the GPS module. You can also use the level converter in reverse to interface an RS232-level GPS unit to the AVR microcontroller. I tried this with the Garmin ETrex Vista and the Tracker got a valid fix from it.

 

Enabling serial debug in the Tracker

Set the #define SERIAL_DEBUG in the Tracker source to enable debug output from PORTA7 (MCU pin 6.) Connect this pin through the level converter to the PC and start the microcontroller with debug firmware loaded. You should get a message "MACHINE STARTED IN DEBUG MODE" at 4800 baud. From there, the microcontroller will copy all phone interactions and responses to the PC. This is essential to debugging the phone interaction.

You can also load the microcontroller with non-debug firmware and "tap" the phone or GPS lines with the level converter. This will get you only one side of the phone interaction, but debug firmware runs slower and might work when production firmware does not.

Page 32: Gps Tracker Full Project

 

Adding a command

To add a new command, add an entry to COMMAND_MATCH_PATTERN with the command and address of a new function. Add the function to handle the command and parse any options. This function will be called while the serial I/O is still running and the command is in the buffer, so you cannot send a message directly from this function.

Parse your options into the PARSE_FIELDS area. To send a message, set the address of another function in COMMAND_PENDING. After the phone poll completes, your function will be called from MAIN and you can send a message. The MULTI_SEND functions send most messages.

 

Alternate uses for the program

The Tracker software can be modified to sense or control a variety of devices. You can easily add commands to turn output lines on and off, read

Page 33: Gps Tracker Full Project

input lines, measure voltages with the ADC, etc. If you need more I/O, the program could be ported to the ATTINY86 or ATMEGA88 devices.

 

Open GPS Tracker: Potential improvements

Done! Store unsent messages in the phone 

Report GPS battery condition

The status page currently shows the phone battery condition. It would be nice to also show the GPS battery condition. At first glance, this should be easy since the MCU has an ADC. The problem is, the battery voltage is higher than the regulated supply to the MCU. The MCU can only measure voltages up to its power supply voltage.

The obvious approach is to scale the battery voltage down with a voltage divider, but that uses current and so has to be switched. This "simple" approach requires three resistors and another transistor. Any voltage drop across the transistor degrades the measurement.

Another approach uses a zener diode or other calibrated voltage drop, a resistor, an output pin, and an analog input pin. Connect the zener from the battery to the input pin, and the resistor from the input pin to the output pin. Normally the output pin is high, and with a 2.1V zener, no current flows. Pull the output pin low, and the input pin will be 2.1V less than battery voltage, a maximum of 2.4V.

 

Handle the parking-garage problem

The Tracker can remain stopped in tracking mode, using a small amount of power, as long as it is in GPS coverage. It takes a fix every few minutes, each fix requiring only seconds of GPS on time, and reports as soon as it moves.

In a parking garage, out of coverage, tracking mode becomes expensive. The GPS has to stay on for about two minutes to be sure there is no

Page 34: Gps Tracker Full Project

coverage, burning over 1 milliamp-hour per check. The user may want to know immediately when the tracked vehicle leaves the garage, so he faces an unpleasant trade-off between quick response and battery life.

The ideal solution is a mercury switch or similar kinetic motion detector. Once the GPS reports blocked, the Tracker could go to sleep until it detects motion, using no power. Mouser does not sell mercury switches; they must be considered an environmental hazard. Some green alternative should be used instead.

 

Almanac and ephemeris refresh

GPS satellites send a longer file called Almanac that could improve the tracking precision. It allows the receiver to correct for atmospheric conditions. To receive Almanac you have to leave the GPS on for several minutes. Provide an option to leave the GPS on for a few minutes periodically to receive the almanac. How long and how often need to be worked out. 

Better power supply

The current power supply is a wasteful linear regulator. The production design should use a micropower boost switching regulator. This consists of a chip, an inductor, and some capacitors. In sleep mode, the regulator remains off and the MCU runs on battery power. When the MCU wakes up, it turns on the regulator, bringing the voltage up to 3.3 volts, and then enables the GPS. This design could run on two alkaline cells instead of three, or on rechargeable batteries. The design would require the ATTINY84-10 variant of the MCU, which works down to 1.8 volts. Mouser does not sell it, but DigiKey does.

For a very-long-life application, it could use D-cells or an expensive Tadiran 3.6V lithium battery, and recharge the mobile phone as needed. A GSM module could be used instead of a mobile phone.

 

Support other phones and GPSes

Page 35: Gps Tracker Full Project

Supporting other phones is easy if they provide a serial AT command set and the standard interface to SMS. I am not sure which ones do. The unlocked C139 should, but the Tracfone C139 does not work. I would like to try some GSM modules, but they are expensive and the C168i works fine for now.

Do any T-Mobile or even CDMA phones provide serial AT commands? The CDMA network has an advantage over the GSM network, in that GSM phones induce noise in nearby electronics. GSM radio transmissions are pulsed at an audio-frequency rate, so any diode will demodulate them into a nasty buzzing sound. My tracker buzzes through the car radio if I put it close to the radio. This is not exactly stealthy. CDMA does not have that problem.

The Antenova M10214-A is a possible alternative GPS module. It runs on 3.6V up to 5 volts and can switch itself on and off. It should last quite a while on a 3.6V Tadiran battery without a regulator. The required Molex connector is backordered until May. The connector looks tricky to solder to, and the device may come up in SiRF Binary mode, requiring a 57,600 bps transmission to switch it into NMEA mode. The interrupt-driven serial transmitter cannot run that fast, so a cycle-counted loop would have to be written.

First priority, before any of these improvements are made, is to get more Trackers out in the field and make sure the firmware is solid.