u-blox NEO-6M GPS on 20x2 example

Hey everyone,

Here's my GPS example for a u-blox NEO-6M GPS. They're cheap on ebay. I could only get it to work on a 20x2 chip. :cool:

Code:
'
'NMEA ref: [URL]http://www.gpsinformation.org/dale/nmea.htm#ZDA[/URL]
'
'init
#terminal 19200 on
setfreq m16

symbol GPSTX = c.2  ' Orange cable
symbol blueLED = c.4
symbol greenLED = B.7
symbol GPSlock = b20
symbol KPH = b21
symbol tempNum = b22    
symbol SatNum = b23

'vars
symbol baud = T9600_16
GPSlock = 0'no lock
symbol MinSats = 6

strt:
 gosub Acquire
 gosub GetTime
 gosub GetPosition
 gosub GetHeadingSpeed
 gosub GetNumOfSat
 'gosub showallgpsstrings
 gosub LEDStatus 
  
 pause 100
goto strt

'------------------------------------------

ShowAllGPSStrings:

 serin GPSTX, T9600_16,("$GPRMC"), b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10
 sertxd  ("##",b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10  ,"#" ,13,10)

return

Acquire:

 serin GPSTX, T9600_16,("$GPRMC,"), b0,b1
 
 if b1 = "V" THEN'do time yet
 
  sertxd (" - No signal", 13,10)
  GPSlock = 0
  
 else'time aquired
 
  sertxd (" - ACTIVE", 13,10)
  GPSlock = 1
  
 end if

return

GetTime:
 
 serin GPSTX, T9600_16,("$GPRMC,"), b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11
 
 if GPSlock = 0 then'no data yet
  return
 end if
 
 sertxd ("Time ", b0, b1, ":", b2, b3, ":", b4, b5, 13,10)

return

GetPosition:
 
 serin GPSTX, T9600_16,("$GPGLL,"), b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11
 
 if GPSlock = 0 then'no data yet
  return
 end if
 
 sertxd ("Latt ", b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b11, 13,10)
 
 if b11 = "N" then'north lattitude
  serin GPSTX, baud,("N,"), b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12
 else'south lattitude
  serin GPSTX, baud,("S,"), b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12
 end if
 
 sertxd ("Long ", b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b12, 13,10)

return

GetNumOfSat:
 
 serin GPSTX, T9600_16,("$GPGSV,"), b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16'number of satelites
 
 SatNum = b4 - $30 * 10
 SatNum = SatNum + b5 - $30
 
 if GPSlock = 0 then'no data yet
  return
 end if
 
 sertxd ("# of Satelites ", b4, b5, 13,10)
 
 return
 
GetHeadingSpeed:
 
 serin GPSTX, baud, ("$GPVTG"), b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16
 
 if GPSlock = 0 then'no data yet
  return
 end if
 
 if b1 = "," then''not moving
  sertxd ("Speed 0", 13, 10)
  low b.7
 else'moving
  sertxd ("Heading ", b1, b2, b3, b4, b5, 13,10)
  sertxd ("Speed ", b13, b14, b15, b16, 13,10)
  
  if b14 = "." then'slower than 10KPH
   tempNum = b13 - $30
  else'faster than 10KPH
  '100ths
   tempNum = b13- $30 * 10
   '10ths
   tempNum = tempNum + b14 - $30
   
   'not an erroneous reading & enough Satelites / error keeps last KPH
   if tempNum < 150 and SatNum >= minSats then
    KPH = tempNum
   end if
   
  end if
  
  if KPH >= 20 then
   
   sertxd ("Faster than 20 KPH")
   high greenLED
   
  else
  
   low GreenLED
   
  end if
  
 end if
 
 return
 
LEDStatus:
 
 if GPSLock = 0 then'no lock slow blink LED
  
  'blink LED slowly
  toggle blueLed
  pause 150
  toggle blueLed
  
 elseif SatNum < minSats and GPSlock = 1 then'les than min sats, turn on fast blink LED
  'blink LED
  
  high blueLED
  pause 50
  low blueLED
  
 else'lock and enough Satelites solid LED
 
  high blueLED
  
 end if
return
 
Last edited by a moderator:

edmunds

