Skip to content

ZeroDivisionError: division by zero on adafruit_tcs34725.py #14

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

Closed
asyzen opened this issue Nov 26, 2018 · 5 comments
Closed

ZeroDivisionError: division by zero on adafruit_tcs34725.py #14

asyzen opened this issue Nov 26, 2018 · 5 comments
Assignees

Comments

@asyzen
Copy link

asyzen commented Nov 26, 2018

On /usr/local/lib/python3.5/dist-packages/adafruit_tcs34725.py the function def color_rgb_bytes(self) should check if rgb values are greater than zero to avoid the division by zero exception

File "/usr/local/lib/python3.5/dist-packages/adafruit_tcs34725.py", line 240, in color_rgb_bytes
red = int(pow((int((r/clear) * 256) / 255), 2.5) * 255)
ZeroDivisionError: division by zero

@caternuson
Copy link
Contributor

@ladyada This is touching on the same part of the code that I stumbled upon in #10. Do you happen to have any insight as to where that math is coming from and/or what it's trying to do?
https://github.com/adafruit/Adafruit_CircuitPython_TCS34725/blob/master/adafruit_tcs34725.py#L240

@ladyada
Copy link
Member

ladyada commented Nov 27, 2018

@microbuilder knows this best!

@microbuilder
Copy link

Weird ... I know this chip fairly well and off the top of my head, I don't know what that code with the pow and 2.5 is doing! I'll have to dig into this a bit.

The div by zero check is valid in any case, though, and I can add that in ... but need to understand what's going on in that function first. That was part of the original commit from TonyD, and it's not obvious to me what the logic was.

@caternuson
Copy link
Contributor

Thanks for confirming weirdness! I read the datasheet and several ap notes and did not find anything with this math. If you figure out what's it's about, great. Otherwise, may not matter as it will likely go away with updated algorithm suggested by #15.

@caternuson
Copy link
Contributor

Fixed with #16

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