Add I2C sensor passthrough client support#148
Merged
Merged
Conversation
Introduces a new `I2C` helper module for raw `/i2c_act` transactions via the UC2 GPIO slave, including convenience APIs for register reads/writes, bus scanning, and sensor-specific parsing for SHT45 and TSL2591. `UC2Client` now initializes this helper as `self.i2c`, and a new ESP32 test script was added to repeatedly read and print SHT45 temperature/humidity and TSL2591 light data.
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new raw I2C passthrough helper to the Python client so sensors connected to the UC2 CAN GPIO slave’s I2C bus can be accessed via /i2c_act, and wires this helper into UC2Client as self.i2c. Also includes a new ESP32-facing test script that repeatedly reads SHT45 and TSL2591 sensor values.
Changes:
- Add
uc2rest.i2c.I2Chelper with raw transactions, register helpers, bus scan, and SHT45/TSL2591 convenience reads. - Initialize the I2C helper in
UC2Client(self.i2c = I2C(self)). - Add a quick ESP32 test script to read/print SHT45 and TSL2591 data in a loop.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
uc2rest/UC2Client.py |
Imports and initializes the new I2C helper as part of the client API surface. |
uc2rest/i2c.py |
Implements the raw /i2c_act passthrough client + convenience sensor helpers. |
uc2rest/TEST/TEST_ESP32_I2CScans.py |
Adds a simple script to exercise the new I2C sensor reads over serial. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+59
to
+60
| if write: | ||
| payload["write"] = [int(b) & 0xFF for b in write] |
Comment on lines
+164
to
+167
| # Set gain + integration time. | ||
| self.write_register(addr, self._TSL_CMD | self._TSL_CONTROL, | ||
| (gain & 0x30) | (integration & 0x07), | ||
| node=node, timeout=timeout) |
Comment on lines
+2
to
+4
| import uc2rest | ||
| import numpy as np | ||
| import time |
| #port = "/dev/cu.SLAB_USBtoUART" | ||
| #port = "COM3" | ||
| port = "/dev/cu.SLAB_USBtoUART" | ||
| baudrate = 912600 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduces a new
I2Chelper module for raw/i2c_acttransactions via the UC2 GPIO slave, including convenience APIs for register reads/writes, bus scanning, and sensor-specific parsing for SHT45 and TSL2591.UC2Clientnow initializes this helper asself.i2c, and a new ESP32 test script was added to repeatedly read and print SHT45 temperature/humidity and TSL2591 light data.