Ain’t that the truth!
Me, the silly boy that I am, decided to work on updating the “remote camera robot” code that comes with the robot, so that it uses a joystick instead of a mouse. Should be simple, right?
WRONG!
I found myself taking a “crash” course in not only Python, (which I had, maybe, twenty hours experience with), but also Python web services, browser side web polling and web push, JavaScript, and a few other things that I don’t remember right now - probably selective amnesia.
How did I feel about this?
Does this answer your question?
Nope. It’s not always easy, but like my trainer at the fitness club says “No Sweat, No Glory”.
The problem you seem to be experiencing is that the software, for whatever reason, is not handling signed numbers correctly.
For example, in “computer speak” numbers work like this:
If the highest bit is a “1”, than the number is in negative two’s complement form. (these are signed 32 bit integer numbers)
“0d” = a decimal number and “0x” = a hexadecimal number.
[decimal] becomes [hexadecimal]
0d0015 0x00 00 00 FF
0d0014 0x00 00 00 FE
0d0013 0x00 00 00 FD
[. . .]
0d0003 0x00 00 00 03
0d0002 0x00 00 00 02
0d0001 0x00 00 00 01
0d0000 0x00 00 00 00
0d-0001 0xFF FF FF FF
0d-0002 0xFF FF FF FE
0d-0003 0xFF FF FF FD
and so on.
0xFF FF FF FF - after you take the two’s complement - becomes 0x00 00 00 01. Because the highest bit is set, you add a minus sign, therefore it becomes -1.
If it were an unsigned 32 bit integer, it would become 4,294,967,295 - which is obviously not the same as “-1”.
You can see, (by looking at this), that the obvious problem is that Python doesn’t know that the number you’re getting from the sensor is a signed floating-point number. Instead, it thinks it’s an unsigned integer which gives you the bizarre numbers.
You should also notice that, as the sensor gets colder, that large number gets smaller.
I do not know, (nor do I care), how negative floating point numbers are handled in Python - that’s a whole college course unto itself - and you don’t need to know either. Python handles that for you behind the scenes.
What you DO have to know is how to tell Python that the number you’re getting from the sensor is a float (floating point) number, and Python will do the rest, converting the numbers into a form that makes sense.
You also need to look at the data sheet so that you can understand the kinds of values that this sensor is giving you. Once you understand that, you can tell Python how to make sense of it.
Exactly how to do that in your particular case is a challenge you will need to accept for yourself.
Let us know what you discover!