Skip to content

Feat: Allow custom TwoWire object for multi-bus support #3

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

raomin
Copy link

@raomin raomin commented May 5, 2025

Description:

This PR enhances the ErriezBMX280 library to support using different I2C buses by allowing users to pass a custom TwoWire object (like Wire1 on ESP32 or Due) to the sensor constructor.
This change allows users with boards supporting multiple hardware I2C interfaces (like ESP32) to easily use multiple BMX280 sensors, even if they share the same I2C address, by connecting them to different buses.

Changes:

  • ErriezBMX280.h / ErriezBMX280.cpp:
    Added a new constructor overload ErriezBMX280(uint8_t i2cAddr, TwoWire *theWire).
    The original constructor now defaults to using the global Wire object.
    Internal I2C communication now uses the provided TwoWire pointer (_wire).

  • ErriezBMX280_TwoSensors.ino:
    Added a new example specifically for ESP32, demonstrating how to read from two BMX280 sensors connected to Wire and Wire1 respectively.

  • README.md:
    Updated the documentation and example code snippet to explain how to use the new constructor for custom I2C bus selection.

@Erriez
Copy link
Owner

Erriez commented May 7, 2025

@raomin Thanks for creating this PR. I like the idea of adding the overloaded constructor to use a custom TwoWire bus.

This is compatible with the original TwoWire, correct?

Unfortunately I do not have hardware available to test it, so I've executed the build script .auto-build.sh manually and is successful. This script also creates the Doxygen PDF automatically. The build script was used by Travis which no longer exists. I did not have time to convert this project to Github Actions.

The new example using two busses can only be tested on DUE and Lolin D32, so I've changed to:

function autobuild()
{
    # Set environment variables
    BOARDS_AVR="--board uno --board micro --board miniatmega328 --board nanoatmega328new --board pro16MHzatmega328 --board pro8MHzatmega328 --board megaatmega2560 --board leonardo"
    BOARDS_ARM="--board due"
    BOARDS_ESP="--board d1_mini --board nodemcuv2 --board lolin_d32"
    BOARDS_WIRE1="--board due --board lolin_d32"

    echo "Building examples..."
    platformio ci --lib="." ${BOARDS_AVR} ${BOARDS_ARM} ${BOARDS_ESP} examples/ErriezBMX280/ErriezBMX280.ino
    platformio ci --lib="." ${BOARDS_WIRE1} examples/ErriezBMX280_TwoSensors/ErriezBMX280_TwoSensors.ino

Can you include this?

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