0

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() {
  Wire.begin(I2C_SLAVE);  

}

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

}

on the ESP i am trying this:

Wire.beginTransmission(I2C_adress[adress]);
int error = Wire.endTransmission();

Serial.println(error);

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 Jul 22 at 20:26
  • 1
    Please show complete compilable programs for both Arduino and ESP – chrisl Jul 22 at 22:40
  • Thank you guys. – Tomas Jul 23 at 15:45
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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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