I2C Help

i just started messing with I2C and have got a push button and the example working but i was wondering how i could countrol 2 servos over I2c.
every time i try to get it to send 2 different values something stops working. im just using the example master_writer as a start.

thanx for any help.

Can you post what device you are sending it to. Each device needs a separate address.

every time i try to get it to send 2 different values something stops working

Can you explain this a bit more please. How have you got it wired up.
Servos require a PPM signal, can you get this out of your I2C device?

im just trying to use 2 arduinos. heres my code
all i need to figure out is how to spereate 3 valuse from the 1 string sent from the slave right now i cant even seperate the s1 from the number right.

Master code

// Wire Master Reader
// by Nicholas Zambetti <http://www.zambetti.com>

// Demonstrates use of the Wire library
// Reads data from an I2C/TWI slave device
// Refer to the "Wire Slave Sender" example for use with this

// Created 29 March 2006

#include <Wire.h>
int inbyte = 0;
void setup()
{
  Wire.begin(1);        // join i2c bus (address optional for master)
  Wire.onRequest(requestEvent); // register event
  Serial.begin(9600);  // start serial for output
}

void loop()
{
  inbyte = Serial.read();
  if (inbyte == 'a'){
   Wire.requestFrom(2, 5);    // request 6 bytes from slave device #2

  while(Wire.available())    // slave may send less than requested
  { 
    char c = Wire.receive(); // receive a byte as character
    if ( c == '255') {
    Serial.println("servo 255");
    }
    else {
    Serial.print(c);     // print the character
    }

  }

  
  }

}
void requestEvent()
{
  Wire.send("hello arduino I2C here 1"); // respond with message of 6 bytes
                       // as expected by master
}

Slave code

// Wire Slave Sender
// by Nicholas Zambetti <http://www.zambetti.com>

// Demonstrates use of the Wire library
// Sends data as an I2C/TWI slave device
// Refer to the "Wire Master Reader" example for use with this

// Created 29 March 2006

#include <Wire.h>
int inbyte = 0;
void setup()
{

  Wire.begin(2);                // join i2c bus with address #2
  Wire.onRequest(requestEvent); // register event
    Serial.begin(9600);  // start serial for output
}

void loop()
{
   inbyte = Serial.read();
  if (inbyte == 'a'){
   Wire.requestFrom(1, 24);   // request 6 bytes from slave device #2

  while(Wire.available())    // slave may send less than requested
  { 
    char c = Wire.receive(); // receive a byte as character
    if ( c == '1') {
    Serial.println();
    }
    else {
    Serial.print(c);     // print the character
  
}
  }
}
}
// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent()
{
  Wire.send("S1255"); // respond with message of 6 bytes
                       // as expected by master
}

You can't say:-

( c == '255')

single quotes designate a character and you have put a string inside it.
I am not sure what this is trying to do but there is no way you are actually sending any numbers, that could be why you are having trouble receiving them.

You are also doing a serial read without first checking that there is anything to read, you have to use serial available first and only if there is something to read should you read it.

Why are you using serial read inside the slave, that makes no sense.

I think you need to go through the worked examples and try to understand what is happening.

the serial read is just so it dont keep looping the data it is only sent when i call it.

