Skip to content
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

Klipper SGP40 PR #4

Open
meteyou opened this issue Nov 23, 2024 · 3 comments
Open

Klipper SGP40 PR #4

meteyou opened this issue Nov 23, 2024 · 3 comments

Comments

@meteyou
Copy link

meteyou commented Nov 23, 2024

Currently their is an open PR for this sensor in Klipper with some questions:

I would be happy, when you support this, to get the Sensor merged in Mainline Klipper...

@thetic
Copy link
Owner

thetic commented Dec 28, 2024

I've ported the code from your PR to the https://github.com/thetic/klipper-sgp40/tree/upstream branch for testing. I am seeing the following error:

Unhandled exception during connect
Traceback (most recent call last):
  File "/home/pi/klipper/klippy/mcu.py", line 91, in _do_send
    return xh.get_response(cmds, self._cmd_queue, minclock, reqclock)
  File "/home/pi/klipper/klippy/serialhdl.py", line 506, in get_response
    raise error("Unable to obtain '%s' response" % (self.name,))
klippy.serialhdl.error: Unable to obtain 'i2c_read_response' response

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/klipper/klippy/printer.py", line 290, in _connect
    cb()
  File "/home/pi/klipper/klippy/extras/sgp40/__init__.py", line 48, in handle_connect
    self._init_sgp40()
  File "/home/pi/klipper/klippy/extras/sgp40/__init__.py", line 67, in _init_sgp40
    serial = self._write_command(SGP40_CMD["GET_SERIAL"], read_len=6,
  File "/home/pi/klipper/klippy/extras/sgp40/__init__.py", line 127, in _write_command
    params = self.i2c.i2c_read([], reply_len)
  File "/home/pi/klipper/klippy/extras/bus.py", line 250, in i2c_read
    return self.i2c_read_cmd.send([self.oid, write, read_len])
  File "/home/pi/klipper/klippy/mcu.py", line 96, in send
    return self._do_send([self._cmd.encode(data)], minclock, reqclock)
  File "/home/pi/klipper/klippy/mcu.py", line 93, in _do_send
    raise self._error(str(e))
klippy.gcode.CommandError: Unable to obtain 'i2c_read_response' response
BME280: Error reading data
Traceback (most recent call last):
  File "/home/pi/klipper/klippy/mcu.py", line 91, in _do_send
    return xh.get_response(cmds, self._cmd_queue, minclock, reqclock)
  File "/home/pi/klipper/klippy/serialhdl.py", line 506, in get_response
    raise error("Unable to obtain '%s' response" % (self.name,))
klippy.serialhdl.error: Unable to obtain 'i2c_read_response' response

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/klipper/klippy/extras/bme280.py", line 468, in _sample_bme280
    data = self.read_register("PRESSURE_MSB", 8)
  File "/home/pi/klipper/klippy/extras/bme280.py", line 865, in read_register
    params = self.i2c.i2c_read(regs, read_len)
  File "/home/pi/klipper/klippy/extras/bus.py", line 250, in i2c_read
    return self.i2c_read_cmd.send([self.oid, write, read_len])
  File "/home/pi/klipper/klippy/mcu.py", line 96, in send
    return self._do_send([self._cmd.encode(data)], minclock, reqclock)
  File "/home/pi/klipper/klippy/mcu.py", line 93, in _do_send
    raise self._error(str(e))
klippy.gcode.CommandError: Unable to obtain 'i2c_read_response' response

I believe this implementation is attempting to read the BME280's before they have been initialized.

@meteyou
Copy link
Author

meteyou commented Dec 29, 2024

your current mod use the get_handle overwrite, which should not be in the merged version. it also doesnt need the temp from the bme280. it will fallback to 25deg per default. i think it is more a timing issue in klipper/i2c reading.

@thetic
Copy link
Owner

thetic commented Dec 29, 2024

your current mod use the get_handle overwrite, which should not be in the merged version. it also doesnt need the temp from the bme280. it will fallback to 25deg per default. i think it is more a timing issue in klipper/i2c reading.

Are you referring to:

# Dirty way of using more retries
# This is harcoded in serialhdl.py in Klipper
def get_response(self, cmds, cmd_queue, minclock=0, reqclock=0):
retries = 15
retry_delay = 0.010
while 1:
for cmd in cmds[:-1]:
self.serial.raw_send(cmd, minclock, reqclock, cmd_queue)
self.serial.raw_send_wait_ack(cmds[-1], minclock, reqclock, cmd_queue)
params = self.last_params
if params is not None:
self.serial.register_response(None, self.name, self.oid)
return params
if retries <= 0:
self.serial.register_response(None, self.name, self.oid)
raise Exception("Unable to obtain '%s' response" % (self.name,))
reactor = self.serial.reactor
reactor.pause(reactor.monotonic() + retry_delay)
retries -= 1
retry_delay *= 2.0
self.i2c.i2c_read_cmd._xmit_helper.get_response = get_response
? This was inherited from the original nevermore max implementation. I just created a branch to remove that hack. I've confirmed that to boots without issue and I will continue testing it.

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

No branches or pull requests

2 participants