cancel
Showing results for 
Search instead for 
Did you mean: 

convert char to double , GPS DATA

diegomerida20
Associate
Posted on March 20, 2016 at 01:17

I'm using the stm32f0 nucleo  and a gps module , I am able to receive data from the gps and i get the string below.

                                                                                

$GPGGA,000055.600,2853.3835,N,08113.7310,W,1,6,1.59,22.9,M,-31.3,M,,*59 

I used the following code to extract the latitud and longitud

char latitud[10];

 char longitud[10];

strncpy(latitud,in+18,9);

strncpy(longitud,in+30,9);

and i get this  :2853.3835  

                        08113.731� 

My question is how can I converter these char to doubles so i can manipulated the numbers and calculate the distance to another coordinate.

Any help or tip would be very appreciated, this is my first time working with microntrollers. In resume all I want is get my current location and calculate the distance to another coordinate using the haversine formula. Thank you so much

#gps
3 REPLIES 3
Posted on March 20, 2016 at 04:25

The longitude contains more characters, perhaps you want some bigger buffers. I'd parse the fields, not all receiver have the same character indexes, especially if they report time or position with more accuracy.

The C on the micro-controller, is the same as a PC, in regard to what you are trying to do. Suggest you experiment there first with the example sentences.

You can use the same sscanf() commands to do ''%lf'' doubles. With NMEA latitude and longitude, you need to decompose the numbers to get decimal degrees, as the numbers here are a mix of degrees and seconds. You also need to pay attention to the hemisphere each is in.

https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Issue%20with%20USART%20RX%20buffer%20and%20char%20filter&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=24...

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

More broken stuff? Hope you didn't pay the people who did the porting job.. @brk​ 

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

@Community member​ as you can see from the link which contains STe2ecommunities, this was a bad link from the first migration from SharePoint to Jive. The correct link is here: https://community.st.com/s/question/0D50X00009Xkh8gSAB/issue-with-usart-rx-buffer-and-char-filter