I2Cexpander - A collection of I2C I/O devices
Another SPCoast Library
|
This library provides a common interface to a variety of I2C expanders, ADC/DAC devices and Arduino/Photon/Wemos/ESP platform-local pins.
The design philosophy is to abstract the setup and initialization of the various chipsets into an "init" function, and then provide high level "read" and "write" calls that do the right thing. It is built on top of the base Wire infrastructure, and coexists (but does not inter-operate) with other I2C device libraries.
This version is limited to a single I2C bus; it does not know how to manage/route through I2C muxes or switch between different MCU I2C appliances.
The digitalWrite/Read functions are convenience interfaces, but not very performant - You should use the Arduino provided ones for onboard pins if you need performance.
The support for PHOTON is rudimentary - their emulation of the Arduino environment is problematic.
It is based on an array of devices that can be read and written as desired. Instead of extending the digitalRead()/digitalWrite abstraction, I chose to read and write in units of 4,6, 8 or 16 bits, depending on the device in question.
In the model railroad community, this is slightly reminiscent of the Chubb CMRI system's design
To put this in context, this is part of a code-generated control system for a model railroad layout where there are many microcontrollers in use, one for every place on the layout where there are things to control.
My default program flow is
define each layout device (signal heads, turnout controllers, occupancy detectors,...) along with the particular bits are used to talk to it. loop() { read the layout state walk thru every device and ask it to update itself if anything changed, handle the side effects (i.e., track becomes occupied, signal needs to turn red...) if needed, update outputs (i.e., write new values) }
The list of supported I2C expanders is
Arduino wire I2C implementation
Written by John Plocher
Released under the terms of the MIT License (MIT)