Show Posts
Pages: 1 ... 3 4 [5] 6 7 ... 18
61  Using Arduino / Programming Questions / string manipulation and float math problems on: January 28, 2013, 11:04:39 pm
In this piece of code:

Code:
float f, latminutes, longminutes;
    long latdecCoords, longdecCoords;
    int latdegrees, longdegrees;
   
    //char sLongDecCoords[10], sLatDecCoords[10];
   
    //convert latitude to GPS Decimal format
    f = atof(latit1);
    f /= 100.00;
    latdegrees = (int)f; //isolate degrees
    latminutes = ((f - (int)f) * 100.0)+(atof(latit2)/10000.00); //get minutes and fraction of minutes
    latdecCoords = (long)((latminutes / 60.0)*1000000);  //convert to fractions of a degree
    //latdegrees += latdecCoords;  //combine it all into one float
   
    if(NS[0] == 'S') latdegrees *= -1.0;
   
    //cconvert longitude to GPS decimal format
    f = atof(longit1);
    f /= 100.00;
    longdegrees = (int)f; //isolate degrees
    longminutes = ((f - (int)f) * 100.0) + (atof(longit2)/10000.00);
    longdecCoords = long((longminutes / 60.0)*1000000);
    //longdegrees += longdecCoords;
    if(EW[0] == 'W') longdegrees *= -1.0;
   
   
   
    sprintf(latitude, "%i.%ld", latdegrees, latdecCoords);
    sprintf(longitude, "%i.%ld", longdegrees, longdecCoords);
    Serial.print(longit2);
    Serial.print(",");
    Serial.print(atof(longit2)/10000, 4);
    Serial.print(",");
    Serial.print(latdegrees);
    Serial.print(",");
    Serial.print(latminutes,4);
    Serial.print(",");
    Serial.print(longdegrees);
    Serial.print(",");
    Serial.println(longminutes,4);

and

Code:
latit1 is equal to "4041"
latit2 is equal to "1271"
longit1 is equal to "07406"
longit2 is equal to "4956"

I get an output that looks like this:

Code:
4956,0.4956,40,41.1271,-74,6.4954

The problem is longit2.  It is equal to "4956" but for some reason after doing this to it:

Code:
longminutes = ((f - (int)f) * 100.0) + (atof(longit2)/10000.00);

the decimal piece ends up being .4954, and this is repeatable.....it is always .0002 off from the expected value.  I progressively printed out an evaluation of that statement and it maintains the correct value until I add the arguments in front of the plus sign.  What could be going wrong with this?  The calculation for latitude works fine....just the longitude is the problem.
62  Using Arduino / Programming Questions / Re: if(!SD.exists(date + ".txt")); How do I do this? on: January 26, 2013, 03:47:20 pm
Thanks!  That is exactly what I needed.
63  Using Arduino / Programming Questions / if(!SD.exists(date + ".txt")); How do I do this? on: January 26, 2013, 02:45:29 pm
Didn't know really how to describe this in the subject line.  I have:

Code:
char date[9]

which contains "13_01_21" (but this will obviously change each day) and I would like to have ".txt" appended to it in:

Code:
if(!SD.exists(date + ".txt")

so that it will be evaluated as:

Code:
if(!SD.exists("13_01_21.txt"));

What is the operator to do this?
64  Using Arduino / Programming Questions / Re: Why won't this work? on: January 23, 2013, 03:47:33 pm
I believe inside setup you need:

Code:
Serial.begin(baud)

Put

Code:
int val;

inside your loop.
65  Using Arduino / General Electronics / Re: Assistance with electricity. Safety first. on: January 22, 2013, 04:57:17 pm
In the condo I live in, the previous owner installed everything himself
[this is obvious from the mistakes I found] in addition to painting the place, etc.



Sounds like the previous owner of the house I bought.  I finally broke down and re-wired the entire house, outlet boxes, fixtures, wires, and all....bringing everything up to or exceeding code requirements.
66  Using Arduino / General Electronics / Re: first pcb try on: January 22, 2013, 04:49:25 pm
I just put in my first order at this place:

http://dorkbotpdx.org/wiki/pcb_order

They are supposed to come back from the fabricator in about a week.  Pretty good deal considering the fast turnaround and tight board specs.  It is also nice that I can just send them my eagle board file and they will take care of creating the gerber files from it.  Cost me about $14 for 3 double sided boards.
67  Using Arduino / Programming Questions / Re: printing floats without the leading '0' on fractional results on: January 22, 2013, 11:36:22 am
About that 6 digit google gps coordinate, I stared at it sometime back and suspected it is just software engineers not knowing what a gps can do. I was right:

http://wiki.xkcd.com/geohashing/GPS_accuracy

I think getring 5 digits is already asking a bit too much;) 6 digits will be asking for 10 centimeter accuracy. Not sure if millitary can get that good.

Good to know!  I started working out the numbers and began to realize that even where the GPS is off a bit, it is consistently off by that amount (usually only a few yards), and since I am calculating distances, the relative distances between two points should be accurate.
68  Using Arduino / Programming Questions / Re: GPS logger works fine...as long as the serial data coming in isn't valid on: January 21, 2013, 05:00:22 pm
Yep that was the problem.  I took it for a drive and it is quite amazing how the track on google maps follows exactly along with the route that I drove.  Thanks everyone for helping me work through this problem!
69  Using Arduino / Programming Questions / Re: printing floats without the leading '0' on fractional results on: January 21, 2013, 04:57:57 pm
Well that is why I was hoping to be able to break it up into chunks and handle each separately so for instance the data comes in from the GPS as something like:

