Skip to content

Dallas 1-Wire temperature sensor #1

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

Merged
merged 5 commits into from
Dec 14, 2017
Merged

Dallas 1-Wire temperature sensor #1

merged 5 commits into from
Dec 14, 2017

Conversation

caternuson
Copy link
Contributor

@caternuson caternuson commented Dec 13, 2017

Uses CircuitPython OneWire to access the DS18X20

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple more comments! Thanks for your work on this.

README.rst Outdated
>>> ow_bus = OneWireBus(board.D2)
>>> ds18 = DS18X20(ow_bus, ow_bus.scan()[0])
>>> ds18.temperature
27.9375
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about removing the prompt so you can copy it all into a file to run? It'd also be good in a separate file under an examples folder as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I like the idea of examples folder. Allows for demonstrating other and more complex uses of the driver.

============

Contributions are welcome! Please read our `Code of Conduct
<https://github.com/adafruit/Adafruit_CircuitPython_DS18X20/blob/master/CODE_OF_CONDUCT.md>`_
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cookiecutter assumes the X should be capitalized but the github repo is lower case. Let me know which you want and lets make sure its consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's got with capital X.

self._device = OneWireDevice(bus, address)
self._buf = bytearray(9)
else:
raise Exception('Incorrect family code in device address.')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its generally bad to raise Exception because its subclassed by a bunch of things. That makes it hard to catch specific exceptions and not others.

I2CDevice raises a ValueError here. The built in list with explanations is here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, yeah, I was wondering about that and was just replicating some of what was already in the code. Should be a ValueError - but are you OK with the idea of raising an exception in general?

# configuration register
self._buf[2] = RESOLUTION.index(bits) << 5 | 0x1F
except ValueError:
raise Exception('Incorrect resolution.')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

_CONVERSION_TIMEOUT = const(1)
RESOLUTION = (9, 10, 11, 12)

class DS18X20(object):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to have object here. Its implicit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the linter wanted that. old style class vs. new style class.

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thank you for your awesome work on OneWire.

@tannewt tannewt merged commit 03e4ae0 into adafruit:master Dec 14, 2017
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

Successfully merging this pull request may close these issues.

2 participants