In this instalment we will continue to examine the use of our GPS system and Arduino through creating two more applications. Some of them may seem simple, but we will build on them later on to make more complex things. To review previous information, the first GPS instalment was chapter seventeen.
Example 19.1 – “Household official time”
At home we often have various discussions about what the actual time is. At first it sounds silly, but when you have clocks on the microwave, kitchen wall, a wristwatch, mobile phone, clock-radio, and so on – things can get a little out of hand. And my better half has all her clocks ten minutes fast. Insanity may prevail!
So let’s make a nice big LED-display reference clock – something that wouldn’t look out of place in a radio or television studio:
Then when people start arguing over the time, you can point at your new clock and smile. From a hardware perspective, we will combine three or four things: our Arduino board, our GPS system, and the MAX7219 display driver. We will need the following items:
- Arduino Uno or compatible board
- the GPS shield bundle
- Maxim MAX7219 display driver IC
- two four-digit, seven-segment LED displays (common cathode). You could also rig up four separate digits with some patience;
- one 1 kilo ohm resistor
- one 10 kilo ohm resistor
- one single pole, double-throw switch
- a nice breadboard and some connecting wire
- a separate 5V power supply – all those LED segments are thirsty, the completed clock uses under 350 milliamps with a brightness setting of 8:
Here is the schematic:
Although the sketch (download) may seem quite complex, it is just made up of things we have already examined in the past. The only unfamiliar part could be the MAX7219 display driver IC, which in itself is quite easy to use. There is a full part review and explanation here. It is most likely that everyone will have different LED display units, as the 4-digit modules can be hard to track for some people or too expensive – so some more explanation is in order.
You will need common-cathode display modules. If you line the digits up from left to right, they will be numbered zero to nine with respect to the MAX7219 – so connect MAX7219 pin 2 to the cathode of your first display, and so on. With regards to the anodes (a~g and dp [decimal point]) – link each anode type together.
For example, if you have eight separate 7-segment display modules, connect each ‘a’ pin together, then to MAX pin 14. And so on. Here is the board layout – a real mess:
And our action video:
An interesting twist you might find of interest is the function:
Which allows you to alter the brightness of the LED display(s). The range is 0 to 18 – in my examples it has been set to 8. You could then make your clock dim the display brightness between (for example) 11pm and 5am – so when you wake up in the middle of the night the display won’t act like a frickin’ laser-beam burning into your eyeballs. Furthermore, dropping the brightness reduces the power consumption.
Example 19.2 – “You went… where?”
Now it is time for what most of you have been waiting for – making a GPS tracking device. Now before you get too excited, it would be proper to make sure you have the permission of someone before you track them. From a hardware perspective this example is a lot easier that you think – it is just the Arduino board, GPS shield and microSD shield. You will need to install TinyGPS library if not already installed.
Then, we will need the following items:
- Arduino Uno or compatible board
- the GPS shield bundle
- microSD shield and a matching memory card up to 2GB in size
- portable power, for example an alkaline 9V PP3 battery and adaptor cable
Don’t forget to format the microSD card to FAT16 before use. Once power is applied, the system will take a position reading and write it to the microSD card every 30 seconds. You can alter this period by changing the value in the delay() function at the end of void getgps(TinyGPS &gps). The text file is closed after every write, so you can just turn it off when finished then take the memory card to the computer to copy the data.
Although the hardware wasn’t that interesting to plug together, what can be done with it and the data it captures is quite fascinating. To generate some sample data, I have taken the hardware for a walk to the post office. We will now open the file produced by our hardware and examine it further. If you would like to follow along, you can download the file from here.
The file is a typical, comma-delimited text file. You can examine it further using common spreadsheet software such as LibreOffice Calc. For example, if you open the file of GPS data from here, you will be presented with the following window:
You can see that the data delimits quite easily. Just click “OK” and the file will be presented to you.
So as you can see, there is time, date (remember – GMT), latitude and longitude, my speed (with a couple of anomalies) and random sensor data results (see the sketch). We can have this data converted into a much more useful form by using the GPS Visualiser website. Save the data as a .csv file. Then visit http://www.gpsvisualizer.com/, and use the Get Started Now box in the middle of the web page. Select Google Maps as the output format, then upload the file. This will result in the following:
Just like normal Google Maps there are many display options you can choose from, and the GPS Visualiser web site has many tutorials about making the most of their service. If you look in detail you will see some “jittering” along parts of the track that are not representative of my movements (though I had just taken my morning coffee). This could be the result of the receiver module moving about in all three axes during my walk, one would imagine it would be a lot smoother inside a motor vehicle. So have fun with that.
Have fun and keep checking into tronixstuff.com. Why not follow things on twitter, Google+, subscribe for email updates or RSS using the links on the right-hand column, or join our Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other – and we can all learn something.
October 11, 2010 Posted by John Boxall | arduino, COM-09622, DEV-09802, GPS, learning electronics, microcontrollers, RTL-10709 | 0183, 406, 406A, acceleration, altitude, arduino, COM-09622, compass, data, DEV-09802, DIY, EM, EM-406, EM-406A, global, GPS, guide, guides, heading, III, lesson, lessons, libraries, library, logging, microSD, microSD shield, navigation, newsoftserial, NMEA, pack, positioning, receiver, RTL-10709, shield, Sirf, SirfStarIII, sparkfun, speed, star, system, tinygps, tracker, tracking, tronixstuff, tutorial, tutorials | Leave a Comment
In this instalment we will introduce and examine the use of the Global Positioning System receivers with Arduino systems. What is the GPS? In very simple terms, a fleet of satellites orbit the earth, transmitting signals from space. Your GPS receiver uses signals from these satellites to triangulate position, altitude, compass headings, etc.; and also receives a time and date signal from these satellites. The most popular GPS belongs to the USA, and was originally for military use – however it is now available for users in the free world.
Interestingly, the US can switch off or reduce accuracy of their GPS in various regions if necessary, however many people tell me this is not an issue unless you’re in a combat zone against the US forces. For more information, have a look at Wikipedia or the USAF Space Command GPS Ops Centre site. As expected, other countries have their own GPS as well – such as Russia, China, and the EU is working on one as well.
So – how can us mere mortals take advantage of a multi-billion dollar space navigation system just with our simple Arduino? Easy – with an inexpensive GPS receiver and shield. When searching for some hardware to use, I took the easy way out and ordered this retail GPS pack which includes the required Arduino shield and header sockets, short connecting cable and an EM-406A 20-channel GPS receiver with in-built antenna:
For reference now and in the future, here is the data book for the GPS receiver: EM-406 manual.pdf. All you will need is an Arduino Uno or 100% compatible board, and the usual odds and ends. When it comes time to solder up your shield, if possible try and sit it into another shield or board – this keeps the pins in line and saves a lot of trouble later on:
And we’re done:
Please notice in the photo above the cable is a lot longer between the shield and the GPS receiver. This was an extra cable, which makes things a lot more convenient, and it never hurts to have a spare. Finally, on the shield please take note of the following two switches – the shield/GPS power switch:
and the UART/DLINE switch:
For now, leave this set to UART while a sketch is running. When uploading a sketch to the board, this needs to be on DLINE. Always turn off your GPS shield board before changing this switch to avoid damage. Example 17.1 – Is anyone out there? Now, let’s get some of that juicy GPS data from outer space. You will need:
Once you have your hardware assembled, upload the following sketch. Now for desk jockeys such as myself, there is a catch – as a GPS receives signals from satellites the receiver will need to be in line of sight with the open sky. If you have your desk next to a window, or a portable computer you’re in luck. Look at the LED on your GPS receiver – if it is blinking, it has a lock (this is what you want); on - it is searching for satellites; off - it is off (!). The first time you power up your receiver, it may take a minute or so to lock onto the available satellites, this period of time is the cold start time.
This will be in ideal conditions – i.e. with a clear line of sight from the unit to the sky (clouds excepted!). Once this has been done, the next time you power it up, the searching time is reduced somewhat as our receiver stores some energy in a supercap (very high-value capacitor) to remember the satellite data, which it will use the next time to reduce the search time (as it already has a “fair idea” where the satellites are). Now open the serial monitor box, sit back and wait a moment or two, and you should be presented with something very similar to this:
What a mess. What on earth does all that mean? For one thing the hardware is working correctly. Excellent! Now how do we decode these space-signals… They are called NMEA codes. Let’s break down one and see what it means. For example, the line: $GPRMC,165307.000,A,2728.9620,S,15259.5159,E,0.20,48.84,140910,,*27 Each field represents:
- $GPRMC tells us the following data is essential point-velocity-time data;
- 165307.000 is the universal time constant (Greenwich Mean Time) – 16:53:07 (hours, minutes, seconds). So you now have a clock as well.
- A is status – A for active and data is valid, V for void and data is not valid.
- 2728.9620 is degrees latitude position data = 27 degrees, 28.962′
- S for south (south is negative, north is positive)
- 15259.5159 is degrees longitude position data = 152 degrees, 59.5159′
- E for east (east is positive, west is negative)
- 0.20 is my speed in knots over ground. This shows the inaccuracy that can be caused by not having a clear view of the sky
- 48.84 – course over ground (0 is north, 180 is south, 270 is west, 90 is east)
- 140910 is the date – 14th September, 2010
- the next is magnetic variation for which we don’t have a value
- checksum number
Thankfully the data is separated by commas. This will be useful if you are logging the data to a text file using a microSD shield, you will then be able to use the data in a spreadsheet very easily. Later on we will work with data from other codes, but if you can’t wait, here is the NMEA Reference Manual that explains them all. In the meanwhile, how can we convert the location data (longitude and latitude) received into a position on a map?
- Visit this website
- In the box that says “paste your data here”, enter (for example, using my data above)
For example: Then click “Draw the Map”, and you will be presented with a Google map in a new window that you can zoom around in, change views and so on. Interestingly enough the coordinates returned in the test above were accurate down to around three meters. Later on that website will be of great use, as you can import text files of coordinates, and it will plot them out for you. If you use this mapping site a lot, please consider making a donation to help them out. Now as always, there is an easier way. The purpose of the previous demonstrations were to see the raw data that comes from a receiver, and understand how to work with it.
Moving on… now we can receive GPS signals – and in the past we have used LCD modules – so we can make our own variations of portable (!) GPS modules and other devices. At this point you will need to install another Arduino library - TinyGPS. So download and install that before moving forward.
Example 17.2 – My First GPS
Using various pieces of hardware from the past, we will build a simple, portable unit to display our data.
You will need:
- Arduino Uno or compatible board
- a suitable GPS setup – for example the GPS shield bundle;
- An LCD with HD44780 interface that has the ability to connect to your Arduino system. The size is up to you, we’re using a 20 x 4 character unit. If you have dropped in or are a bit rusty on LCDs, please read chapter twenty-four;
- An external power supply for your setup (if you want to walk up and down the street at midnight like I did) – for example, a 9V battery snap soldered to a DC plug is a quick and dirty solution!
Luckily I have made an LCD shield in the past which works nicely, and doesn’t use digital pins D0 and D1 – these are used by the GPS shield to get the data back to the Arduino. Therefore the whole lot just plugged in together as shields do. Here is the sketch for your consideration. Before uploading the sketch, turn off the GPS shield, set the DLINE/UART switch on the GPS shield to DLINE, upload the sketch, then set it back again, then back on with the GPS shield.
So here it is all thrown together in my lunch box:
And a close-up view of the LCD. There was not room for the course data, but you can modify the sketch accordingly. The data will be a little off due to the photo being taken indoors:
Now for some outdoor fun. In the video clip below, we take a ride on the bus and see our GPS in action…
I had to take an old bus that wasn’t full of security cameras, so the ride is bumpy:
As we have a lot of electronics in this setup, it would be interesting to know the current draw – to help plan for an appropriate power supply. The trusty meter gives us:
Wow – a maximum of 122 milliamps even with that LCD backlight blazing away. So when we make some GPS logging devices without such a monstrous LCD, we should be able to get the current draw down a lot more.
The purpose of this example was to show how you can manipulate the data from the GPS receiver. We continue with GPS part II here.
September 17, 2010 Posted by John Boxall | arduino, beginnner, education, GPS, GPS-09123, learning electronics, microcontrollers, RTL-10709 | 0183, 406, 406A, acceleration, altitude, arduino, compass, data, DIY, EM, EM-406, EM-406A, global, GPS, GPS-09123, guide, guides, heading, III, lesson, lessons, libraries, library, logging, microSD, microSD shield, navigation, newsoftserial, NMEA, pack, positioning, receiver, RTL-10709, shield, Sirf, SirfStarIII, sparkfun, speed, star, system, tinygps, tracker, tracking, tronixstuff, tutorial, tutorials | 13 Comments
YouTubeVisit tronixstuff on YouTube for our range of videos
Arduino TutorialsClick for Detailed Chapter Index
Chapters 0 1 2 3 4
Chapters 5 6 6a 7 8
Chapters 9 10 11 12 13
Ch. 14 - XBee
Ch. 15 - RFID - RDM-630
Ch. 15a - RFID - ID-20
Ch. 16 - Ethernet
Ch. 17 - GPS part I
Ch. 18 - RGB matrix
Ch. 19 - GPS part II
Ch. 20 - I2C bus part I
Ch. 21 - I2C bus part II
Ch. 22 - AREF pin
Ch. 23 - Touch screen
Ch. 24 - Monochrome LCD
Ch. 25 - Analog buttons
Ch. 26 - Arduino + GSM - part I
Ch. 27 - Arduino + GSM - part II
Ch. 28 - Colour LCD
Ch. 29 - TFT LCD
Ch. 30 - Arduino + twitter
Ch. 31 - Inbuilt EEPROM
Ch. 32 - Infra-red control
Ch. 33 - Control AC via SMS
Ch. 34 - SPI bus part I
Ch. 35 - Video-out
Ch. 36 - SPI bus part II
Ch. 37 - Timing with millis()
Ch. 38 - Thermal Printer
Ch. 39 - NXP SAA1064
Ch. 40 - Push wheel switches
Ch. 40a - Wheel switches II
Ch. 41 - More digital I/O
Ch. 42 - Numeric keypads
Ch. 42a - Keypads II
Ch. 43 - Port Manipulation
Ch. 44 - ATtiny+Arduino
Ch. 45 - Ultrasonic Sensor
Ch. 46 - Analog + buttons II
Ch. 47 - Internet-controlled relays
Ch. 48 - MSGEQ7 Spectrum Analyzer
Arduino Due - first look
Ch. 49 - KTM-S1201 LCD modules
Ch. 50 - ILI9325 colour TFT LCD modules
Ch. 51 - MC14489 LED display driver IC
- May 2013
- April 2013
- March 2013
- February 2013
- January 2013
- October 2012
- September 2012
- June 2012
- May 2012
- April 2012
- March 2012
- February 2012
- January 2012
- December 2011
- November 2011
- October 2011
- September 2011
- August 2011
- July 2011
- June 2011
- May 2011
- April 2011
- March 2011
- February 2011
- January 2011
- December 2010
- November 2010
- October 2010
- September 2010
- August 2010
- July 2010
- June 2010
- May 2010
- April 2010
- March 2010
email - john at tronixstuff dot com
Australian Electronics!Buy and support Silicon Chip - Australia's only Electronics Magazine.
Creative CommonsAll the original material in this website, unless noted otherwise, is covered under a Creative Commons Attribution-Non Commercial-Share Alike v3.0 license. Please email me if you see any mis-attributions or would like to use my content in different circumstances.
- RT @MakerFaireMel: Ammon, James and Paul have been working on another event in Nov 2013. You can check out what we've been up to here: htt… 20 hours ago
- RT @jonoxer Packaging for the new @freetronics Arduino-compatible RGB cube looks almost as good as the actual cube http://t.co/xXMb8HFbXw 1 day ago
- RT @jonoxer Awesome! Postie just delivered @tronixstuff's new #Arduino book. Looks great. #ArduinoWorkshop http://t.co/3nX0bWaxLi 1 day ago
- RT @jonoxer: Awesome! Postie just delivered @tronixstuff's new #Arduino book. Looks great. #ArduinoWorkshop http://t.co/5Bxq4bBn7r 1 day ago
- Arduino IDE v1.0.5 has been released - arduino.cc/en/Main/Softwa… 4 days ago
Find me on…
Nuclear weapons = global suicide