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

Mall Assistant Robot
Advanced
  • 355
  • 6

Create a Hospitality Robot that is capable of interacting with visitors at public spaces such as Malls, Rec Centers, Hospitals, Stadium etc.

BrainForce
Advanced
  • 698
  • 6

Full instructions

A wireless headset which allows you to control devices through cerebral waves. It works with two sensors and a Bluetooth shield.

Crazy Engineer’s Drawing Robot Arduino GRBL CoreXY Drawbot
Advanced
  • 4,515
  • 29

Full instructions

It is an Arduino, Customised GRBL, CoreXY, Servo and Stepper based CNC Drawbot that is Open Source and Open Hardware. It can draw or .......

Propeller Display
Advanced
  • 1,120
  • 10

This propeller display is mechanically scanned and displays the characters in digital format. Made from scrap it can be used anywhere.

Theragym
Advanced
  • 78
  • 2

Low cost robots to assist recovery of patients with non-traumatic brain injuries.

Theragym

Team Theragym

ERASynth
Advanced
  • 847
  • 3

Protip

An open-source, Arduino-compatible RF signal generator with Wi-Fi connectivity.

ERASynth

Team ERA Instruments

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login