Skip to content

Add wait for conversion #12

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 6 commits into from
Jul 10, 2018
Merged

Add wait for conversion #12

merged 6 commits into from
Jul 10, 2018

Conversation

caternuson
Copy link
Contributor

This adds a wait for conversion polling loop to fix #11

However, also refactored a lot of the boiler plate register read / write code into private funcs.

@caternuson caternuson requested a review from a team July 3, 2018 02:25
self.buf[1] = (value >> 8) & 0xFF
self.buf[2] = value & 0xFF
with self.i2c_device as i2c:
i2c.write(self.buf)
Copy link

Choose a reason for hiding this comment

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

Any reason for not using Adafruit_CircuitPython_Register?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just haven't used it yet. I'll take a look.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deferring this to a future PR.

self._write_register(ADS1X15_POINTER_CONFIG, config)
# Wait for conversion to complete
while not self._conversion_complete():
pass
Copy link

Choose a reason for hiding this comment

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

wouldn't be better to have time.sleep() instead of pass?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's the reason? Easy enough to do, just curious what the trade off is.

Copy link

Choose a reason for hiding this comment

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

I suppose it's a good practice from regular Python, where you want to give the control back to the operating system and other applications, instead of running it at 100%.
Perhaps it will also make a difference for SAMD at some point, when we get to the power management options.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gotcha. I figured pass took care of that. So is just a zero sleep good enough?

time.sleep(0)

i2c.write(self.buf, end=1, stop=False)
i2c.readinto(self.buf, start=1)
# LSB MSB
return self.buf[2], self.buf[1]
Copy link

Choose a reason for hiding this comment

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

This function is only used in one place, does it really make sense to have it?
Also, where it is used, we don't use the first byte of the result, does it really make sense to create a new tuple every time, especially since we do it in a tight loop?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yah, I was wondering about the tuple also. Basically it's just left over from first version of code. I was thinking of changing to just passing back an int. I'll take a look, I'm not sure why I can't just go ahead and do that.

I think having the function makes sense for any future expansion of functionality - it'll be the generic register read for whatever.

@caternuson caternuson merged commit 8a5cb46 into adafruit:master Jul 10, 2018
@caternuson caternuson deleted the wait_for_conversion branch July 10, 2018 21:16
tannewt pushed a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Jul 14, 2018
Updating https://github.com/adafruit/Adafruit_CircuitPython_ADS1x15 to 0.4.0 from 0.3.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_ADS1x15#12 from caternuson/wait_for_conversion

Updating https://github.com/adafruit/Adafruit_CircuitPython_Crickit to 2.0.2 from 2.0.1:
  > evaluate reversed immediately; otherwise get not hashable error
  > correct DRIVE order for steppers; improve stepper names
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.

ADC conversion timing issue for ADS1115
2 participants