Go Down

Topic: Arduino to Arduino I2C Question (Read 555 times) previous topic - next topic

riaanhar

I have Arduino to Arduino transmission working, I can send a command and it works but only on the one character.How can I send the following information.

I need to send information like B101P255 where the protocol is broken up further
B1                   O1                   P                     255
B1 = board no / O1 = Output 1 / P = pwm mode /000 - 255 = pwm val
Also have other command like
IR01
IR                    01
IR = Infrared     command 01
and more

I have converted the Integers into a string to form the commands above.
I have also converted the string to a Char for sending via udp.
That is all working.

But on the I2C slave I only receive the first character. ie I or B from the complete message.


Code: [Select]

// on master
void Data()
{

Message.toCharArray(ReplyBuffer, 10);
Serial.print(ReplyBuffer);//Serial.print(pwmlbl);//Write notification
Udp.beginPacket(ServerIP, ServerPort);
Udp.write(ReplyBuffer); // Send Message back to iPhone
Udp.endPacket();
Wire.beginTransmission(5);
Wire.write(ReplyBuffer);
Wire.endTransmission();
}

The ReplyBuffer contains the correct information


Code: [Select]

#include <Wire.h>
void setup()

{
  Wire.begin(5);
  Wire.onReceive(receiveEvent);
}

void loop(){}

while(Wire.available())
{
  char c = Wire.read();
  if(c == 'IR01'){command}
  else if (c == 'B101P255'){command}
}
}


What can I do to get the whole message?

Then can I use charAt(n) to find the numbers and conver the back to int's for use int the rest of the sketch?

I don't know if the following will work and how it will work
Code: [Select]

#include <Wire.h>
Wire.begin(); // Join the I2C bus as Master (Address 0)
Wire.begin(2); // Join the I2C bus as Master (Address 2)

Wire.beginTransmission(2); // Transmit to device 2
// Transmit 6 bytes of outgoing:
Wire.write(outgoingByte[0]);
Wire.write(outgoingByte[1]);
Wire.write(outgoingByte[2]);
Wire.write(outgoingByte[3]);
Wire.write(outgoingByte[4]);
Wire.write(outgoingByte[5]);

Wire.endTransmission();


// Receive Data:
Wire.requestFrom(2,2);
incomingByte[0] = Wire.read();
incomingByte[1] = Wire.read();



Can someone please recommenced the best method

Thanks

robtillaart


have you read this one - http://arduino.cc/en/Tutorial/MasterWriter -
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

riaanhar

Thanks Exactly what I was looking for

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy