Skip to content

Arduino abstraction layer to support both Wire and SoftwareWire.

License

Notifications You must be signed in to change notification settings

pepaslabs/AnyWire

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 

Repository files navigation

AnyWire

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);

Screen Shot 2022-08-04 at 12 51 50 AM

IMG_1532

Caveats

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 address
  • setWireTimeout() when called with reset_with_timeout = true
  • getWireTimeoutFlag()
  • clearWireTimeoutFlag()
  • requestFrom() when called with a second "internal" address and size
  • flush()

License

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.

About

Arduino abstraction layer to support both Wire and SoftwareWire.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published