Things used in this project

Schematics

I2C INTERFERANCE
Master and Slave
Screenshot 2017 03 24 17 orflmlclhe

Code

MasterArduino
//This sketch created by Dimitris Kagioulis.You can modify it at your need.
//Library belongs to Kristian Sloth Lauszus

#include <PS3BT.h>
#include <Wire.h>


USB Usb;
BTD Btd(&Usb);
PS3BT PS3(&Btd);

int sensor1 = A0;
int sensor2 = A1;
int sensor3 = A2;

void setup() {

  Serial.begin(9600);
  Wire.begin();  // 0 adress of Master
  
  if (Usb.Init() == -1) {
    Serial.print(F("\r\nOSC did not start"));
    while (1); //halt
  }

 pinMode(sensor1, INPUT);
 pinMode(sensor2, INPUT);
 pinMode(sensor3, INPUT);
 
}

void loop() 
{

  long safety1 = digitalRead(sensor1);
  long safety2 = digitalRead(sensor2);
  long safety3 = digitalRead(sensor3);
  
  Usb.Task();

    char c = Serial.read();
  
  


  if (PS3.PS3Connected || PS3.PS3NavigationConnected) {

    if (PS3.getButtonPress(UP)) {
      if(safety1 == LOW){
    Wire.beginTransmission(1); // transmit to device #1
    Wire.write( 'A' );            
    Wire.endTransmission();    // stop transmitting

    Wire.beginTransmission(2); // transmit to device #2
    Wire.write( 'A' );            
    Wire.endTransmission();    // stop transmitting  
      }
        else if (safety1 == HIGH){
    Wire.beginTransmission(1); // transmit to device #1
    Wire.write( 'C' );            
    Wire.endTransmission();    // stop transmitting

    Wire.beginTransmission(2); // transmit to device #2
    Wire.write( 'C' );            
    Wire.endTransmission();    // stop transmitting
  }
    }
    else  if  (PS3.getButtonPress(DOWN)) {
    Wire.beginTransmission(1); // transmit to device #1
    Wire.write( 'B' );            
    Wire.endTransmission();    // stop transmitting

    Wire.beginTransmission(2); // transmit to device #2
    Wire.write( 'B' );            
    Wire.endTransmission();    // stop transmitting    
 
    }

       else  if  (PS3.getButtonPress(RIGHT)) {
        if(safety2 == LOW){
    Wire.beginTransmission(1); // transmit to device #1
    Wire.write( 'D' );            
    Wire.endTransmission();    // stop transmitting

    Wire.beginTransmission(2); // transmit to device #2
    Wire.write( 'D' );            
    Wire.endTransmission();    // stop transmitting    
        }
        else if (safety2 == HIGH){
    Wire.beginTransmission(1); // transmit to device #1
    Wire.write( 'C' );            
    Wire.endTransmission();    // stop transmitting

    Wire.beginTransmission(2); // transmit to device #2
    Wire.write( 'C' );            
    Wire.endTransmission();    // stop transmitting
        }
    }
        else  if  (PS3.getButtonPress(LEFT)) {
          if(safety3 == LOW){
    Wire.beginTransmission(1); // transmit to device #1
    Wire.write( 'E' );            
    Wire.endTransmission();    // stop transmitting

    Wire.beginTransmission(2); // transmit to device #2
    Wire.write( 'E' );            
    Wire.endTransmission();    // stop transmitting    
          }
        else if (safety3 == HIGH){
    Wire.beginTransmission(1); // transmit to device #1
    Wire.write( 'C' );            
    Wire.endTransmission();    // stop transmitting

    Wire.beginTransmission(2); // transmit to device #2
    Wire.write( 'C' );            
    Wire.endTransmission();    // stop transmitting   
        }
    }
     else  if  (PS3.getButtonPress(CIRCLE)) {
      
    Wire.beginTransmission(1); // transmit to device #1
    Wire.write( 'F' );            
    Wire.endTransmission();    // stop transmitting

    Wire.beginTransmission(2); // transmit to device #2
    Wire.write( 'F' );            
    Wire.endTransmission();    // stop transmitting 
      
     }
        else  if  (PS3.getButtonPress(SQUARE)) {
          
    Wire.beginTransmission(1); // transmit to device #1
    Wire.write( 'G' );            
    Wire.endTransmission();    // stop transmitting

    Wire.beginTransmission(2); // transmit to device #2
    Wire.write( 'G' );            
    Wire.endTransmission();    // stop transmitting 
     }
  else
  {
    Wire.beginTransmission(1); // transmit to device #1
    Wire.write( 'C' );            
    Wire.endTransmission();    // stop transmitting

    Wire.beginTransmission(2); // transmit to device #2
    Wire.write( 'C' );            
    Wire.endTransmission();    // stop transmitting
  }
 

   if (PS3.PS3Connected) {

      if (PS3.getButtonClick(PS)) {
        PS3.disconnect();
      }
    }
  
  }
  
  }

  