Senior Member
Thanks for posting. Looks very interesting. And they actually provide a manual :).

I wander if you have any clues as to why it would only work with 20X2?


Regards,

Edmunds
 
Thanks for posting. Looks very interesting. And they actually provide a manual :).

I wander if you have any clues as to why it would only work with 20X2?


Regards,

Edmunds
I only tried on a 08m and 20x2. I think it didn't work on the 08m because of the 9600 baud rate.

My only problem is my code is a bit slow. I'm trying to speed it up.

Norm
 

neiltechspec

Senior Member
I just tried your code, sure enough it doesn't work on an 08m2.

Noticed that you have defined variable 'baud' and not used it.
So changed your code to use it instead of 'T9600_16'.
Now it works.

So it's probably down to the way you have coded being too slow and missing the input strings.

Neil
 

Michael V

Senior Member
Hi Norm,
I'm about to try a project using GPS. where i capture data from a vehicle, and send it by radio or bluetooth, but only if it within specified range of my base station. I really am only interested in the location, not all the other stuff that comes with the long NMEA string. I've been reading a lot on processing data From GPS. What i read it is not uncommon for the processor to be overwhelmed with incoming data, ( probably the code rather than the processor itself) and missing the input strings. I have looked at your code and can't wait to try it, i think i can adapt it - thanks for sharing.

I also came across this video

https://www.youtube.com/watch?v=TwhCX0c8Xe0

Its about an arduino - but from it i learned that UBlox modules can be configured with a software utility. The Baud rate can be slowed down, to make it more 08m friendly, and the data send frequency can be changed. That could help.

The video is actually about using binary data rather than the NMEA string, the ublox modules have this option. Evidently this means less serial data needs to be sent, and less lines of code are needed to process the data. This has bound to be beneficial to someone.

I'm a newby to GPS and i won't be doing any of that fancy stuff. I'll be starting with your code, but i thought i'd share.
Michael
 

BESQUEUT

Senior Member
So it's probably down to the way you have coded being too slow and missing the input strings.
Neil
+1
sertxd takes a lot of time...
Try reading all at one time
Code:
 serin GPSTX, T9600_16,("$GPRMC"), @bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc
 serin GPSTX, T9600_16,("$GPRMC,"), @bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc
 
 serin GPSTX, T9600_16,("$GPGLL,"), @bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc
 
 serin GPSTX, baud,("S,"), @bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc
 serin GPSTX, T9600_16,("$GPGSV,"), @bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc'number of satelites
  
 serin GPSTX, baud, ("$GPVTG"), @bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc
and only then deal with data.
But I do not think that it is enought because using qualifiers the Picaxe have to wait a full message to read only one sentence...
If the GPS refresh rate is one message per second, the Picaxe have to wait at least 6 s to read each message.
I said "at least" because it is also possible that the sertxd be too long to catch the next sentence. In that case, the Picaxe have to wait two messages (or more) to read one sentence, that may be 12s or more for the full message...

If the GPS send not only 6 sentences but the full 19 set, that may be 3 times more...


The good way is to use serial background receive.

You can also suppress all PAUSE commands...
 
Last edited:

hippy

Technical Support
Staff member
Also check out the code examples and other documentation under the datasheet section for the GPS010 ublox max-6 GPS breakout ...

www.picaxestore.com/gps010

If only wanting co-ordinate data, the trick is to determine which $GP message delivers that and ignore the others. Even better still, configure the GPS so it does not send those others.

I think the message required is $GPGLL. I did have some PICAXE code which read only the GPS location, put its raw co-ordinates on an OLED display but can't seem to locate that at present.

I also had some PICAXE code which converted to real world OS co-ordinates which has also gone missing. I recall it was a bit tricky but even using simplistic 16-bit PICAXE maths I could place myself on a map to within about half a mile of where I actually was.

The easiest way of determining whether one is in range of a certain location, is probably not to do it with circles and trig, but to build that circle out of sets of squares. Have a square that surrounds the circle and a square inside it and that gives a fast outside and inside test, then it just needs further tests when in the larger square but not in the smaller square.

If you need to know distance or heading to a particular location that will likely need a maths library.
 

BESQUEUT

Senior Member
Maybe an idea to speed up things....

