2

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.

float to int issue

asked Sep 17, 2020 at 23:53
2
  • 2
    Please 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. Commented Sep 18, 2020 at 2:03
  • Covered up for privacy sake? You are sharing the same data below, with only a trivial transformation. Commented Sep 18, 2020 at 7:48

1 Answer 1

6

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.

Nick Gammon
38.9k13 gold badges69 silver badges125 bronze badges
answered Sep 18, 2020 at 0:00
2
  • 1
    I'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. Commented Sep 19, 2020 at 7:49
  • 1
    @NickGammon Wow. Thank you so much. Commented Sep 21, 2020 at 23:37

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.