Skip to content

Negative temperature unsigned integer issue #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
maha-haji opened this issue Dec 21, 2020 · 2 comments
Open

Negative temperature unsigned integer issue #7

maha-haji opened this issue Dec 21, 2020 · 2 comments
Assignees

Comments

@maha-haji
Copy link

I've seen some weird behavior with my sensor when it dips below freezing (< 32 deg F, < 0 deg C) whereby the temperature reading is around 654 C and less. After posting this issue to the Adafruit forum, a support member suggested it was an unsigned integer problem. Since temperature register in the device is a 16 bit 2's complement value in 100ths of a degree. A temperature of -1C would be stored in binary as 1111 1111 1001 1100. Interpreted as a signed integer that is -100. As an unsigned integer it would be 65436. Since the library takes the contents of the register and divides by 100 - which results in the 654 that I am seeing.

Is it possible to fix this library bug?

Thanks!

@ladyada
Copy link
Member

ladyada commented Dec 21, 2020

https://github.com/adafruit/Adafruit_CircuitPython_LPS35HW/blob/master/adafruit_lps35hw.py#L189

needs something like

if x > 32767:
  x -= 65536

@maha-haji can you try adding that pseudo code in the location indicated above and see if that helps

@jposada202020
Copy link
Contributor

@maha-haji changes were made in #8. Did you test this changes, let me know, thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants