Pages: [1]   Go Down
Author Topic: Arduino to Arduino I2C Question  (Read 497 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
// 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:
#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:
#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
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 220
Posts: 13846
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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

Rob Tillaart

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

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Exactly what I was looking for
Logged

Pages: [1]   Go Up
Jump to: