Tiny library to parse Ublox7 and dtostrf to handle lat-long floats [Arduino Uno]

I was helped enormously by others in a former topic - in particular one commentator suggested that I use the dtostrf function to get the full Lat-Long decimal points. This I tried and managed to get a successful serial printout showing data with the expected layout in terms of columns, but no real GPS data (Figure 1).

Figure 1
0, 0.00000, 0.00000, 0, 0,
0, 0.00000, 0.00000, 0, 0,
0, 0.00000, 0.00000, 0, 0,
0, 0.00000, 0.00000, 0, 0,

My apologies if I have missed something very simple, but help would be greatly appreciated on ways of securing live data from the GPS [programme attached]. I should say that the GPS picks up and presents credible data using another programme.

/*
 * Rui Santos 
 * Complete Project Details http://randomnerdtutorials.com
 *Based on the example TinyGPS++ from arduiniana.org; adapted by CH
 *
 */
 
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <stdlib.h>
static const int RXPin = 8, TXPin = 9;
static const uint32_t GPSBaud = 9600;
TinyGPSPlus gps;// The TinyGPS++ object
SoftwareSerial ss(RXPin, TXPin);// The serial connection to the GPS device

//--------------------------dtostrf-insert---------------------------------------------
static float f_val1 = (gps.location.lat());///value of sensor [f-val]
static float f_val2 = (gps.location.lng());///value of sensor [f-val]
static char outstr1[15];//stors char. 
static char outstr2[15];//stors char.
int Alt;
int Sat;
int Date; 
//-------------------------------------------------------------------------------------

void setup(){
//------------------------------dtostrf-insert-----------------------------------------
  dtostrf(f_val1,7, 5, outstr1);//converts f-val(float)to a char array
  dtostrf(f_val2,7, 5, outstr2);//converts f-val(float)to a char array
  Alt = (gps.altitude.meters());
  Sat = (gps.satellites.value());
  Date = (gps.date.value());
  Serial.begin(9600);
  ss.begin(GPSBaud);///////////////from origional programme
 }
//-------------------------------------------------------------------------------------


void loop(){
  // This sketch displays information every time a new sentence is correctly encoded.
  while (ss.available() > 0){
//------------------------------dtostrf-insert-----------------------------------------
  Serial.print(Date);
  Serial.print(", ");
  Serial.print(outstr1);
  Serial.print(", ");
  Serial.print(outstr2);
  Serial.print(", "); 
  Serial.print(Sat);
  Serial.print(", "); 
  Serial.print(Alt);
  Serial.println(", ");
  delay(400); 
   
    }
  }

Sorry to be harsh, but you clearly don't understand how an Arduino program has to be organized.

Nothing in the code you posted will work as you intended, because large parts of the program are completely out of place, and are nonfunctional as a result.

Please take time to work through some of the basic examples that come with the Arduino IDE. Learn the purpose of the setup() and loop() functions, and the basic utilities supplied with Arduino.

EVERY LINE of a program has its proper place, so study working, recommended examples until you understand the organizing principles.

I can understand the use of dtostrf etc if you need to assemble a CSV style buffer of GPS co-ordinates for transmission via radio or similar.

But if you just want to print to serial monitor or log to SD card the location co-ordinates that the GPS is producing there are much easier ways.

Thank you both. I want to assemble bits of the GPS stream to sent to an SD card - and maybe to a Radiometrix.

My program was a bit of a stick-n-past, admittedly, but I shall follow your leads and get down to some basics. Many thanks. But , any specific pointers and leads from the community would be appreciated.

Colin.

bits of the GPS stream to sent to an SD card

That is very easy if you learn basic program organization first.

Starting with a working program that outputs the data to the serial monitor in the required format, the simplest approach is to change the Serial.print() statements to SD.print() statements.

Of course, in setup() you have to initialize the SD card, open or create the output file, etc.

There is a worked example here;

Program '28_GPS_Checker'

Reads a GPS with TinyGPS++, and prints to serial monitor;

GPS fix time, Latitude, Longitude, Altitude, Number of satellites in use and the HDOP value to the serial monitor.

And program '29_GPS_Checker_With_Display' prints to serial monitor;

Latitude, Longitude, Altitude, Number of satellites in use, the HDOP value, time and date

Both programs also spool the direct output of the GPS to the serial monitor too, so you can see what the GPS is actually putting out.

Easy to convert for printing to SD.

Thank you, Kama,

Much appreciated. I will follow up the file you quoted.

I did clean up my code, ditched the dtosrf sections and used the Tiny statements and got the following output [post edit of the GPS coordinates]:

40420, 54.003703, -1.011260, 0, 0.00
40420, 54.003004, -1.011266, 0, 0.00
40420, 54.003023, -1.011272, 0, 0.00
40420, 54.003031, -1.011273, 0, 0.00
40420, 54.003035, -1.011272, 0, 0.00

What puzzles me is that all my searches suggest that Arduino doesn't do floats - strange.

Does this result mean that I will be able to add data from sensors etc and send the batch to a Radiometrix? Apologies for bothering you.

Colin.

Suggest you study the use of Google, its a marvelous search engine.

Try this as a Google search for instance;

'Arduino reference float'

suggest that Arduino doesn't do floats

Which you know is nonsense, because your Arduino is "doing floats".

Perhaps you are confused by the fact that the original AVR-based Arduinos do not support double precision floating point arithmetic, commonly used in scientific applications.

Great! This will help me winnow out the relevant [from Google etc]. Thanks for your encouragement - eventually everything will click, I am certain.

Regards,

Colin.