Fill out above information andin all cases attach yourklippy.logfile (use zip to compress it, if too big). Pasting yourprinter.cfgis not needed Be sure to check our “Knowledge Base” Category first. Most relevant items, e.g. error messages, are covered there
Describe your issue:
Hi,
I have added a SHT21 sensor to my printer, and added this to my printer.cfg:
I have tried a lot of different iterations of the config, but I always get:
htu21d: Unknown Device ID 0x1
Unhandled exception during connect
Traceback (most recent call last):
File "/nix/store/h0v1gcg8dzpjwlz7jw2x5y3slqbxqp6n-klipper-0.12.0-unstable-2024-10-26/lib/klipper/klippy.py", line 135, in _connect
cb()
File "/nix/store/h0v1gcg8dzpjwlz7jw2x5y3slqbxqp6n-klipper-0.12.0-unstable-2024-10-26/lib/klipper/extras/htu21d.py", line 102, in handle_connect
self._init_htu21d()
File "/nix/store/h0v1gcg8dzpjwlz7jw2x5y3slqbxqp6n-klipper-0.12.0-unstable-2024-10-26/lib/klipper/extras/htu21d.py", line 140, in _init_htu21d
if self.deviceId != deviceId_list[0]:
~~~~~~~~~~~~~^^^
IndexError: list index out of range
Hi, 64 is the default (0x40), uncommented or commented makes no difference.
All commented fields make no difference uncommented, i just left them to show I have tried them.
The setups via the Linux host are always a bit fiddly. It usually has a lot of quirks, starting from the correct setup in the OS with its device tree overlays, through the userspace GPIO control libraries, up to Klipper.
I’d rather recommend using a small RP2040 board and hooking up your sensors there. Often, it’s a lot less problematic. For an example see Klipperize IFD-175 AP (prototype)
Why is it fiddly, though? The sensor works on the host, it’s just a weird python error in klipper for some reason. I don’t see why i’d expect to see anything different going through another intermediary?
diff --git a/klippy/extras/htu21d.py b/klippy/extras/htu21d.py
index ec44da633..c9325ac74 100644
--- a/klippy/extras/htu21d.py
+++ b/klippy/extras/htu21d.py
@@ -136,6 +136,8 @@ class HTU21D:
logging.info("htu21d: Found Device Type %s" % deviceId_list[0])
else:
logging.warning("htu21d: Unknown Device ID %#x " % rdevId)
+ # List is empty, it is required to forcing the type
+ deviceId_list = [rdevId]
if self.deviceId != deviceId_list[0]:
logging.warning(
IDK, if it is a real one STH21 and if that behavior is normal.
There is an issue in the code, so this is a duct tape patch here.
You have already defined an issue here, it is enough, thank you.
If you are willing to write a full-fledged patch, you can do that.
And send it as a PR.
If you can show the macro photo of the SHT21, that probably helps.
Because technically, that allows us to assume 0x1 as SHT21 in the code.
You can show us the fresh/patched log, so I can see the actual log output.
Probably lambda code, should be rewritten to totally avoid the situation with an empty ID.
Instead of my duct tape solution, where I know it is empty, I set it to “something”.
If you don’t do that, I can probably do that myself, and later will ask to test PR.
This was my thinking as well, and thanks for confirming that I did not totally misread the code.
Maybe the only reason for this could be differentiating various sensors of the same kind. However, this would still require different I2C addresses or buses to serve as a means of differentiation.
idk, seems like this code worked for others and for all clones of SHT21.
So, I would suggest just not to break anything.
But technically, yes, it seems that we can simply use the provided config value (which is actually happening already).
And just check that DevID is reading correctly, without direct verification of content.