Using Arduino Mega

I have latitude and Longtitude from NMEA string. I have properly read the string and stored the required lat long in float variable.
In next step i have send these latitude and longitude to a device which is expecting these values in following format.

0 to 3 bytes --> Latitude (+/-180)
4 to 7 bytes --> longitude (+/- 180)
Device manual also says that the least significant bit of longitude is 360/2^32.

I need help in converting my float lat long in the required format. Looking for help please.

Regards

Did you mean "360 / 232" ?

Binary, or ASCII? Please post or provide a link to the device manual or at least, comms protocol. Little or big endian?

1 Like

Do you also need help in sending it, once it's converted? :slight_smile:

Yes

Serial.write() works fine for me. Device protocol is too lengthy and its not available online. I need to send in big endian format.

Have you tried the multiplier operator '*' ?

1 Like

@anon57585045 I can send it once it is converted. As i said Serial.write () works fine for me.
Sorry if i am not replying properly. I am new here. Thanks :blush:

Hello oss89

Why don't you send the position information in floating point data type?

Could it be because of this ?

In this case he has to use the multiplier operator '*' .

does this mean a 32 bit value where the upper 9 bits represent the integer value in degree (0-360 or -180-180) and the remaining 23-bits the fractional part of the angle?

a fixed point value. 2^23 * angle

Can you elaborate plz @paulpaulson and @anon56112670

@gcjr yes thats what i understood from the information given. Can you please how can i do it? I am using following code :

`Void packet()
  
  uint8_t LongitudeInt8[4];
  uint8_t LatitudeInt8[4];

  double scalingFactor = 180.0 * static_cast<double>(1UL << 23) / 360.0;

  int32_t LatitudeInt32 = static_cast<int32_t>(33.739757 * scalingFactor);
  LatitudeInt8[0] = static_cast<uint8_t>((LatitudeInt32 >> 24) & 0xFF);  // MSB (Big-Endian)
  LatitudeInt8[1] = static_cast<uint8_t>((LatitudeInt32 >> 16) & 0xFF);
  LatitudeInt8[2] = static_cast<uint8_t>((LatitudeInt32 >> 8) & 0xFF);
  LatitudeInt8[3] = static_cast<uint8_t>(LatitudeInt32 & 0xFF);  // LSB (Big-Endian)



  int32_t LongitudeInt32 = static_cast<int32_t>(72.849635 * scalingFactor);
  LongitudeInt8[0] = static_cast<uint8_t>((LongitudeInt32 >> 24) & 0xFF);  // MSB (Big-Endian)
  LongitudeInt8[1] = static_cast<uint8_t>((LongitudeInt32 >> 16) & 0xFF);
  LongitudeInt8[2] = static_cast<uint8_t>((LongitudeInt32 >> 8) & 0xFF);
  LongitudeInt8[3] = static_cast<uint8_t>(LongitudeInt32 & 0xFF);  // LSB (Big-Endian)'

look this over

  39.665920 13d53ce0  39.665920
 -78.815605 d8979a40 -78.815605
uint32_t  Q23 = 1L << (32-9);

float lat  = 39.6659213;
float lon = -78.8156087;

char s [80];
char t [80];
char u [80];

void
disp (
    float    latLong,
    int32_t  q23 )
{
    float  f = q23 * 1.0 / Q23;

    dtostrf (latLong, 10, 6, t);
    dtostrf (f,       10, 6, u);
    sprintf (s, " %10s %08lx %10s", t, q23, u);
    Serial.println (s);
}

void
setup ()
{
    Serial.begin (9600);

    int32_t  latQ23 = Q23 * lat;
    int32_t  lonQ23 = Q23 * lon;

    disp (lat, latQ23);
    disp (lon, lonQ23);
}

void
loop ()
{
}
1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.