i am trying to communicate between ESP(master) and arduino nano(slave). This is only a prototype and all works fine. But i want to add multiple arduinos and therefor i need to detect if the arduino is connected.

I use the return function from wire.endTransmission as shown in i2c scanner to detect devices. But it doesnt work.

On the arduino i have this program:

#include <Wire.h>

const int16_t I2C_SLAVE = 0x22; // 0x22 = 34 cize izba 3(30)

void setup() {


void loop() {
  // put your main code here, to run repeatedly:


on the ESP i am trying this:

int error = Wire.endTransmission();


It returns only 2 (received NACK on transmit of address) Why? When i have other code on the slave (with onRecive and onRequest all works and comunicates)

Thank you.

  • you have two aduinos with the above program?
    – jsotola
    Commented Jul 22, 2020 at 20:26
  • 1
    Please show complete compilable programs for both Arduino and ESP
    – chrisl
    Commented Jul 22, 2020 at 22:40
  • Thank you guys.
    – Tomas
    Commented Jul 23, 2020 at 15:45

1 Answer 1


I'm a fool, I tried to detect other devices in the setup function before the Wire.begin(PIN_SDA, PIN_SCL, I2C_MASTER); I Found it only because of you. The rubber duck. I started to write the program down to post it here and bingo. That was the reason why the master had the "NACK" answer. The master was not started yet.

Thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.