So I am trying to take GPS data with a Neo 6M gpsmodule (that is what is covered up by the square for privacy sake) and process it by adding/multiplying to get large integers representing the GPS data. This is using Arduino nano. When I try and convert the float numbers to integers, it gives me totally different numbers. 1242895 turns into -2289, and 611194 turns into 21370. I have tried so many things, but am stumped as to what is going on. Is it related to pointing? It's been awhile since I learned about pointers in my C++ class. X and Y are initialized as int global variables.
-
2Please copy and paste your code here instead of posting a screenshot. A picture of some text is about the most useless thing on the internet. It can't be copied and edited. It's hard to read. Screen readers can't touch it. Please in the future just copy and paste the text itself.– Delta_GCommented Sep 18, 2020 at 2:03
-
Covered up for privacy sake? You are sharing the same data below, with only a trivial transformation.– Edgar BonetCommented Sep 18, 2020 at 7:48
Add a comment
|
1 Answer
On an Arduino board with the 328 processor, an INT is stored as a 2 byte value, so the max number is 32,767.
You want to use a LONG which is a 4 byte number which has a max of 2,147,483,647.
When the variable you are using is not big enough, the number rolls over, which is why you end up getting a negative number.
-
1I've fixed up the capitalization in your post, but in future please try to make English sentences. They start with a capital letter. This isn't a game chat where you just type in all lower-case.– Nick Gammon ♦Commented Sep 19, 2020 at 7:49
-
1