Skip to content

Instantly share code, notes, and snippets.

@biskandar
Created October 6, 2012 06:39
Show Gist options
  • Save biskandar/3844237 to your computer and use it in GitHub Desktop.
Save biskandar/3844237 to your computer and use it in GitHub Desktop.
Using I2C as Communication Link between Arduinos 2012010402
#include <Wire.h>
void setup() {
Serial.begin( 9600 ) ;
while ( !Serial ) ;
// run as I2C Slave with id = 1
int slaveId = 1 ;
Wire.begin( slaveId ) ;
// setup callback function
Wire.onReceive( onWireReceive ) ;
}
void loop() {
// nothing to do
}
void onWireReceive( int howMany ) {
while ( Wire.available() ) {
// print back all the characters
// into console terminal
char ch = Wire.read() ;
Serial.print( ch ) ;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment