Skip to content

Clearer error printout for I2C communication error #13

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 4 commits into from
Mar 8, 2022
Merged

Clearer error printout for I2C communication error #13

merged 4 commits into from
Mar 8, 2022

Conversation

tekktrik
Copy link
Member

@tekktrik tekktrik commented Mar 8, 2022

Resolves #10 by:

  1. Transforming the OSError into a RuntimeError that explains that some commands are unavailable in working mode. Still mentions it as an I2C communication just in case it really is
  2. Referenced the datasheet to add the list of commands that should work while in working mode to the docstring of start_periodic_measurement() (and a reference to that in start_low_periodic_measurement()) to help clarify.

Not tested yet, but wanted to know if this is the right solution

@tekktrik tekktrik requested review from ladyada and caternuson March 8, 2022 18:12
@ladyada
Copy link
Member

ladyada commented Mar 8, 2022

looks ok to me @caternuson can also take a look

@caternuson
Copy link
Contributor

Oh yah, that issue. Thanks for picking this up and PRing a fix.

LGTM. Even tested. Did black change the long string message syntax to be multi-line? Looks like it's adding a bunch of white space.

BEFORE

Adafruit CircuitPython 7.1.1 on 2022-01-14; Adafruit ItsyBitsy M4 Express with samd51g19
>>> import board
>>> import adafruit_scd4x
>>> scd4x = adafruit_scd4x.SCD4X(board.I2C())
>>> scd4x.altitude
0
>>> scd4x.altitude = 42
>>> scd4x.altitude
42
>>> scd4x.start_periodic_measurement()
>>> scd4x.altitude
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/lib/adafruit_scd4x.py", line 284, in altitude
  File "/lib/adafruit_scd4x.py", line 307, in _send_command
OSError: [Errno 5] Input/output error
>>> 

AFTER

Adafruit CircuitPython 7.1.1 on 2022-01-14; Adafruit ItsyBitsy M4 Express with samd51g19
>>> import board
>>> import adafruit_scd4x
>>> scd4x = adafruit_scd4x.SCD4X(board.I2C())
>>> scd4x.altitude
42
>>> scd4x.start_periodic_measurement()
>>> scd4x.altitude
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/lib/adafruit_scd4x.py", line 302, in altitude
  File "/lib/adafruit_scd4x.py", line 329, in _send_command
RuntimeError: Could not communicate via I2C, some commands/settings                     unavailable while in working mode
>>>

@tekktrik
Copy link
Member Author

tekktrik commented Mar 8, 2022

Thanks for testing! I think I botched how I accounted for breaking up the string, this new commit should fix that whitespace.

@tekktrik tekktrik marked this pull request as ready for review March 8, 2022 21:05
@caternuson
Copy link
Contributor

Yep. Looks good:

Adafruit CircuitPython 7.1.1 on 2022-01-14; Adafruit ItsyBitsy M4 Express with samd51g19
>>> import board
>>> import adafruit_scd4x
>>> scd4x = adafruit_scd4x.SCD4X(board.I2C())
>>> scd4x.altitude
42
>>> scd4x.start_periodic_measurement()
>>> scd4x.altitude
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/lib/adafruit_scd4x.py", line 302, in altitude
  File "/lib/adafruit_scd4x.py", line 329, in _send_command
RuntimeError: Could not communicate via I2C, some commands/settings unavailable while in working mode
>>> 

@caternuson caternuson merged commit abb882e into adafruit:main Mar 8, 2022
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Mar 10, 2022
Updating https://github.com/adafruit/Adafruit_CircuitPython_SCD4X to 1.3.0 from 1.2.3:
  > Merge pull request adafruit/Adafruit_CircuitPython_SCD4X#13 from tekktrik/dev/clearer-i2c-failure
  > Fixed readthedocs build
  > Post-patch cleanup
  > Consolidate Documentation sections of README

Updating https://github.com/adafruit/Adafruit_CircuitPython_MIDI to 1.4.7 from 1.4.6:
  > Merge pull request adafruit/Adafruit_CircuitPython_MIDI#48 from tekktrik/dev/expose-velocity-attr
  > Fixed readthedocs build
  > Consolidate Documentation sections of README
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.

Guard against idle mode only methods?
3 participants