Slave 1Arduino
// Start the I2C Bus as Slave 1

#include <Wire.h>
void setup() 
{
  Wire.begin(1); // Adress 1
  Wire.onReceive(reciveEvent);

    //Setup Channel A
  pinMode(12, OUTPUT); //Initiates Motor Channel A pin
  pinMode(9, OUTPUT); //Initiates Brake Channel A pin

  //Setup Channel B
  pinMode(13, OUTPUT); //Initiates Motor Channel A pin
  pinMode(8, OUTPUT);  //Initiates Brake Channel A pin
}

void loop() 
{
}

void reciveEvent ( int howMany)
{
  char c = Wire.read();
  if ( c == 'A')
  {
     
  //Motor A forward @ full speed
  digitalWrite(12, HIGH); //Establishes forward direction of Channel A
  digitalWrite(9, LOW);   //Disengage the Brake for Channel A
  analogWrite(3, 200);   //Spins the motor on Channel A at full speed

  //Motor B forward @ full speed
  digitalWrite(13, HIGH); //Establishes forward direction of Channel B
  digitalWrite(8, LOW);   //Disengage the Brake for Channel B
  analogWrite(11, 200);   //Spins the motor on Channel B at full speed

  }
  else if ( c == 'B')
  {
  //Motor A backword @ full speed
  digitalWrite(12, LOW); //Establishes backword direction of Channel A
  digitalWrite(9, LOW);   //Disengage the Brake for Channel A
  analogWrite(3, 200);   //Spins the motor on Channel A at full speed

  //Motor B backword @ full speed
  digitalWrite(13, LOW); //Establishes backword direction of Channel B
  digitalWrite(8, LOW);   //Disengage the Brake for Channel B
  analogWrite(11, 200);   //Spins the motor on Channel B at full speed
  }

   else if ( c == 'D')
  {
  //Motor A backword @ full speed
  digitalWrite(12, LOW); //Establishes backword direction of Channel A
  digitalWrite(9, LOW);   //Disengage the Brake for Channel A
  analogWrite(3, 200);   //Spins the motor on Channel A at full speed

  //Motor B backword @ full speed
  digitalWrite(13, HIGH); //Establishes backword direction of Channel B
  digitalWrite(8, LOW);   //Disengage the Brake for Channel B
  analogWrite(11, 200);   //Spins the motor on Channel B at full speed
  }

  else if ( c == 'E')
  {
  //Motor A backword @ full speed
  digitalWrite(12, HIGH); //Establishes backword direction of Channel A
  digitalWrite(9, LOW);   //Disengage the Brake for Channel A
  analogWrite(3, 200);   //Spins the motor on Channel A at full speed

  //Motor B backword @ full speed
  digitalWrite(13, LOW); //Establishes backword direction of Channel B
  digitalWrite(8, LOW);   //Disengage the Brake for Channel B
  analogWrite(11, 200);   //Spins the motor on Channel B at full speed
  }
    else if ( c == 'F')
  {
  //Motor A backword @ full speed
  digitalWrite(12, LOW); //Establishes backword direction of Channel A
  digitalWrite(9, LOW);   //Disengage the Brake for Channel A
  analogWrite(3, 200);   //Spins the motor on Channel A at full speed

  //Motor B backword @ full speed
  digitalWrite(13, HIGH); //Establishes backword direction of Channel B
  digitalWrite(8, LOW);   //Disengage the Brake for Channel B
  analogWrite(11, 200);   //Spins the motor on Channel B at full speed
  }
  else if ( c == 'G')
  {
  //Motor A backword @ full speed
  digitalWrite(12, HIGH); //Establishes backword direction of Channel A
  digitalWrite(9, LOW);   //Disengage the Brake for Channel A
  analogWrite(3, 200);   //Spins the motor on Channel A at full speed

  //Motor B backword @ full speed
  digitalWrite(13, LOW); //Establishes backword direction of Channel B
  digitalWrite(8, LOW);   //Disengage the Brake for Channel B
  analogWrite(11, 200);   //Spins the motor on Channel B at full speed
  }
 else if ( c == 'C')
  {
     
      digitalWrite(8, HIGH);  //Engage the Brake for Channel B
      digitalWrite(9, HIGH);  //Engage the Brake for Channel A

  }

}
Slave 2Arduino
// Start the I2C Bus as Slave 2

#include <Wire.h>
void setup() 
{
  Wire.begin(2); // Adress 2
  Wire.onReceive(reciveEvent);

    //Setup Channel A
  pinMode(12, OUTPUT); //Initiates Motor Channel A pin
  pinMode(9, OUTPUT); //Initiates Brake Channel A pin

  //Setup Channel B
  pinMode(13, OUTPUT); //Initiates Motor Channel A pin
  pinMode(8, OUTPUT);  //Initiates Brake Channel A pin
}

