Uh Oh It Go BOOM!

Stardate 98775.14

I am Captain Douglas Adams of the Andromeda Class Starship Heart of Stainless Steel.  It is a single person craft.  My exploration mission to M97 was delayed when a meteor shower caused the ship to crash.   After I woke up from the crash, I managed to salvage a few Arduino Controllers and connect the I2C bus together to start repairing the ship.   This mission was just me.  It is very dark.  I cannot even see the control boards around the ship.   My repairs started when I went below deck to fix the computer and controllers for the ship.  I still need to get to the back of the ship.  You can see off to the middle left of the front of the ship.

As you can see in the video log.  The I2C bus is working. I am counting to 6. Devices are 1 to 5 left to right. As the loop cycles, pin 13 LED turns on for each device. When it reaches 6, all 5 LEDs turn on.

The I2C bus connections are as follows

Ground: Green:  I connected both – bars on the bread board with a green cross over wire.   All I2C devices will need a common ground to work.

I2C uses SDA and SCL connections. 
SDA: Serial Data: Data moves here
SCL: Serial Clock: Clock sync here

Mega 2560:
SDA : pin 20
SCL: pin 21

Arduino Uno and Hero
SDA: pin A4
SCL: pin A5

The Arduino devices have 9V-1A power supplies to the reactor.  I have two of the UNO devices rigged up on battery power till I find the power supplies to the reactor.

The next project is creating the power and ground buses to the other control boards.   I also need to fix the two front LEDs.  

I configured the I2C bus so all 5 devices were connected to it.  LED 13 blinks from left to right 1 to 5.  On 6, all 5 devices have LED 13 light up.   I put the bread boards in a row above the 5 Arduino devices and connected the ground, SDA and SCL writes in a bus. 

Links to the code below:

Master

// Include the required Wire library for I2C

#include <Wire.h>
int x = 0;
int LED = 13;

void setup(){
pinMode (LED, OUTPUT);
// Start the I2C Bus as Master

Wire.begin();
}

void loop() {
x++; // Increment x

//From Left to Right
// First UNO
Wire.beginTransmission(1); // transmit to device #1
Wire.write(x); // sends x
Wire.endTransmission(); // stop transmitting

//Second UNO
Wire.beginTransmission(2); // transmit to device #2
Wire.write(x); // sends x
Wire.endTransmission(); // stop transmitting

//Mega in the Middle

//Third UNO
Wire.beginTransmission(3); // transmit to device #3
Wire.write(x); // sends x
Wire.endTransmission(); // stop transmitting

//Fourth UNO
Wire.beginTransmission(4); // transmit to device #4
Wire.write(x); // sends x
Wire.endTransmission(); // stop transmitting

if (x == 3) {
digitalWrite(LED, HIGH);
}
else {
digitalWrite(LED, LOW);
}

if (x == 6) {
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
}

if (x > 7) x = 0; // `reset x once it gets 6
delay(500);

}

Slave 1

#include <Wire.h>
int LED = 13;
int x = 0;

void setup() {
pinMode (LED, OUTPUT);
// Start the I2C Bus as Slave on address 1
Wire.begin(1);
// Attach a function to trigger when something is received.
Wire.onReceive(receiveEvent);
}
void receiveEvent(int bytes) {
x = Wire.read(); // read one character from the I2C
}

void loop() {
if (x == 1) {
digitalWrite(LED, HIGH);
}
else {
digitalWrite(LED, LOW);
}

if (x == 6) {
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
}

}

Slave 2

#include <Wire.h>
int LED = 13;
int x = 0;
void setup() {
pinMode (LED, OUTPUT);
// Start the I2C Bus as Slave on address 2
Wire.begin(2);
// Attach a function to trigger when something is received.
Wire.onReceive(receiveEvent);
}
void receiveEvent(int bytes) {
x = Wire.read(); // read one character from the I2C
}

void loop() {
if (x == 2) {
digitalWrite(LED, HIGH);
}
else {
digitalWrite(LED, LOW);
}

if (x == 6) {
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
}

}

Slave 3

#include <Wire.h>
int LED = 13;
int x = 0;
void setup() {
pinMode (LED, OUTPUT);
// Start the I2C Bus as Slave on address 3
Wire.begin(3);
// Attach a function to trigger when something is received.
Wire.onReceive(receiveEvent);
}
void receiveEvent(int bytes) {
x = Wire.read(); // read one character from the I2C
}

void loop() {
if (x == 4) {
digitalWrite(LED, HIGH);
}
else {
digitalWrite(LED, LOW);
}

if (x == 6) {
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
}

}

Slave 4

#include <Wire.h>
int LED = 13;
int x = 0;
void setup() {
pinMode (LED, OUTPUT);
// Start the I2C Bus as Slave on address 4
Wire.begin(4);
// Attach a function to trigger when something is received.
Wire.onReceive(receiveEvent);
}
void receiveEvent(int bytes) {
x = Wire.read(); // read one character from the I2C
}

void loop() {
if (x == 5) {
digitalWrite(LED, HIGH);
}
else {
digitalWrite(LED, LOW);
}

if (x == 6) {
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
}

}