The WordPress.com stats helper monkeys prepared a 2014 annual report for this blog.

Here’s an excerpt:

The concert hall at the Sydney Opera House holds 2,700 people. This blog was viewed about 13,000 times in 2014. If it were a concert at Sydney Opera House, it would take about 5 sold-out performances for that many people to see it.

I knew the dimension of the LCD (Nokia 5110) as 43mm x 43mm but it looked smaller than I thought. That’s good because I want to put it on top of the GPS (Holux M-1000).

In my previous post, I explained how to get coordinates, date & time, speed, and bearing data from GPS, Holux M-1000. Now that I have the LCD, it’s time to add two parts to the Arduino sketch: 1) LCD driver/display, 2) distance calculation between two locations.

1. LCD Driver

First of all, I searched for a simple and small library for the LCD, Nokia 5110. There were a few different libraries for this LCD: Adafruit’s, Sparkfun’s, and Henning Karlsen’s. Among these libraries, I chose Henning Karlsen’s because I needed only simple text display with a couple of different font sizes. Henning Karlsen has separate library for graphics as well. I would like to thank Henning for his sharing his nice work on the library. Henning’s library supports 3 different font sizes: SmallFont (text and number, 6×8), MediumNumber (number only, 12×16), and BigNumber (number only, 14x 24). Only downside of this library is that the Medium and Big fonts do not support texts but only numbers. However I would need only numbers to display with bigger fonts, this limitation was no problem with me.

2. Distance calculation between two locations

There are number of websites showing how to calculate distance between two locations from latitudes and longitudes. Movable Type Scripts shows various calculations of distance, bearing and other useful conversions using Haversine formula and BlueMM posted the Excel formula to calculate distance which is basically the same way as Haversine.

The calculation is quite straightforward but I found there was a problem: Arduino (Atmega328p) cannot handle over 6-7th decimal digits which is very important in trigonometric calculation for short distance.

Arduino reference page says “Floats have only 6-7 decimal digits of precision. That means the total number of digits, not the number to the right of the decimal point. Unlike other platforms, where you can get more precision by using a double (e.g. up to 15 digits), on the Arduino, double is the same size as float.”

Let me give you an example. Suppose we started from a position A (lat: 40.00, long: 80) to a position B (lat: 40.01, long: 80.00). That is, we moved 0.01 degrees in latitude only. If you calculate the distance using Haversine formula on your PC, you will get about 1,111.9m. However, Arduino calculates it as 3,110.8m. Big error! More interesting thing is that even if you reduce the latitude difference to 0.001 or 0.0001 degrees, you get the same results, 3,110.8m. So I investigate further what exactly cause this error. Of course I know the culprit is the float precision limitation as said above. But I wanted to know which part of the calculation by Arduino cause this big error. In the Haversine formula, there are COS, SIN and ACOS functions used. I tested a few different calculations using these functions and found the calculation of COS and SIN functions affect minimal but the problem was the ACOS. If you calculate the formula on your PC only inside of ACOS bracket, you will get 0.9999999848. See my point? The decimal places below 6th in ACOS function is actually important to calculate the angular difference for small distance, but unfortunately Arduino cannot handle this. Not only for small distance but for even relatively long distance (say over 1 degree for instance) there is error between the results on the PC and Arduino.

Well, so I started thinking about how to avoid trigonometric function calculation when over 6th decimal places are important. And I found a solution! Instead of calculating angular difference between two positions and THEN calculating the distance by multiplying the mean earth radius, calculating a ratio of angle between two positions (latitude and longitude separately) over 360 degrees and divide the circumference of the earth by this ratio. In other words, keep the numbers big while calculation. Arduino’s float type has a limitation on the small decimal places, but can handle relatively big numbers!

Below is the test Arduino sketch to test my formula. The result is 11.029m while Haversine formula for the same coordinates gives 11.119m. This is close enough considering the accuracy of the most GPS is bigger than one meter.

Finally, I got the Nokia 5110 LCD that was ordered on eBay a few weeks ago. It took me a couple of days to find the best library for the LCD and quickly updated my Arduino program to display current location (latitude and longitude), date/time, speed, and bearing. There is 2.8V regulated power in the GPS that powers the JeonLab mini and LCD. I will upload my sketch and full detail later.

Holux M-1000 is a GPS receiver with a Bluetooth. I had used it for navigation with Palm TX and Treo700p (yes, I have long been a big fan of Palm PDA series) and Geocaching until I bought Android smartphone which has a built-in GPS module. So Holux M-1000 has been in my drawer collecting dust for more than a year.

From last summer, I began to play golf and I think I’m getting better. :-) I searched and found a lot of Android applications for assist golfing with maps, hole/hazard information, showing how many yards left and so on. I’m a gadget mania so I downloaded most of them and tried but none of them satisfied me. In most of cases, I didn’t bother to pull out my phone and enter my password to unlock the phone and go to the application and run and wait. Well, one might say that why not keep the phone ON while you are playing? Yes, you can do that. But the GPS module drains battery so fast and I don’t want to miss any phone calls because of the low battery. Not only because of the battery consumption, I can’t find any application fits me (yet).

So I thought I would like to have a GPS module, very simple module, that can show distance between two locations. For example, at a tee, the first location can be marked by pressing a button on the device and from that point, the device shows how far I moved while I walk to the spot for the second shot. And then I can push another (or the same) button to clear the first point and mark current spot as the first location and do the same, and so on.

