Skip to content

Changes on the _chip_id #9

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
Apr 15, 2021
Merged

Changes on the _chip_id #9

merged 5 commits into from
Apr 15, 2021

Conversation

jposada202020
Copy link
Contributor

This is an attempt to solve #8.
When troubleshooting this, I found two solutions, first is removing the @property and using the _chip_id as a normal function.

However this solutions works better as we do not need to change the logic. I found that the problem was when trying to write .
This solve also the problem of resetting the device with the sensor connected as mention in the Adafruit earning guide.

As I cannot figure out why this work, please test, and feel free to reject this PR if this solution is not desired

I test this on

Adafruit CircuitPython 6.2.0-beta.3-188-g05ed179e1 on 2021-03-15; Adafruit Feather RP2040 with rp2040

@jposada202020 jposada202020 requested a review from a team April 14, 2021 12:58
@anecdata
Copy link
Member

Before PR:

Adafruit CircuitPython 6.2.0 on 2021-04-05; Adafruit MagTag with ESP32S2
>>> import board
>>> import adafruit_shtc3
>>> i2c = board.I2C()
>>> shtc3 = adafruit_shtc3.SHTC3(i2c)
>>> shtc3._chip_id
2119
>>> dir(shtc3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "adafruit_shtc3.py", line 112, in _chip_id
  File "adafruit_shtc3.py", line 112, in _chip_id
OSError: [Errno 19] Unsupported operation

After PR:

Adafruit CircuitPython 6.2.0 on 2021-04-05; Adafruit MagTag with ESP32S2
>>> import board
>>> import adafruit_shtc3
>>> i2c = board.I2C()
>>> shtc3 = adafruit_shtc3.SHTC3(i2c)
>>> shtc3._chip_id
2119
>>> dir(shtc3)
['__class__', '__dict__', '__init__', '__module__', '__qualname__', 'i2c_device', 'reset', 'temperature', '_buffer', 'low_power', 'sleeping', '_chip_id', '_write_command', '_cached_sleep', '_low_power', 'relative_humidity', 'measurements', '_crc8']

@ladyada
Copy link
Member

ladyada commented Apr 14, 2021

oof i feel like its risky to reset the chip when asking for the ID - the right thing to do is not let folks call _chip_id? we could remove the funciton

@jposada202020
Copy link
Contributor Author

@anecdata Thank you for testing :)
@ladyada agree with you, we could just remove it, but as you can see in


We already reset the sensor to get the ID number and verify that is in the I2C bus in the class constructor that is how I arrive to this proposal, but I could change the PR to remove the _chip_id function. Let me know. and thanks :)

@ladyada
Copy link
Member

ladyada commented Apr 14, 2021

yeah we should just move the chip id grabber into the init code

@jposada202020
Copy link
Contributor Author

will do Thanks

@jposada202020
Copy link
Contributor Author

This is my interpretation of the requested changes. Resetting the board with the sensor still work, open the possibility to remove the red warning in the learning guide. (to be tested by the person that made that guide)

Adafruit CircuitPython 6.2.0-beta.3-188-g05ed179e1 on 2021-03-15; Adafruit Feather RP2040 with rp2040
>>> import time
>>> import busio
>>> import board
>>> import adafruit_shtc3
>>> 
>>> i2c = busio.I2C(board.SCL, board.SDA)
>>> sht = adafruit_shtc3.SHTC3(i2c)
>>> 
>>> dir(sht)
['__class__', '__dict__', '__init__', '__module__', '__qualname__', 'i2c_device', 'reset', 'temperature', '_buffer', 'low_power', 'sleeping', '_chip_id', '_get_chip_id', '_write_command', '_cached_sleep', '_low_power', 'relative_humidity', 'measurements', '_crc8']
>>> 

Also tested with the simpletest

Adafruit CircuitPython 6.2.0-beta.3-188-g05ed179e1 on 2021-03-15; Adafruit Feather RP2040 with rp2040
>>> import shtc3_simpletest
Temperature: 25.1 C
Humidity: 43.7 %

Temperature: 25.2 C
Humidity: 43.7 %

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "shtc3_simpletest.py", line 17, in <module>
KeyboardInterrupt: 
>>> 

However one last thing, not getting the device id as @anecdata

I am getting

>>> sht._chip_id
2183

@ladyada
Copy link
Member

ladyada commented Apr 15, 2021

maybe try printing it in hex?
image

@jposada202020
Copy link
Contributor Author

you are right, 🤦🏼 , I changed the logic to get the right chip identifier.

Adafruit CircuitPython 6.2.0-beta.3-188-g05ed179e1 on 2021-03-15; Adafruit Feather RP2040 with rp2040
>>> import time
>>> import busio
>>> import board
>>> import adafruit_shtc3
>>> 
>>> i2c = busio.I2C(board.SCL, board.SDA)
>>> sht = adafruit_shtc3.SHTC3(i2c)
>>> 
>>> sht._chip_id
2055
>>> 

2055 = _SHTC3_CHIP_ID = 0x807

_SHTC3_CHIP_ID = 0x807

@ladyada ladyada merged commit f12e925 into adafruit:master Apr 15, 2021
@jposada202020 jposada202020 deleted the using_reset branch April 15, 2021 17:27
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Apr 17, 2021
Updating https://github.com/adafruit/Adafruit_CircuitPython_PCT2075 to 1.1.9 from 1.1.8:
  > Merge pull request adafruit/Adafruit_CircuitPython_PCT2075#16 from jposada202020/improving_docs
  > "Increase duplicate code check threshold "

Updating https://github.com/adafruit/Adafruit_CircuitPython_SHTC3 to 1.1.0 from 1.0.6:
  > Merge pull request adafruit/Adafruit_CircuitPython_SHTC3#9 from jposada202020/using_reset

Updating https://github.com/adafruit/Adafruit_CircuitPython_Thermistor to 3.3.6 from 3.3.5:
  > Merge pull request adafruit/Adafruit_CircuitPython_Thermistor#16 from jposada202020/improving_docs
  > "Increase duplicate code check threshold "

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bitmap_Font to 1.4.1 from 1.4.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_Bitmap_Font#44 from jposada202020/Including_examples_in_the_API

Updating https://github.com/adafruit/Adafruit_CircuitPython_BLE_Adafruit to 1.3.0 from 1.2.4:
  > Merge pull request adafruit/Adafruit_CircuitPython_BLE_Adafruit#12 from dhalbert/init-entry
  > "Increase duplicate code check threshold "

Updating https://github.com/adafruit/Adafruit_CircuitPython_LIFX to 1.10.0 from 1.9.5:
  > Merge pull request adafruit/Adafruit_CircuitPython_LIFX#11 from todbot/master
  > "Increase duplicate code check threshold "
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.

3 participants