GPGGA,175030.000,4041.1314,N,07406.5125,W,1,07,1.2,-189.2,M,-34.2,M,,0000*4D

with 4041.1314 being the latitude written as 40 degrees, 41.1314 minutes N latitude.  My sketch pulls out the 4041 and the 1314 as separate numbers.  I then divide the 4041 by 100 to get 40.41 and take just the integer (40) portion as my degrees and then subtract out that integer from the 40.41, multiply it by 100 to get 41 minutes.  Then I add the 41 minutes to the .1314 to get 41.1314 and divide by 60 to get the fractional amount of degrees.  Now it seems to me that I should be able to divide a float value of 41.1314 by 60 and get 6 significant digits because at no time should a float have to truncate any of those values.  Then I can print out the integer degrees value of 40 and then the fractional result from the 41.1314/60 calculation and all should be well.  What am I missing here?
70  Using Arduino / Programming Questions / Re: GPS logger works fine...as long as the serial data coming in isn't valid on: January 21, 2013, 02:23:16 pm
I think I've figured out what I was doing wrong, and as usual it is a face palm kind of problem.  I was mistaking the format that the GPS was spitting out (4041.4335 as an example) as 40 degrees, 41 minutes, 43.35 seconds but it appears that this is actually 40 degrees, 41.4335 minutes.  I am going to wait until I am driving around before I decide if this was truly the problem but in this format it does seem to put me within 20 yards or so of my house on google maps.
71  Using Arduino / Programming Questions / Re: printing floats without the leading '0' on fractional results on: January 21, 2013, 02:12:46 pm
The project is a GPS logger and I notice when I pick a spot on google maps it shows the GPS coordinates with 6 digits after the decimal point so for instance, the U.S. Post Office in my town is located at GPS coordinates:

Code:
40.666585,-74.115669

according to google maps.  I would like to be able to calculate to that same degree of precision with my GPS module but as I understand, arduino floats/doubles can only handle about 6-7 total digits which would mean 2-3 digits for the integer portion and 3 - 4 digits in the fractional portion.
72  Using Arduino / Programming Questions / Re: printing floats without the leading '0' on fractional results on: January 21, 2013, 01:59:41 pm
You can use dtostrf function to get the float into a string.
http://www.nongnu.org/avr-libc/user-manual/group__avr__stdlib.html#ga060c998e77fb5fc0d3168b3ce8771d42

Then, if the original float is in between 0 and 1, you trim one character from the left, the zero, out. Or trim all character to the left of the decimal separator out.

I'll have to study how do you manipulate strings with Arduino, but how is this for a start?

That's a good place to start and looks easy to implement.  Thanks!
73  Using Arduino / Programming Questions / printing floats without the leading '0' on fractional results on: January 21, 2013, 01:41:46 pm
I am sending values to Serial.print in the format:

Code:
Serial.print(Integer result);
Serial.println(fractional result);

So the number 40.43567 would be printed as:

Code:
Serial.print("40");
Serial.print(".43567");

but the numbers are represented by variables.  I am doing this to get more precision out of the float data type, peeling off the integer value and then calculating the fractional separately before combining them in my output for viewing.  The problem is that printing floats that are a fractional amount seems to be placing a zero in front of the decimal so:

Code:
.43567 gets printed as
0.43567

which means my output based on the two calls to Serial.print would look like:

Code:
400.43567

Is there a way to make it not print that leading zero on the fractional value?
74  Using Arduino / Programming Questions / Re: GPS logger works fine...as long as the serial data coming in isn't valid on: January 21, 2013, 12:28:19 pm
I'm not familiar with that hardware but it seems unlikely to me that an electrical failure would leave it basically working and with such a precise and consistent error in the results.

That would be my expectation as well, but I just can't figure out what may be causing this behavior.  As far as I can tell, these modules are basically designed to be plug and play.   smiley-confuse

The module that I am using is the Maestro A2035-H.

http://www.richardsonrfpd.com/resources/RellDocuments/SYS_28/Maestro_A2035_H_data_v11.pdf

Does anyone else have experience with this module?
75  Using Arduino / Programming Questions / Re: GPS logger works fine...as long as the serial data coming in isn't valid on: January 21, 2013, 10:46:37 am
I'm kinda thinking more and more that I have a defective unit.  I drove that route again and got the exact same track on google maps, even the places where the offset between the indicated track and the actual track suddenly jumps.  I'm logging the number of satellites used in the position calculation and it is never less than 7 which seems to me should provide a very precise location (within a few meters).  I then took it out on the freeway to see if perhaps a better line of sight would give better results.  The results are just as erratic in terms of the offset.  Crazy thing is that when I am sitting outside of my house, it is absolutely sure of my position in that it doesn't jump around.  I hooked it up wrong when I first started prototyping with it and for a short period of time was applying negative 1.7 volts to Vcc by accidently plugging the ground wire into the +5V arduino rail with Vcc hooked to the 3.3V arduino output.  Given that it was putting out data after I hooked it up correctly, I kind of figured that I must not have done any damage to the GPS module but perhaps I did and that is causing the erratic behavior.  Thoughts?
Pages: 1 ... 3 4 [5] 6 7 ... 18