# I2C problem - received byte does not match sent byte

**URL:** <https://forum.arduino.cc/t/i2c-problem-received-byte-does-not-match-sent-byte/1461295>\
**Category:** Networking, Protocols, and Devices\
**Created:** [September 28, 2026, 2:18pm UTC](https://forum.arduino.cc/t/i2c-problem-received-byte-does-not-match-sent-byte/1461295 "2026-09-28T14:18:26Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgb](https://avatars.discourse-cdn.com/v4/letter/m/2bfe46/32.png) [@mgb](https://forum.arduino.cc/u/mgb)\
**Post date:** [September 28, 2026, 2:18pm UTC](https://forum.arduino.cc/t/i2c-problem-received-byte-does-not-match-sent-byte/1461295/1 "2026-09-28T14:18:26Z")

</div>

I have a simple master/slave with I2C to link 2 Nanos. The problem is that the slave sends the byte 100000 but the master receives 11111111

The 2 nanos are each connected to separate laptops which provide the power through the USB connectors

The master code is

```arduino
#include <Wire.h> 
byte ind_stalk_status;
long slave_poll_time = 0;
#define IND_STALK_ADDR 9

void setup(void) {
  Serial.begin(9600);
  Wire.begin();   
  Wire.setWireTimeout(3000, true);
}

void loop() {
  if (millis() - slave_poll_time > 1500) {
    slave_poll_callback();
    slave_poll_time = millis();
  }
}

void slave_poll_callback() {
  Wire.requestFrom(IND_STALK_ADDR, 1);
  byte ind_stalk_status = Wire.read(); // receive a byte
  Serial.print(F("slave_poll_callback: "));
  Serial.println(ind_stalk_status, BIN); // print the byte
}

```

This prints slave\_poll\_callback: 11111111 on each poll

Slave code

```arduino
#include <Wire.h> 

void setup() {
  Serial.begin(9600);
  Wire.begin(9); 
  Wire.setWireTimeout(3000, true);
  Wire.onRequest(requestEventReceived);
}

void requestEventReceived(int bytes) {
  byte ind_status;
  bitWrite(ind_status, 5, 1);
  Serial.print(F("requestEventReceived "));
  Serial.print(F("ind_status "));
  Serial.println(ind_status, BIN);
  Serial.flush();
  Wire.write(ind_status);
}

```

This prints requestEventReceived ind\_status 100000 on each request

---

<div class="post-metadata">

**Author:** ![anon94801460](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon94801460](https://forum.arduino.cc/u/anon94801460)\
**Post date:** [September 28, 2026, 2:28pm UTC](https://forum.arduino.cc/t/i2c-problem-received-byte-does-not-match-sent-byte/1461295/2 "2026-09-28T14:28:42Z")

</div>

> [@mgb](#):
>
> but the master receives 11111111

That value suggests a very basic communications error. Be sure to check function return values for error status, keeping in mind that the Arduino Wire library is not very robust.

---

<div class="post-metadata">

**Author:** ![SurferTim](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/surfertim/32/1072341_2.png) [@SurferTim](https://forum.arduino.cc/u/SurferTim)\
**Post date:** [September 28, 2026, 2:41pm UTC](https://forum.arduino.cc/t/i2c-problem-received-byte-does-not-match-sent-byte/1461295/3 "2026-09-28T14:41:40Z")

</div>

Don't you mean

```arduino
  byte ind_status = 0;

```

Edit: You aren't sending anything to the slave.

The slave is going to send one byte,.

---

<div class="post-metadata">

**Author:** ![mgb](https://avatars.discourse-cdn.com/v4/letter/m/2bfe46/32.png) [@mgb](https://forum.arduino.cc/u/mgb)\
**Post date:** [September 28, 2026, 2:47pm UTC](https://forum.arduino.cc/t/i2c-problem-received-byte-does-not-match-sent-byte/1461295/4 "2026-09-28T14:47:17Z")

</div>

I assume that byte ind\_status; will set the byte to 0 and the bitWrite(ind\_status, 5, 1) will change the byte to 100000

---

<div class="post-metadata">

**Author:** ![mgb](https://avatars.discourse-cdn.com/v4/letter/m/2bfe46/32.png) [@mgb](https://forum.arduino.cc/u/mgb)\
**Post date:** [September 28, 2026, 2:49pm UTC](https://forum.arduino.cc/t/i2c-problem-received-byte-does-not-match-sent-byte/1461295/5 "2026-09-28T14:49:11Z")

</div>

Doesn’t the fact that the return is 11111111 mean that the link returned a byte?

---

<div class="post-metadata">

**Author:** ![SurferTim](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/surfertim/32/1072341_2.png) [@SurferTim](https://forum.arduino.cc/u/SurferTim)\
**Post date:** [September 28, 2026, 2:49pm UTC](https://forum.arduino.cc/t/i2c-problem-received-byte-does-not-match-sent-byte/1461295/6 "2026-09-28T14:49:46Z")

</div>

I would not assume that. Set it to zero and see if it makes a difference.

Is the slave return the same every request?

---

<div class="post-metadata">

**Author:** ![mgb](https://avatars.discourse-cdn.com/v4/letter/m/2bfe46/32.png) [@mgb](https://forum.arduino.cc/u/mgb)\
**Post date:** [September 28, 2026, 2:51pm UTC](https://forum.arduino.cc/t/i2c-problem-received-byte-does-not-match-sent-byte/1461295/7 "2026-09-28T14:51:55Z")

</div>

Thanks, the print shows 100000 so the byte is being set correctly

---

<div class="post-metadata">

**Author:** ![SurferTim](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/surfertim/32/1072341_2.png) [@SurferTim](https://forum.arduino.cc/u/SurferTim)\
**Post date:** [September 28, 2026, 3:08pm UTC](https://forum.arduino.cc/t/i2c-problem-received-byte-does-not-match-sent-byte/1461295/8 "2026-09-28T15:08:20Z")

</div>

Here is my slave

```arduino
#include <Wire.h>
byte array[8] = {2,4,6,8,10,12,14,16};
volatile byte regReq = 0;
volatile byte* rtnPtr;

void setup()
{
  Wire.begin(13);
  Wire.onReceive(receiveEvent);
  Wire.onRequest(requestEvent);
}

void loop()
{

}

void receiveEvent(int byteCount)
{
  regReq = Wire.read();
}

void requestEvent()
{
  rtnPtr = &array[regReq*2];

  Wire.write((byte*)rtnPtr,2);
  rtnPtr += 2;
}

```

Here is my master

```arduino
#include <Wire.h>

void setup() {
  Serial.begin(115200);
  Wire.begin(); // join i2c bus (address optional for master)
}

byte x = 0;
int failCount = 0;

void loop() {
  Wire.beginTransmission(13); // transmit to device #13
  Wire.write(x); // sends one byte
  if(Wire.endTransmission() != 0)
    Serial.println("Write failed");

  delayMicroseconds(10);

  if(Wire.requestFrom(13, 2) == 2) { // request 2 bytes from slave device #13
    while(Wire.available()) // slave may send less than requested
    { 
      char c = Wire.read(); // receive a byte as character
      Serial.print(c,DEC); // print the character
      Serial.print(" ");
    }
    Serial.print(failCount);
    Serial.println();
  }
  else {
    Serial.println(F("Fail"));
    failCount++;
  }

  x++;

  if(x > 3) x = 0;

  delay(500);
}

```

---

<div class="post-metadata">

**Author:** ![GolamMostafa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/golammostafa/32/239011_2.png) [@GolamMostafa](https://forum.arduino.cc/u/GolamMostafa)\
**Post date:** [September 28, 2026, 3:25pm UTC](https://forum.arduino.cc/t/i2c-problem-received-byte-does-not-match-sent-byte/1461295/9 "2026-09-28T15:25:31Z")

</div>

> [@mgb](#):
>
> The problem is that the slave sends the byte 100000 but the master receives 11111111

**1.** Let us say that the I2C-Master requests the I2C-Slave to send 1-byte data (0x23) at 1-sec intervals.

**2.** Check that your NANO-Mater and NANO-Slave are connected as per Fig-1:

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/b/b/9/bb95450ab1ba6b9dc7f704417261e00f5fdb664d.png)  
Figure-1:

**3.** Upload the following sketches.  
**Master Sketch:**

```arduino
#include <Wire.h>
#define slaveAddr 0x09

void setup() {
  Serial.begin(9600);
  Wire.begin();
  //------------
  Wire.beginTransmission(slaveAddr);
  byte busStatus = Wire.endTransmission();
  if (busStatus != 0) {
    Serial.println("Slave is not found!");
    while (true)
      ;
  }
  Serial.println("Slave is found.");
}

void loop() {
  Wire.requestFrom(slaveAddr, 1);
  byte data = Wire.read();
  Serial.println(data, HEX); //shows: 23
  delay(1000);
}

```

**Slave Sketch:**

```arduino
#include <Wire.h>
#define slaveAddr 0x09

void setup() {
  Serial.begin(9600);
  Wire.begin(slaveAddr);
  //------------
  Wire.onRequest(sendEvent);
}

void loop() {
}

void sendEvent() {
  Wire.write(0x23);
}

```

**5.** Check that SM1 (Serial Monitor 1) shows 23 at 1-sec intervals.  
**6.** Replace 0x23 with 0xFF (11111111) and upload the Slave sketch.  
**7.** Check that SM1 shows FF (11111111).

---

<div class="post-metadata">

**Author:** ![mgb](https://avatars.discourse-cdn.com/v4/letter/m/2bfe46/32.png) [@mgb](https://forum.arduino.cc/u/mgb)\
**Post date:** [September 28, 2026, 4:21pm UTC](https://forum.arduino.cc/t/i2c-problem-received-byte-does-not-match-sent-byte/1461295/10 "2026-09-28T16:21:38Z")

</div>

Thanks, the significant difference is that you are using Wire.available(), I will that a try

---

<div class="post-metadata">

**Author:** ![mgb](https://avatars.discourse-cdn.com/v4/letter/m/2bfe46/32.png) [@mgb](https://forum.arduino.cc/u/mgb)\
**Post date:** [September 28, 2026, 4:24pm UTC](https://forum.arduino.cc/t/i2c-problem-received-byte-does-not-match-sent-byte/1461295/11 "2026-09-28T16:24:39Z")

</div>

I don’t have resisters on the I2C lines, I will give them a try

---

<div class="post-metadata">

**Author:** ![GolamMostafa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/golammostafa/32/239011_2.png) [@GolamMostafa](https://forum.arduino.cc/u/GolamMostafa)\
**Post date:** [September 28, 2026, 4:26pm UTC](https://forum.arduino.cc/t/i2c-problem-received-byte-does-not-match-sent-byte/1461295/12 "2026-09-28T16:26:57Z")

</div>

You must need pull-up resistors on the I2C bus as the lines are open-drain.

---

<div class="post-metadata">

**Author:** ![kmin](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kmin/32/1147370_2.png) [@kmin](https://forum.arduino.cc/u/kmin)\
**Post date:** [September 28, 2026, 4:46pm UTC](https://forum.arduino.cc/t/i2c-problem-received-byte-does-not-match-sent-byte/1461295/13 "2026-09-28T16:46:25Z")

</div>

> [@GolamMostafa](#):
>
> lines are open-drain.

I agree with external pullups, however doesn't Wire.begin activate internal ones?

---

<div class="post-metadata">

**Author:** ![GolamMostafa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/golammostafa/32/239011_2.png) [@GolamMostafa](https://forum.arduino.cc/u/GolamMostafa)\
**Post date:** [September 28, 2026, 5:33pm UTC](https://forum.arduino.cc/t/i2c-problem-received-byte-does-not-match-sent-byte/1461295/14 "2026-09-28T17:33:59Z")

</div>

> [@kmin](#):
>
> however doesn't Wire.begin activate internal ones

Internal pull-up is 20k - 50k, which offers very weak pull-up!

Adding external 2x4.7 k pull-up resistors from `SDA` and `SCL` to VCC provides enough current to ensure sharp, clean voltage transitions.

---

<div class="post-metadata">

**Author:** ![kmin](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kmin/32/1147370_2.png) [@kmin](https://forum.arduino.cc/u/kmin)\
**Post date:** [September 28, 2026, 5:47pm UTC](https://forum.arduino.cc/t/i2c-problem-received-byte-does-not-match-sent-byte/1461295/15 "2026-09-28T17:47:48Z")

</div>

I have never tried without external pullups.  
Question was if internals are automatically used or lines are open-drain.

---

<div class="post-metadata">

**Author:** ![SurferTim](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/surfertim/32/1072341_2.png) [@SurferTim](https://forum.arduino.cc/u/SurferTim)\
**Post date:** [September 28, 2026, 5:49pm UTC](https://forum.arduino.cc/t/i2c-problem-received-byte-does-not-match-sent-byte/1461295/16 "2026-09-28T17:49:49Z")

</div>

I always run the i2c\_scanner sketch to check the connection.

I use 5k pullups when I use a SAMD21 as the i2c slave.

---

<div class="post-metadata">

**Author:** ![anon94801460](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon94801460](https://forum.arduino.cc/u/anon94801460)\
**Post date:** [September 28, 2026, 7:26pm UTC](https://forum.arduino.cc/t/i2c-problem-received-byte-does-not-match-sent-byte/1461295/17 "2026-09-28T19:26:54Z")

</div>

> [@mgb](#):
>
> Doesn’t the fact that the return is 11111111 mean that the link returned a byte?

No, it just suggests that the input pullups are working on the receive end. There are several tested, functional examples of Arduino-to-Arduino communication via I2C posted on the web. Try one of those before writing your own code.

[This post on Wire](https://github.com/Koepel/How-to-use-the-Arduino-Wire-library/wiki/Explanation-of-the-functions-of-the-Wire-library) has helpful explanations, suggestions and warnings, e.g.

> [@](#):
>
> The function **Wire.requestFrom()** reads data. After it is finished, the received data is in a buffer (inside the Wire library). That data can be read with **Wire.read()**. The **Wire.available()** tells how many bytes are still in that buffer.
> 
> When there was a problem during the I2C bus activity, the received bytes up to that point are not reliable. With the Arduino Wire library it is not even possible to know if there are any reliable bytes before the bus error did happen. It is therefor better to first check for errors and if there are no errors, then read all the bytes.  
> Checking for errors might not be needed, see the [Check for bus errors ?](https://github.com/Koepel/How-to-use-the-Arduino-Wire-library/wiki/Check-for-bus-errors-%3F) page.

Finally, "separate laptops", if both powered from the AC line, can lead to noise problems with ground loops. Test using battery power only.

---

<div class="post-metadata">

**Author:** ![mgb](https://avatars.discourse-cdn.com/v4/letter/m/2bfe46/32.png) [@mgb](https://forum.arduino.cc/u/mgb)\
**Post date:** [September 29, 2026, 7:53am UTC](https://forum.arduino.cc/t/i2c-problem-received-byte-does-not-match-sent-byte/1461295/18 "2026-09-29T07:53:24Z")

</div>

I have 5 Nanos daisy chained together for the I2C bus. I'm not hot on the electronics side but will pull up resistors be required on only one Nano as the whole line will be pulled up

---

<div class="post-metadata">

**Author:** ![mgb](https://avatars.discourse-cdn.com/v4/letter/m/2bfe46/32.png) [@mgb](https://forum.arduino.cc/u/mgb)\
**Post date:** [September 29, 2026, 8:54am UTC](https://forum.arduino.cc/t/i2c-problem-received-byte-does-not-match-sent-byte/1461295/19 "2026-09-29T08:54:11Z")

</div>

Solved: Many thanks to all that helped, a pull-up resistor on the clock pin A5 did the trick. Originally I added a resistor to both A4 and A5 and the link wouldn’t work, as soon as I removed the one from A4, it started transmitting successfully

---

<div class="post-metadata">

**Author:** ![GolamMostafa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/golammostafa/32/239011_2.png) [@GolamMostafa](https://forum.arduino.cc/u/GolamMostafa)\
**Post date:** [September 29, 2026, 10:18am UTC](https://forum.arduino.cc/t/i2c-problem-received-byte-does-not-match-sent-byte/1461295/20 "2026-09-29T10:18:28Z")

</div>

> [@mgb](#):
>
> Solved:

This is not a solution!

You must be placing pull-up resistors for both lines of the I2C bus as per Fig-1 of post #9 along with common GND line connected between the NANOs.

Can you confirm to me that the sketches in post #9 work for you? If they work, then that is the solution.

[Next page](https://forum.arduino.cc/t/i2c-problem-received-byte-does-not-match-sent-byte/1461295.md?page=2)
