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!

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

Give feedback

Comments

Similar projects you might like

Make an Autonomous "Follow Me" Cooler
Advanced
  • 8,899
  • 69

Full instructions

We use an Arduino to build an autonomous "follow me" cooler that connects to a smartphone via Bluetooth and uses GPS to navigate.

MEGA BREAD - Hank the Hexabot
Advanced
  • 258
  • 4

Work in progress

A 6 legged, 18 servo, self guiding time wasting project. MEGA BREAD series #7, Delivery and retrieval from the air project.

Kalam32 ESP32 Board as a Wireless WiFi/TCP ECG/Resp Monitor
Advanced
  • 565
  • 12

Protip

We interface one of our most popular Arduino shields, the ADS1292R ECG/Respiration shield, to ProtoCentral's new ESP32 platform.

Battle BLE Bot 9000
Advanced
  • 109
  • 2

Work in progress

Use a front-facing light to attack your opponent's side-mounted photoresistor. When your hit points drop to 0, you are dead!

Gorgy Meteo Clock
Advanced
  • 4,407
  • 30

Work in progress

My 'Gorgy' clock! Enhanced with an IR remote, a TFT display, a barometer, and a humidity and temperature sensor.

How to Build an Arduino Self-balancing Robot
Advanced
  • 268
  • 4

Full instructions

Tutorial on how to make an Arduino self-balancing robot. This robot uses an Arduino UNO or Nano, MPU6050, and an L293D motor driver.

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login
Feedback