Arduino abstraction layer to support both Wire and SoftwareWire.
Included in this repo are a local copy of SoftwareWire and a forked copy of HTU2xD_SHT2x_Si70xx, which has been modified to support AnyWire.
See the included demo.ino
, which reads from both hardware and software I2C sensors
("GY-21" breakout boards).
// an SHT21 sensor using hardware I2C:
HTU2xD_SHT2x_SI70xx hw_sht21(HTU2xD_SENSOR, HUMD_12BIT_TEMP_14BIT);
// an SHT21 sensor using software I2C:
uint8_t sw_sda_pin = 12;
uint8_t sw_scl_pin = 11;
SoftwareWire swire(sw_sda_pin, sw_scl_pin);
HTU2xD_SHT2x_SI70xx sw_sht21(HTU2xD_SENSOR, HUMD_12BIT_TEMP_14BIT, &swire);
Not all of the Wire API is supported by SoftwareWire. For the unsupported portions, AnyWire simply enters into an infinite loop:
bool AnyWire::getWireTimeoutFlag(void) {
if (_softwareWire) {
while (1) { __asm volatile(""); } // not supported
} else {
return Wire.getWireTimeoutFlag();
}
}
These include:
begin()
when called with an addresssetWireTimeout()
when called withreset_with_timeout = true
getWireTimeoutFlag()
clearWireTimeoutFlag()
requestFrom()
when called with a second "internal" address and sizeflush()
AnyWire.h
, AnyWire.cpp
and demo.ino
are copyright 2022 Jason Pepas,
released under the terms of the MIT License. See https://opensource.org/licenses/MIT.
SoftwareWire.h
and SoftwareWire.cpp
are copied from https://github.com/Testato/SoftwareWire,
which is GPL-3.0 licensed.
HTU2xD_SHT2x_Si70xx.h
and HTU2xD_SHT2x_Si70xx.cpp
are forked from https://github.com/enjoyneering/HTU2xD_SHT2x_Si70xx,
which is GPL-3.0 licensed.