String

Hello,

In TinyGPS program, I want to make a string which includes all parameter like as count, lng, lat, speed, altitude and time) . How can I do this string ?

#include "TinyGPS++.h"
#include "AltSoftSerial.h"

TinyGPSPlus gps;
AltSoftSerial altserial(8,7);// 8-Rx 9-Tx

void setup(){
  Serial.begin(9600);
  altserial.begin(9600);
  Serial.println("GPS Start");
}
void loop(){
  while(altserial.available() > 0)
  {
    gps.encode(altserial.read());
  }
  if(gps.location.isUpdated())
  {
    int sayi = gps.satellites.value();
    Serial.print("Satellite Count");
    Serial.print(gps.satellites.value());
    float boylam = gps.location.lng();
    Serial.print(" | Longitude:");
    Serial.print(gps.location.lng(),6);
    float enlem = (gps.location.lat());
    Serial.print(" | Latitude:");
    Serial.print(gps.location.lat(),6);
    Serial.print(" | Lat = ");
    Serial.print(lat);
    Serial.print(" | Speed MPH:");
    Serial.print(gps.speed.mph());
    Serial.print(" | Altitude Meter:");
    Serial.print(gps.altitude.meters());
    Serial.print(" | Time:");
    Serial.print(gps.time.value());
 
  }
}

sprintf

Why do you want to store all information in a string?

Because, I will send all data in a string by a transmitter. For this reason I want to create a string to send all data at once.

For this reason I want to create a string to send all data at once.

The data is sent in parallel?

AWOL:
The data is sent in parallel?

Depending on the radio protocol in use, it is often essential to send a complete string (or char array or whatever) without any gaps. Gaps can cause the fm sync to fail. Even if gaps are tolerated by using a suitable protocol, it is often desirable to keep the radio packet as short as possible for several reasons.

Depending on the radio protocol in use, it is often essential to send a complete string (or char array or whatever) without any gaps.

Serial I/O is usually buffered.

I will send data serially. I will use a transceiver module.But I thik that I must put a comma between each parameter (i.e lat value, lng value, time, etc) because it must be easy to separate in receiver side.

As AWOL noted, many interfaces are buffered, which means you can just write the pieces (separated by commas):

  transceiver.print( sats );
  transceiver.print( ',' );
  transceiver.print( lat, 6 );
    ...

Which transceiver and associated library are you using? They determine how you must send the message.

Cheers,
/dev

bmkaya:
Because, I will send all data in a string by a transmitter. For this reason I want to create a string to send all data at once.

That's not a reason to transmit data as text. You can place all data first in a byte array and next transmit that.

Maybe even neater is the use of a struct. If the receiver has the same endianness as as the transmitter, that will be extremely simple.

So, if I can different types of data which some of them ints, some of them chars, etc, how can I do string ? When I use struct command, how can I send this struct ?

Cheers.

When I use struct command, how can I send this struct ?

Depending on the library you are using, you might be able to do something like this:

    transceiver.write( (uint8_t *) &myStruct, sizeof(myStruct) );

This works for any struct that contains ints, floats, chars, or arrays of those things (no pointers).

At the receiving end, it would copy the received bytes back onto a structure in a similar way (depending on your transceiver and library). This is also called a "binary" message. As sterretje says, it requires the exact same structure definition on the sender and receiver.

It is more difficult to debug a binary message, so I usually recommend a text message first, like your comma-separated values message. These are easy to print and see on the Serial Monitor. Binary messages are all kinds of ugly on the Serial Monitor... you have to print the HEX values instead.

But if you didn't get the hint, "What transceiver and library are you using?"

Cheers,
/dev

What can I do to use printf and sprintf in Arduino software ?

printf prints to console; the arduino does not have one

sprintf works except for floats; use dtostrf to convert a float to string and next use the result in sprintf.

    float enlem = (gps.location.lat());
    Serial.print(" | Latitude:");
    Serial.print(gps.location.lat(),6);

Can't find out what type gps.location.lat() returns (I have poor internet connection at the moment) but if you want 6 decimal places (plus 3 whole number places) for a latitude / longitude then an Arduino 'float' will be no good to you, it only has 6-7 significant figures in total. So best to transmit these as strings.

Can't find out what type gps.location.lat() returns

class TinyGPSPlus
{
public:
  TinyGPSPlus();
  bool encode(char c); // process one character received from GPS
  TinyGPSPlus &operator << (char c) {encode(c); return *this;}

  TinyGPSLocation location;
struct TinyGPSLocation
{
   friend class TinyGPSPlus;
public:
   bool isValid() const    { return valid; }
   bool isUpdated() const  { return updated; }
   uint32_t age() const    { return valid ? millis() - lastCommitTime : (uint32_t)ULONG_MAX; }
   const RawDegrees &rawLat()     { updated = false; return rawLatData; }
   const RawDegrees &rawLng()     { updated = false; return rawLngData; }
   double lat();
   double lng();

OK, thanks, so it is just floats. With a four-byte float for lat & long that gives a resolution of about 100 metres worst case. Good enough for many applications I suppose.