void loop() 
{
}

void reciveEvent ( int howMany)
{
  char c = Wire.read();
  if ( c == 'A')
  {
     
  //Motor A forward @ full speed
  digitalWrite(12, HIGH); //Establishes forward direction of Channel A
  digitalWrite(9, LOW);   //Disengage the Brake for Channel A
  analogWrite(3, 200);   //Spins the motor on Channel A at full speed

  //Motor B forward @ full speed
  digitalWrite(13, HIGH); //Establishes forward direction of Channel B
  digitalWrite(8, LOW);   //Disengage the Brake for Channel B
  analogWrite(11, 200);   //Spins the motor on Channel B at full speed

  }
  else if ( c == 'B')
  {
  //Motor A backword @ full speed
  digitalWrite(12, LOW); //Establishes backword direction of Channel A
  digitalWrite(9, LOW);   //Disengage the Brake for Channel A
  analogWrite(3, 200);   //Spins the motor on Channel A at full speed

  //Motor B backword @ full speed
  digitalWrite(13, LOW); //Establishes backword direction of Channel B
  digitalWrite(8, LOW);   //Disengage the Brake for Channel B
  analogWrite(11, 200);   //Spins the motor on Channel B at full speed
  }

   else if ( c == 'D')
  {
  //Motor A backword @ full speed
  digitalWrite(12, LOW); //Establishes backword direction of Channel A
  digitalWrite(9, LOW);   //Disengage the Brake for Channel A
  analogWrite(3, 200);   //Spins the motor on Channel A at full speed

  //Motor B backword @ full speed
  digitalWrite(13, HIGH); //Establishes backword direction of Channel B
  digitalWrite(8, LOW);   //Disengage the Brake for Channel B
  analogWrite(11, 200);   //Spins the motor on Channel B at full speed
  }
    else if ( c == 'E')
  {
  //Motor A backword @ full speed
  digitalWrite(12, HIGH); //Establishes backword direction of Channel A
  digitalWrite(9, LOW);   //Disengage the Brake for Channel A
  analogWrite(3, 200);   //Spins the motor on Channel A at full speed

  //Motor B backword @ full speed
  digitalWrite(13, LOW); //Establishes backword direction of Channel B
  digitalWrite(8, LOW);   //Disengage the Brake for Channel B
  analogWrite(11, 200);   //Spins the motor on Channel B at full speed
  }
    else if ( c == 'F')
  {
  //Motor A backword @ full speed
  digitalWrite(12, HIGH); //Establishes backword direction of Channel A
  digitalWrite(9, LOW);   //Disengage the Brake for Channel A
  analogWrite(3, 200);   //Spins the motor on Channel A at full speed

  //Motor B backword @ full speed
  digitalWrite(13, LOW); //Establishes backword direction of Channel B
  digitalWrite(8, LOW);   //Disengage the Brake for Channel B
  analogWrite(11, 200);   //Spins the motor on Channel B at full speed
  }
    else if ( c == 'G')
  {
  //Motor A backword @ full speed
  digitalWrite(12, LOW); //Establishes backword direction of Channel A
  digitalWrite(9, LOW);   //Disengage the Brake for Channel A
  analogWrite(3, 200);   //Spins the motor on Channel A at full speed

  //Motor B backword @ full speed
  digitalWrite(13, HIGH); //Establishes backword direction of Channel B
  digitalWrite(8, LOW);   //Disengage the Brake for Channel B
  analogWrite(11, 200);   //Spins the motor on Channel B at full speed
  }
 else if ( c == 'C')
  {
     
      digitalWrite(8, HIGH);  //Engage the Brake for Channel B
      digitalWrite(9, HIGH);  //Engage the Brake for Channel A

  }

}

Credits

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Using OV7670 Camera Module With Arduino
Advanced
  • 798
  • 31

Protip

This is an Arduino camera module, using the surveillance camera's digital image processing chip-OV0706.

Using Nokia 3310 84x48 LCD with Arduino
Advanced
  • 6,632
  • 116

Protip

These 84 by 48 pixel LCDs are what you might have found in Nokia 3310. And what about using them in the Arduino projects?

A Sudoku Solver's Robot
Advanced
  • 2,491
  • 16

Full instructions

Sudoku-robot is a robot that solves and fills Sudoku grids!

Jrobot - Android and Arduino-Based Global Control Robot Car
Advanced
  • 2,078
  • 11

Jrobot adds wheels to mobile phone and makes it truly mobile. Jrobot on 4G has unlimited range and goes anywhere in the world.

Raspberry Pi - Powered Candy Dispenser
Advanced
  • 2,004
  • 11

Full instructions

Make a candy machine that can give candy with a push of a button or a tweet!

New Electronic Music Instrument Design
Advanced
  • 1,180
  • 7

A new piece for percussion quartet seeks to bring physicality to electronic music using two custom musical instruments.

Sign up / LoginProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlog