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.
// 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
#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
#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