Master Slave Communication

Hello,

i want to use an Arduino Mega ADK as Master to Controll an Arduino UNO as Slave. I want the Mega to send datas via I2C to the uno. The Mega Recieves the Data via Serial Communication. The Data is separatet with letters. E.g c150b150v20 ... using the serial.parseInt command I'm extracting the number values and write them to my variables.
Further i want to send a part of this values to my slave Arduino. But somehow this dosen't work. Maybe anyone can help me. I've attached the Master and Slave Codes. Thank you

Master

#include<Wire.h>

String SendeDaten;
int x, y, z;
char xt[] = "x";
char yt[] = "y";
char zt[] = "z";


void setup() {
  Serial.begin(9600);
  Wire.begin();

}

void loop() {

  while (Serial.available() > 0) {
    x = Serial.parseInt();
    y = Serial.parseInt();
    z = Serial.parseInt();
  }

  String e = String(x);
  SendeDaten = String("x" + e );

  //Serial.println(SendeDaten);

  Wire.beginTransmission(4);
  Wire.write(SendeDaten.c_str());
  Wire.endTransmission();
  delay(100);

}

Slave

#include<Wire.h>
#include<LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

int x;

void setup() {
  Wire.onReceive(Empfangen);
  Wire.begin(4);
  pinMode(3,OUTPUT);

  lcd.begin(16,2);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Here we go");
}

void loop() {
  
  delay(100);
  analogWrite(3,x);
}

void Empfangen(int xy)
{
  while(Wire.available())
  {
    x = Wire.parseInt();
  }
  lcd.setCursor(0,0);
  lcd.print(x);
}

But somehow this dosen't work.

The code does something. It would be helpful to tell us exactly what it does.
You expect the code to do something. It would be helpful to tell us what you expect.

char xt[] = "x";
char yt[] = "y";
char zt[] = "z";

What are these for?

You send a String like "x14". Then, on the receiver end, you call parseInt() to read that data, expecting it to return a numeric value. What, given a string of "x14" do you expect to see returned? If you expect anything other than 0, it is your expectations that are wrong.

your code will most likely only receive one byte at a time before calling the parsing function. code executes fast, communication is slow. maybe add some delay(...) commands before parsing?

@PaulS, thank you for your answer.
In general i want the code extract the intergers from the data string the slave recieves.

My whole is projekt is about controlling serveral devices with the arduino. But i realised its to much for only one arduino.

I have a GUI (for now on the computer later as android application) that sends the comands as string to the mega. Like mentioned above the string (a10b20c30... ) the integers should be extracted and some of them should go to the slave arduino.

So my Question is actually. How can I send several values from the master to the slave device. An extract them again on the slave device

PC --a10b20c30d40 --> Arduino Mega Master -- b20c30--> Arduino Uno Slave

So my Question is actually. How can I send several values from the master

Put them in a string, and send the string.

An extract them again on the slave device

Once you have read the whole collection of bytes sent, add a NULL terminator to the array you stored them in, to make it a string. Then, parse the string, using strtok() or other means.

Usingsomedelimitersratherthanshovingeverythingtogethermakestokenizingthestringeasier.