For thoses who need all sentences.
GPS is sending messages in the form of few sentences, say S1 S2 S3 S4 S5 S6
With the #1 code, IMHO your are reading the RED sentences :
S3 S4 S5 S6 S1 S2 S3 S4 S5 S6 S1 S2 S3 S4 S5 S6 S3 S4 S5 S6 S1 S2 S3 S4 S5 S6 S1 S2 S3 S4 S5 S6 S1 S2 S3 S4 S5 S6 S1 S2 S3 S4 S5 S6
So it is very long...
Of course, when just reading S1, you are to late to read the S2 message...
but you have a chance to read S3
So, you may speed up things reading sentences in the order S1 S3 S5 S4 S6 S2
S3 S4 S5 S6 S1 S2 S3 S4 S5 S6 S1 S2 S3 S4 S5 S6 S1 S2 S3 S4 S5 S6 S1 S2 S3 S4 S5 S6 S1

If you not want all the data, simply comment corresponding gosub in #1 code.
As this code use qualifiers, there no need to explicitely read all sentences...
I recall it was a bit tricky but even using simplistic 16-bit PICAXE maths I could place myself on a map to within about half a mile of where I actually was.
Whaou !!! That is less than 0.007 degree. I want to read this code !

If you need to know distance or heading to a particular location that will likely need a maths library.
Time to promote my Floating-Point-Library
 
Last edited:

Michael V

Senior Member
Yes i looked at that - the utility allows you basically pick the shortest "sentence" that has the info you want. That has to help.

I started reading about the floating point thing and maths which i thought i might need, as nummbres might not all be the same length. But then it came to me that this application does not need to tell me what part of the globe i am in, only if i an within a short distance of another point - possibly another picaxe with GPS. The Lat and long are numbers about seven digits long, i only need the last three, the fifth integer after the decimal place is about a metre. the radio isn't going to go more than a few hundred metres. I figured if all i did was subtracted one number from the other to find out the difference between the two, i could do it with conventional picaxe integer maths. I have to ignore the leading numbers but there must be a way to do it. If there isn't the digital way would work because just have to use the least significant bits. Not that i know how to do that yet.

I thought about defining a circle and i thought - no. if i determine which is the bigger latitude with four significant figures, then and subtract the smaller from the larger, knowing that i could never have received that data from more than 1km away, that will give me the difference in latitude. Repeat for longitude. If the sum of the two is less than say 10 metres, then i have defined a square, or a diamond, that is ten metres across the diagonal, about 7 metres side to side. Good enough for what i want. the physical vehicle is either going to be in that box, or much more than 10 metres away. Well that's the theory, im sure i will learn more when i do it.

Fortunately in Australia i don;t have a Greenwich meridian or equator to worry about, that will be enough of a challenge. Sorry BESQUEUT, maybe i'll use the floating point library another time.

Thanks for the guidance!

Michael
 

BESQUEUT

Senior Member
Yes i looked at that - the utility allows you basically pick the shortest "sentence" that has the info you want. That has to help.

I started reading about the floating point thing and maths which i thought i might need, as nummbres might not all be the same length. But then it came to me that this application does not need to tell me what part of the globe i am in, only if i an within a short distance of another point - possibly another picaxe with GPS. The Lat and long are numbers about seven digits long, i only need the last three, the fifth integer after the decimal place is about a metre. the radio isn't going to go more than a few hundred metres. I figured if all i did was subtracted one number from the other to find out the difference between the two, i could do it with conventional picaxe integer maths. I have to ignore the leading numbers but there must be a way to do it. If there isn't the digital way would work because just have to use the least significant bits. Not that i know how to do that yet.

I thought about defining a circle and i thought - no. if i determine which is the bigger latitude with four significant figures, then and subtract the smaller from the larger, knowing that i could never have received that data from more than 1km away, that will give me the difference in latitude. Repeat for longitude. If the sum of the two is less than say 10 metres, then i have defined a square, or a diamond, that is ten metres across the diagonal, about 7 metres side to side. Good enough for what i want. the physical vehicle is either going to be in that box, or much more than 10 metres away. Well that's the theory, im sure i will learn more when i do it.

Fortunately in Australia i don;t have a Greenwich meridian or equator to worry about, that will be enough of a challenge. Sorry BESQUEUT, maybe i'll use the floating point library another time.