[char c = Wire.receive(); // receive a byte as character
    if ( c == '255') {

and as you can see im sending my data through i2c not the serial port. but all i can get it to do is read 1 byte at a time. basicly im trying to control a servo over i2c with a pot.
turn pot on arduino 1 servo on arduino2 moves to that position

Your slave code includes this

Wire.requestFrom(1, 24);   // request 6 bytes from slave device #2

A slave can't request data from itself, and it can't request data from a master reader.

Try some simple code first then add to it.

Master Reader

// Wire Master Reader
// by Nicholas Zambetti <http://www.zambetti.com>

// Demonstrates use of the Wire library
// Reads data from an I2C/TWI slave device
// Refer to the "Wire Slave Sender" example for use with this

// Created 29 March 2006

#include <Wire.h>

void setup()
{
  Wire.begin(1);        // join i2c bus (address optional for master)
  Serial.begin(9600);  // start serial for output
}

void loop()
{
  Wire.requestFrom(2, 6);    // request 6 bytes from slave device #2

  while(Wire.available())    // slave may send less than requested
  { 
    char c = Wire.receive(); // receive a byte as character
    Serial.print(c);         // print the character
  }

  delay(500);
}

Slave Sender

// Wire Slave Sender
// by Nicholas Zambetti <http://www.zambetti.com>

// Demonstrates use of the Wire library
// Sends data as an I2C/TWI slave device
// Refer to the "Wire Master Reader" example for use with this

// Created 29 March 2006

#include <Wire.h>

void setup()
{
  Wire.begin(2);                // join i2c bus with address #2
  Wire.onRequest(requestEvent); // register event
}

void loop()
{
  delay(100);
}

// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent()
{
  Wire.send("S1255 "); // respond with message of 6 bytes
                       // as expected by master on #1
}

sorry to burst your bubble but you can read and send from both i have 2 sketches that do exactly what you say they cant.and it reads from the master at 1 and my slave is at 2

master

#include <Wire.h>
int inbyte = 0;
void setup()
{
  Wire.begin(1);        // join i2c bus (address optional for master)
  Wire.onRequest(requestEvent); // register event
  Serial.begin(9600);  // start serial for output
}

void loop()
{
  inbyte = Serial.read();
  if (inbyte == 'a'){
   Wire.requestFrom(2, 24);    // request 6 bytes from slave device #2

  while(Wire.available())    // slave may send less than requested
  { 
    char c = Wire.receive(); // receive a byte as character
    if ( c == '1') {
    Serial.println();
    }
    else {
    Serial.print(c);     // print the character
    }

  }

  
  }

}
void requestEvent()
{
  Wire.send("hello arduino I2C here 1"); // respond with message of 6 bytes
                       // as expected by master
}

slave

#include <Wire.h>
int inbyte = 0;
void setup()
{
  Wire.begin(2);        // join i2c bus (address optional for master)
  Wire.onRequest(requestEvent); // register event
  Serial.begin(9600);  // start serial for output
}

void loop()
{
  inbyte = Serial.read();
  if (inbyte == 'a'){
   Wire.requestFrom(1, 24);    // request 6 bytes from slave device #2

  while(Wire.available())    // slave may send less than requested
  { 
    char c = Wire.receive(); // receive a byte as character
    if ( c == '1') {
    Serial.println();
    }
    else {
    Serial.print(c);     // print the character
    }

  }

  
  }

}
void requestEvent()
{
  Wire.send("hello arduino I2C here 1"); // respond with message of 6 bytes
                       // as expected by master
}

all i did was combine the 2 sketches and it works no probs just upload and what board is hooked to serial port is the 1 that calls for the response just upload and send a in the serial monitor its the same on master and slave

the serial read is just so it dont keep looping the data it is only sent when i call it.

No a serial read will not hold until something is read, it will read what is in the buffer. If there is nothing in the buffer it will return a random rubbish character.

well when i upload the sketches it dont send anything to the serial monitor until i send the letter a . and that is what i was trying to do nothing more there. now i just wanna try to send the value from a pot to my slave

well when i upload the sketches it dont send anything to the serial monitor until i send the letter a

If you know it all then why are you stuck and refusing to listen.

i never said anything about knowing everything . in fact ill be the first to say i dont know a whole lot about the arduino but i do know you can send and recive from both master and slave with i2c and i did get my sketch to at least send the data when i want it to. now all im ASKING is if some one knows how to control a servo over i2c. just cause your grumpy and i dont know everything is no reason to say im refusing to listen when im just telling you waht i have done. and like i said in the first post

THANX FOR ANY HELP.