Skip to content

Conversation

@ito55
Copy link

@ito55 ito55 commented Oct 19, 2025

This PR introduces a new example sketch to demonstrate the use of the Unit Encoder with the M5Unified library. This is intended to offer a modern and unified way for users to integrate the Unit Encoder across different M5Stack host devices.

Status and Request for Collaboration

  • Status: The new example has been confirmed working on an M5Stack Core2 (tested by the author).
  • Request: Since this example utilizes M5Unified for cross-platform compatibility, I'd like to confirm its stability on at least one other M5Unified-supported host device before moving this PR out of draft status and requesting final review.

I kindly request the community to help confirm the operation on one other M5Unified host (e.g., Basic, M5StickC Plus, CoreS3, M5Paper, etc.).

Your confirmation (or bug report) in the comments would be greatly appreciated.

Changes Included

  • New example sketch for M5Unified integration.
  • Version bump to v0.0.3 in library.properties and library.json.

Quick way to get the code (for Testers)

To test this branch locally, please follow the steps appropriate for your environment.

  1. git clone https://github.com/ito55/M5Unit-Encoder
  2. cd M5Unit-Encoder
  3. git switch feature/example-m5unified

ito55 added 6 commits October 19, 2025 15:07
copied from Unit_Encoder_M5Core2
rename
cleanup comment
Place Serial.println(encoder_value) inside the conditional block (if statement) to print the value only when a change occurs.
This prevents continuous output and prints the encoder value only when it has been updated.
Fix: Display cutoff for values over 4 digits.
Replaced canvas.drawString with canvas.println/print for display output. This removes fixed coordinate dependencies, allowing for automatic text wrapping and easier porting to M5 controllers with different screen sizes.
cfg.clear_display = true;
cfg.serial_baudrate = 115200;
M5.begin(cfg);
sensor.begin();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When connecting the ATOMS3 and STM32F030F4P6 using the included cable, you may need to explicitly specify the pins.

    // G2=SDA, G1=SCL
    Wire.begin(2, 1);
    sensor.begin(&Wire);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ssknaoya, thank you for testing the operation with ATOMS3 and for sharing this valuable information. Since I don't own an ATOMS3, your cooperation is extremely helpful!

The fact that the I2C port had to be explicitly specified for ATOMS3 to function correctly suggests that we need to improve how the I2C port is designated.

While specifying Wire.begin(2, 1); might be the simplest solution for just the ATOMS3, as a sample sketch for a library, the ideal approach is to have common source code that works across different M5Unified controllers without hardware-specific port number designation.

I will look into ways to allow the current combination of M5Unified and the Unit Encoder library to operate without requiring explicit I2C port number specification.

Thank you again for the feedback!

Enhance the sample sketch to improve compatibility across M5Unified devices, specifically addressing the I2C initialization behavior on ATOMS3.
By ensuring the proper I2C context is available before `sensor.begin()`, the example now runs reliably on ATOMS3 and maintains compatibility with other controllers without device-specific pin declarations.
@ito55
Copy link
Author

ito55 commented Nov 1, 2025

@ssknaoya, I've implemented a fix based on your valuable feedback regarding the I2C initialization issue on ATOMS3. Thank you again for bringing that to my attention!
I believe this update resolves the need for explicit pin designation. Could you please confirm the operation of the Unit Encoder on your ATOMS3 using the latest sample sketch in this Pull Request?
The relevant commit is: a0eb37b f282b60
Your verification would be highly appreciated before merging this change.

ito55 added 4 commits November 2, 2025 12:26
Move Wire.begin() into the conditional block to correctly initialize either external or default I2C pins.

Simplify the sensor.begin() call to only take the Wire instance, removing redundant pin parameters. This improves code clarity and maintains device compatibility.
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.

2 participants