Sending 2 or more variables over I2C

I am connecting a NodeMCU with an Arduino UNO board with the I2C protocol. The Uno board will read Analog values and send them to the NodeMCU.

First I am trying to build a code to make sure I can send more than 1 value from the Arduino board to the NodeMCU. I decided to use an array to see if I could make this happen, but unfortunately I am not receiving the values I want.

I am using the NodeMCU as a master and the Arduino as a slave.

Code for Arduino (slave):

#include <Wire.h>

void setup() {
Wire.begin(8); /* join i2c bus with address 8 */

Wire.onRequest(requestEvent); /* register request event */

Serial.begin(9600); /* start serial for debug */

}

void loop() {
delay(100);
Serial.println();
}

// function that executes whenever data is requested from master
void requestEvent() {

byte x[2]={25,0};

Serial.println(x[0]);
Serial.println(x[1]);
Wire.write(x,2);

}

Code for NodeMCU (master):

#include <Wire.h>
#include <ESP8266WiFi.h>

void setup() {
Serial.begin(9600); /* begin serial for debug /
Wire.begin(D1, D2); /
join i2c bus with SDA=D1 and SCL=D2 of NodeMCU */

}

void loop() {
byte x[2];
Wire.requestFrom(8, 2); /* request & read data of size 2 from slave */
while(Wire.available()){
x [0] = Wire.read();
x [1] =Wire.read();
Serial.println(x[0]);
Serial.println(x[1]);

Serial.println();

delay(100);

}

The same code works when I send only one value (for example x=43;), Any suggestions can help, I am really just a beginner when it comes to programming.

Dont mind the emoji, its just an 8 and a )

Wire.begin ( 8 ) ;

and also the [0]

its just [ 0 ]

...or you could just use [code][/code] tags.

Dont mind the emoji

You mean "don't mind the dumbass that can't read the instructions and post code properly". Well, OK. Moving on to help someone that CAN.

On the master, why are you using a while loop to read two bytes? Why are you waiting for at least one byte, and then reading 2 as soon as one is available.

but unfortunately I am not receiving the values I want.

Don't you think it might be important to tell us what actually happens? "Not what I want" is completely useless information.

PaulS:
You mean "don't mind the dumbass that can't read the instructions and post code properly". Well, OK. Moving on to help someone that CAN.

On the master, why are you using a while loop to read two bytes? Why are you waiting for at least one byte, and then reading 2 as soon as one is available.
Don't you think it might be important to tell us what actually happens? "Not what I want" is completely useless information.

My way of thinking it was that inside the while loop, it would read the array of bytes, first storing in x[ 0 ] and then storing the next byte in x[ 1 ].

and then the "values I want". I just picked random numbers in the "slave" code. the array x is composed of numbers 25 and 0. When I send them to the NodeMCU and display them in the Serial monitor of the NodeMCU, instead of having 25 and 0 (what I want), I see 12 and 255.

PaulS:
You mean "don't mind the dumbass that can't read the instructions and post code properly". Well, OK. Moving on to help someone that CAN.

On the master, why are you using a while loop to read two bytes? Why are you waiting for at least one byte, and then reading 2 as soon as one is available.
Don't you think it might be important to tell us what actually happens? "Not what I want" is completely useless information.

As I said, I am a beginner coder and need help. Considering changing from I2C to Serial, or SPI, to see if I can send more than 2 variables from the Arduino to the NodeMCU in an easier way (codewise).

My way of thinking it was that inside the while loop, it would read the array of bytes, first storing in x[ 0 ] and then storing the next byte in x[ 1 ].

It would IF there were two bytes available to read. The body of the while loop is entered as soon as a byte arrives. There are not necessarily two bytes available to read, then, and it is poor practice to assume that there are.

while(Wire.available() < 2)
{
   // Do nothing
}
x[0] = Wire.read();
x[1] = Wire.read();