Thanks for the guidance!

Michael
No problem for floating point library :rolleyes:
In a close area, you can consider Lat and long are close to X and Y coordinates. You have to calculate Xscale and Yscale for your local area. After that , you are OK.
 
Last edited:

hippy

Technical Support
Staff member
But then it came to me that this application does not need to tell me what part of the globe i am in, only if i an within a short distance of another point
If you have two coordinates, a simple test of Abs(x1-x2)2 + Abs(y1-y2)2 > d2 should get the job done in telling if something is further away than expected, and it should be possible to handle that with native PICAXE integer maths.

One might have to convert a WGS84 degree and minute value 'ddmm.mmmm' to a degree value to make things easier but that isn't particularly hard either.
 

hippy

Technical Support
Staff member
One thing to note with any SERIN based NMEA/GPS project is that value fields returned may be of variable length.

That can make it difficult to capture the data a character at a time, and can also make it difficult to interpret data correctly. Using a "#" to capture numeric fields can work in some places, but using the same to capture fields after a decimal point will not work as important leading zeroes will be lost.

Because coding and testing is usually done in a fixed location it is often easy to forget that the data format may change dramatically when the final project is moved elsewhere.

A tool which can be useful in that situation is to program another PICAXE or a PC to send faked GPS/NMEA strings in various formats to help check they are all interpreted correctly.

One solution to unknown or uncertain format of data is to use a separate PICAXE between the GPS receiver and the PICAXE which is using the GPS data. That bridging PICAXE can be programmed to take variable field data and deliver it to the main PICAXE in an fixed format.

That may feel like an excess PICAXE whose code could be incorporated directly into the main PICAXE but it does allow the project to be nicely partitioned, separately developed and tested. It can be a lot easier to develop ( and for others to understand or help debug ) two simpler pieces of code than one more complicated piece of code. It allows each piece of code to be developed in the way which best suits its goals without having to overly worry about how the two have to integrate together.

It can be a good approach during development at least. The two parts of the code can be merged later once each part is finalised if that is desired. Though 'if it's not broken; don't fix it' can make going with what one has a better choice for one-off projects.
 

srnet

Senior Member
There is code available, for an X2 PICAXE, that will use a normal NMEA output GPS to record the Home (startup) location and then calculate and transmit the distance and direction from Home. The calculations were limited to around 1 degree of latitude and longitude and were accurate in distance to circa 1% and direction within 1 degree.
 

Michael V

Senior Member
I like that Abs test - better - also circular rather than square - There is no function in the manual for that, but i'm sure there are a few lines of code or subroutine.

I knew the variable length could be a trap for young players, which is why i thought the option to configure the ublox to output Byte data might be attractive, and mentioned it here. You can close off the NMEA completely and only get the Ublox byte format. Also the frequency at which you get it, if you want it faster. There are more sentences you can choose and they are smaller. The Arduino guy in the video says it reduces the number of lines in the code dramatically - which was his reason for doing it - running out of memory. Great if you can speak Binary - or not.

I was hoping i would not have to learn the binary. Because i'm only looking for short distances i hope that there is a way to only grab the last four significant digits, even on Greenwich meridian at the equator the numbers will always be longer than that. But maybe binary is easier than i thought.

Using fake GPS data from another picaxe is a really good idea.

I like the idea of using a separate picaxe to "process" the variable length data - will start there and get that right first. Thinking dedicate a 08M to that and

I had a closer look at the ublox chips, and there are newer versions than the Neo-M6N. While some changes don't really add much to an Amateur tracking project, the newer modules Neo-M8N modules might. They seem to be made for planes and drones, are still only about $30-40 AUD on Alibaba or eBay.

Evidently the Neo-M6 modules only pick up the american satellites, but the M8N also picks up the Russian GPS satellites and other peoples satellites. Here was me thinking there was one GPS system, but evidently not. More satellites makes for greater precision , and more chance of getting a signal if you are surrounded by buildings. It Also has a compass, (which i ay never use). So i've just ordered one of those.

