I'm trying to make project to monitor my home. I am using some gas sensors and temperature and humidity sensors. I want to do this wirelessly and I think the best thing to do that is XBee.
I use this code for the transmitter Arduino:
char dataPacket[64];
int gx = 1;
int gy = 321;
int gz = 456;
int ax = 654;
int ay = 789;
int az = 987;
int mx = 147;
int my = 258;
int mz = 369;
void setup(){
Serial.begin(9600);
}
void loop(){
sprintf(dataPacket, "X%d" ,gx);
// sprintf(dataPacket, "A%dB%dC%dD%dE%dF%dG%dH%dI%d", gx, gy, gz, ax, ay, az, mx, my, mz);
Serial.println(dataPacket);
}
gx gy gz .... these are the sensor reading variables
and in the receiving Arduino I use this code
void setup(){
// Start up our serial port, we configured our XBEE devices for 9600 bps.
Serial.begin(9600);
}
void loop()
{
if(Serial.available() > 0)
{
while(Serial.available() > 0)
{
char dataPacket[64];
for (int i = 0; i < 64; i++)
{
dataPacket[i] = Serial.read();
Serial.print(dataPacket[0]);
}
String show = Serial.readStringUntil('C') ;
delay(500);
}
}
}
but i can't split the values from the stream and put them into their variables (gx gy ...)
Does anyone have idea how to split it?