What parts would I need for building this device? Here is the list of the part I noted.

GPS module that can communicate with Arduino (or Jeonlab mini, of course :-)

LCD: I have a 16×2 LCD but it’s bulky and shows only two lines. I have ordered popular Nokia 5110 LCD on ebay and I’m waiting for it as of this writing.

That’s when I remembered my old gadget, Holux M-1000. It has a bluetooth which means it should have serial output somewhere between the GPS module and the bluetooth module. I started opening up the Holux M-1000 and found RX… TX… on the PCB. YES!! But I needed to know what voltage requirements for these pins. So I searched on internet for a datasheet or instruction manual of Holux M-1000 and found there were already some people tried to read GPS signal from the Holux M-1000 using either Arduino or PIC microcontrollers. Maybe I was not very lucky to find good articles but none of them were quite useful to give me answers what I wanted clearly. I found the User’s Manual (1371865.pdf) from Holux homepage and I got very important information as below.

Pin 4 and 3 on the USB mini B connector on Holux M-1000 are TX and RX (so I don’t have to add wires from the PCB. That’s good news to make my life easier. In fact, I had thought the USB jack is only for charging the battery!)

Pins 5 and 1 of the USB connector are Vcharge (5V) and GND, respectively as standard USB pinouts.

Those two RX and TX pins’ voltage range is 3.3 – 5V

Data format: NMEA0183 V3.01, GGA, RMC, VTG, GSA, GSV

Power consumption: 40 – 50mA in normal mode, 35mA in power saving mode

Now, I’m not familiar with NMEA data format, so I searched on internet again and found some good sites here and there. There are bunch of GPS information you can get from sentences that Holux M-1000 generates periodically as GGA, RMC, VTG, GSA, and GSV, but I don’t need all of them. All I need is latitude and longitude actually, but additional information such as time and date, bearing, speed will be good to know as well. The sentence, RMC has all of these. Well, program might be simple if I needed to read data from only one sentence, then.

The GPS (Holux M-1000) and the Jeonlab mini v1.3 with an FTDI breakout board are shown above. I have USB A to mini-B cable but I didn’t want to cut the cable, so I used a female USB-A connector as shown below. Note that only 3 pins (V+, GND, and TX from GPS) are used since I only need to read serial data from the GPS, not sending any command or data to it.

And the picture below shows how they connected each other. The FTDI breakout board is connected to my computer through USB cable.

While I’m testing, I need serial communication between the Jeonlab mini and my computer and I will need these pins (RX, TX on the Jeonlab mini) later when I want to modify my program. So I decided to use the Softwareserial library which is already included in the Arduino libraries. The TX pin from the GPS is connected to the pin 10 of the Jeonlab mini. I also connected the V+ from the GPS to the Vcc pin of the Jeonlab mini as well as GND pins. In fact, you don’t need to connect the V+ pins as long as they are powered up by their own power source, but this way I can continuously charge the GPS battery from my computer USB port.

I will need more time to finish the whole program while I’m waiting for the LCD that I bought, but let me show how I have programmed so far. It can read RMC data from the GPS and get the coordinate, bearing, speed, date and time. Thanks to ‘serial parse’ function that is included in the Arduino version >1.0, it was easy to get numeric values from the serial data coming in from the GPS. However, one tricky thing was to get the local time from UTC time and date. I had to consider time zone, DST(daylight saving time), number of days of each month, leap year, etc. That was fun to figure out how to get correct time and date.

Here is my code so far. I guess it is quite straight forward, but if you have any question, please add a comment below.

My car doesn’t have a compass which I wish to have one. So I started making one using my JeonLab mini v1.3 (minimalist Arduino compatible board), popular 16×2 LCD panel with a back light LED, and a 3 axis magnetometer. Here is the part list and pictures of the LCD, JeonLab mini v1.3 and the prototyping board.

The JeonLab mini v1.3 is so small that can be attached to the back of the LCD.

First of all, the LCD, JeonLab mini and the magnetometer, MAG3110 have been assembled on a breadboard and tested. The magnetometer has 3 axis sensor, but because, fortunately, the most roads where I live and commute to work are relatively level. So I didn’t bother to use complicated equations, but decided to calculate simply the heading angle using ATAN from X and Y readings. And it really works just good enough. Take a look at the source Arduino code below./*
JeonLab Car Digital Compass & Thermometer

I have introduced a step-by-step assembling procedure on Instructable, and here are some pictures of assembling and mounting on top of the interior mirror of my car.

Note that there is no LED attached. A 6-pin header is attached upwards for the FTDI USB interface and 3 single header pins are attached at the bottom of the JeonLab mini to support on the prototyping board which will be attached to the back of the LCD.

The temperature sensor (TO-92 package), a voltage regulator, and a calibration switch are assembled.

Next to the temperature sensor, the phototransistor (looks like a 3mm LED in black) is added to adjust the LED backlight of the LCD automatically.

A thick solid copper wire (appx. 1mm in diameter) is used to form a simple bracket on top of the interior mirror.

A heat shrink tube is used to insulate the copper wire bracket where it touches the LCD PCB.

Two short cable ties are used to fix the assembled LCD and bracket on top of the mirror.

The magnetometer is held by a small suction cup on the wind shield at the back of the mirror.