There is a chip that ublox have just released, not yet available on the eBay module market yet, the NEO-M8U. The U is for Untethered dead reckoning. It also has accelerometers and a gyro in there plus the compass. So, if it loses satellites through going through car parks, tunnels, into buildings, rather that cut out or give innacurate signal, it still keeps generating reasonably valid position data, without the need for connection to any external sensor ( eg speedo). I reckon it won't be long before we start seeing those on ebay.

Question - looking at the code at beginning of this, that the code would not work on 08m but now does, this comment:

'Noticed that you have defined variable 'baud' and not used it. So changed your code to use it instead of 'T9600_16' Now it works."

Do i just replace each instance of "T9600_16" with "BAUD"?

Thanks,
Michael
 

BESQUEUT

Senior Member
I was hoping i would not have to learn the binary. Because i'm only looking for short distances i hope that there is a way to only grab the last four significant digits, even on Greenwich meridian at the equator the numbers will always be longer than that
Suppose you are near Coober Pedy.
One point can be 134°59'59'' and the other 135°00'01'...

'Noticed that you have defined variable 'baud' and not used it. So changed your code to use it instead of 'T9600_16' Now it works."
Do i just replace each instance of "T9600_16" with "BAUD"?l
Yes you can.
 
Last edited:

BESQUEUT

Senior Member
If you have two coordinates, a simple test of Abs(x1-x2)2 + Abs(y1-y2)2 > d2 should get the job done in telling if something is further away than expected, and it should be possible to handle that with native PICAXE integer maths.

One might have to convert a WGS84 degree and minute value 'ddmm.mmmm' to a degree value to make things easier but that isn't particularly hard either.
Lat/lon are NOT coordinates : they are angles, not length...
To convert from theses angles to actual coordinates, you have to know earth radius for the local area.(To be exact, for any point with the same latitude)
With the help of Excel, you can calculte this in advance for your local area and define symbols for the Picaxe code.
Excel..jpg
For example, 1'lon is 1300m near Melbourne, but 1800 m near Darwin
Also note that going away 1' North or Sud will cause a 0.27m per ' lon error,
and going up 2000m will cause length growing 0.50 m per '

I you don't believe me, you can also go the flat earth society
Not sure they use GPS,... but you may have a try...
 
Last edited:

srnet

Senior Member
My understanding would be that Latitude and Longitude are an example of Spherical Coordinates.

https://en.wikipedia.org/wiki/Spherical_coordinate_system

"In a geographical coordinate system positions are measured in latitude, longitude and height or altitude"

And I think everyone understands that you cannot treat Lat and Lon directly as a simple set of Polar Coordinates. Although for small distances of a few 10s of kM you can with only a small error, if you know the earth radius for the locality.
 

BESQUEUT

Senior Member
My understanding would be... you cannot treat Lat and Lon directly as a simple set of Polar Coordinates. Although for small distances of a few 10s of kM you can with only a small error, if you know the earth radius for the locality.
Not polar, but rectangular coordinates, with X and Y scales not equals.
#17 show how to convert 1 degree lat or lon to meters, knowing latitude of local area.
 

hippy

Technical Support
Staff member
The difference in length of a degree arc may not always be as significant as it may first appear; 1300m near Melbourne, 1800 m near Darwin sounds a lot but is essentially 1550 +/- 16%. If we had a 10 m distance based on it being a flat earth, the distance actually covered would be 10 +/- 16% between the two places.

Being 8 to 12 m, an elliptical area rather than circlular, might not make much practical difference for detecting if a car is still on the driveway or has been stolen.

And, when we are getting down to such small distances, the accuracy and consistency of the GPS equipment itself comes into play. When I was testing GPS I was quite surprised to find my house jumped a good few metres at 18:00 every day. I never investigated but suspect it was a satellite coming into or falling out of contact at that time.

It does come down to what the application is. In some cases the difference in length of degree arc will make a difference, other times less so.
 

Michael V

Senior Member
I don;t even have my chip and my head is hurting.

Good thing i'm not in Coober Pedy, for a number of reasons.

Thinking outside the flexible Lat-Long box, my objective is to know the distance apart between two points. The default NMEA is a way of doing it.

