Library for extending the capabilities of an Arduino with other identical ones. Extension uses the Wire library under the hood to send messages to the different devices.
Devices must be wired to create an I2C bus. Here is an example using 2 slaves:
You should now be able to power the whole chain through the master.
Each slave device must be programmed using a unique id (i.e. I2C address). Here is what your slave code should look like:
#include "Extension.h"
void setup(){
Extension::slave(5) ; // use a different address for each slave
}
void loop(){
}
You can now program the master and extend it's capabilities through the slaves:
#include "Extension.h"
Extension sl1(5) ;
Extension sl2(6) ;
void setup(){
Serial.begin(9600) ;
sl1.pinMode(2, INPUT) ;
sl2.pinMode(2, INPUT) ;
}
void loop(){
byte v = sl1.digitalRead(2) ;
Serial.print("Pin 2 of slave 1 is: ") ;
Serial.println(v) ;
v = sl2.digitalRead(2) ;
Serial.print("Pin 2 of slave 2 is: ") ;
Serial.println(v) ;
// ...
}
- Download the latest release: https://github.com/patrickleboutillier/arduino-extension/releases
- Follow the Arduino IDE installation instructions: https://www.arduino.cc/en/guide/libraries
Extension supports the following methods that aim to behave exactly like their native Arduino counterparts:
- pinMode(PIN, MODE)
- VALUE = digitalRead(PIN)
- digitalWrite(PIN, VALUE)
- VALUE = analogRead(PIN)
- analogWrite(PIN, VALUE)