One of the Binary outputs available from the Ublox chip is ECEF - which is another thing i am just learning about, like Russian and Chinese satellites. Earth Centerd Earth Fixed. This is apparently a three dimensional coordinate, x,y.z. where the centre of the earth is 0,0,0, and the units are metres. So i'd guess that this is already in + and - . If i have two points with X y z coordinates, then the formula will apply wherever you are on ( below or above) the planet. Not that i know what that is, but i will find out. Only thing is that since the earth is about 6000000 metres the picaxe maths might struggle.
 

srnet

Senior Member
Well as I said, the code to do a distance and direction calc from two sets of Latitude and Longitude coordinates has been done before, so is clearly possible, see here;

http://www.picaxeforum.co.uk/showthread.php?24337-Lost-Model-Locator-with-long-range-capability&highlight=lost+model+locator

It uses a lookup table for the latitdude corrections, has a range of circa 60km here in the UK and is reasonably accurate.

Works with a standard NMEA GPS.

It used a Hope RFM22B to get the telemetry back, or to send the Morse digits. These days you would be much better off using a LoRa device (RFM98\DRF1278F) that will go a great deal further.
 

Michael V

Senior Member
U-Blox Neo 8m

I received the Neo 8Mn module from Alibaba today - been playing with it ever since.

I hooked it up to the computer using a serial adapter and the u-blox u-center utility. At first i couldn't get it to work, but i played with the Baud rate and at 38,400 the screen jumped to life - and the thing new exactly where i was. There really are a lot of satellites out there - this thing picks up American GPS and Russian Glonass satellites. There even a few NSAS satellites, which is a Japanese thing, and QZSS has popped up - another brand. And this is all without leaving the house! There is a way of configuring it to pick up the European Galileo satellites but i can't get that to work yet. All of this means greater precision and signal reliability over a US GPS Neo 6m, for about $10 more.

I played with the configuration settings and there are indeed options, including Binary output, in either Lat-long or XYZ ECEF coordinates. Whatever way i do it i have to do addition and subtraction on some really big numbers that go beyond the 65365 that you can use in picaxe maths. If i use the XYZ otion, it resolves in metres with a decimal point to the nearest cm, although i know its not that accurate.

In My "GPS proximity switch", where i trigger an output if two GPS modules are within radio range, the numbers will be really big, in the tens of thousands of metres, but i will be subtracting one very close large number from the other, to end up with a number of more than a few hundred metres. That will be the range of the radio. I am not interested in the position on the earth, ( because i know where i am) only how far apart two GPS modules are.

I had trouble with that code downloaded from dropbox, the one that works on the nmea code, - it seemed to get all messed up.

I've looked for posts that give tips on doing maths (addition and subtraction) with really large numbers - but i can't really find anything that helps, - but people must be doing it all the time.

Are there any posts or pointers in doing addition and subtraction on numbers like -4663974.56 -(-4663968.52) ? i.e they are only about 6 metres apart, but 4000 km from the centre axis of the earth. Plus - they they come out in Binary ( looks like hex on the screen) with fixed length of four bytes each for x, y and z. Ive searched but obviously not using the right key words.

Regards,
Michael
 

Attachments

AllyCat

Senior Member
Hi,

I haven't looked at that thread in detail, but Jeremy Leach is a "real" mathematician. But beware that program code from 2007 might need to be adapted for the more modern M2 chips.

Another solution might be to use one of the several floating point software packages which have been described for PICaxe. But FP won't necessarily help (much) - it's valuable with numbers which have very large differences (in scale), or if you just can't be bothered to optimse scale factors (e.g. using integer cms rather than 2 decimal places of metres).

There have been a few threads which discuss higher resolution calculations, but I can only find quickly my own. :) So, see if post #2 of this code snippet thread is of any use. Note that 32 bits can handle integers up to over 4 billion.

Cheers, Alan.
 

srnet

Senior Member
I had trouble with that code downloaded from dropbox, the one that works on the nmea code, - it seemed to get all messed up.
If its my code yopu are referring to, can you say what you mean by 'it seemed to get all messed up' ?

The code as published has always worked just fine.

Did you run the code on a 28X2 as required ?
 

srnet

Senior Member
Attached file seemed to get all messed up with HTML code
An un-helpful description of a problem, without any details I would not waste my time looking at working code.

I did ask whether you used it on a 28X2, but you did not reply.
 
Top