logo elektroda
logo elektroda
X
logo elektroda

How to start i2c communication between NodeMcu and Wemos D1?

omnixcrs 1179 15
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 18474243
    omnixcrs
    Level 11  
    Welcome,

    colleagues I am running out of ideas for the above problem. I have been trying for a few hours to get i2c communication working between the NodeMcu and the Wemos D1 mini.
    I have connected both boards with ground and d1 to d1 and d2 to d2. Of course the lines pulled up to the power supply via 4k7. Node as master and Wemos as slave. Unfortunately after uploading the programs in the ports monitor nothing !
    I paste the codes, they are almost finished examples, maybe I have rewritten something wrong.

    Master to node code:
    Code: C / C++
    Log in, to see the code
    .

    code to slave Wemos:
    Code: C / C++
    Log in, to see the code
    .
  • ADVERTISEMENT
  • #2 18474289
    khoam
    Level 42  
    The Wire.endTransmission() function returns a value of 0 if the transmission was successful. Returns a value greater than zero if any error occurred. Verify this first.
  • ADVERTISEMENT
  • #3 18474311
    omnixcrs
    Level 11  
    function returns value 2

    Added after 11 [minutes]:

    I've connected an arduino nano instead of wemos for testing, removing the line "Wire.begin(D2, D1);" and it works without a problem, I suspect that this is where the problem will be with this addressing or pin setting, maybe it writes wrong ???
    I have also tried writing in this form: " Wire.begin(D2,D1,8); " and also nothing.
  • ADVERTISEMENT
  • Helpful post
    #4 18474382
    khoam
    Level 42  
    This code means that " received NACK on transmit of address ". The master sent the slave address, but did not receive an acknowledgement, the slave with this address did not report - the master "does not see" the slave with this address. The reasons for such an error can unfortunately be many.
    NACK - Negative Acknowledgement.
    https://www.arduino.cc/en/Reference/WireEndTransmission

    Additionally in the slave code is:
    Code: C / C++
    Log in, to see the code
    It would be better to write simply:
    Code: C / C++
    Log in, to see the code
    .
  • #5 18474388
    omnixcrs
    Level 11  
    As I wrote above I also used: "Wire.begin(D2, D1, 8);" and it did not do anything.
    I read somewhere that esp 12 does not have the option to work in SLAVE mode is it possible ???
    I connected another esp instead of WEMOSA, namely another NodeMcu and also nothing.
  • Helpful post
    #6 18475388
    khoam
    Level 42  
    The situation is as follows:
    In the HAL 2.5.2 version for the ESP8266, master-slave communication over I2C works, albeit with minor errors and transmission repetitions - I checked this with your code from the first post, using the NodeMCU and the Wemos D1 mini.

    Master
    Code: Dos
    Log in, to see the code
    .
    Slave
    Code: Dos
    Log in, to see the code
    In HAL version 2.6.3 (latest) already does not work . I have read from the mailing lists that the problem is with the newer NonOS-SDK, on which the Arduino HAL for ESP8266 versions 2.6.x is based.

    In general, the problem is that there is no hardware I2C controller on the ESP8266, and all communication over I2C is done by "pin waving". The code is modified all the time and that's probably where the problems come from. The second issue is that the default speed of 100 kHz is too high for Master and Slave on the ESP8266, rather Wire.setClock(50000UL) should be set.
  • #7 18476318
    omnixcrs
    Level 11  
    Hmm.... I understand in that case I will give up esp as sleve and replace it with some Adriano uno or mega, I think they support slave MODE.
  • ADVERTISEMENT
  • Helpful post
    #8 18476437
    khoam
    Level 42  
    omnixcrs wrote:
    Adriano uno or mega, I think they support slave MODE.
    .
    They do support. You will need to remember to use 5V/3V3 logic level converters if this is how you will want to connect the ESP to the Uno/Mega.
  • #9 18477006
    omnixcrs
    Level 11  
    Yes, I know. Thanks for your help khoam!
  • #10 18504131
    omnixcrs
    Level 11  
    Hello, I have another question, will the esp32 support slave mode?
  • #11 18504298
    khoam
    Level 42  
    ESP32 itself certainly supports this, but the Arduino HAL for ESP32 does not support slave mode in the Wire library - it is not implemented. I have no idea why.
  • #12 18504875
    omnixcrs
    Level 11  
    Aha, so in short I can't use the ESP32 as a slave by programming it from the Arduino IDE, yes ??
  • #14 18505362
    omnixcrs
    Level 11  
    Ok, I'll figure it out somehow. Tell me just a little bit off the top of my head: Because I have to build a network of temp sensors on a site where distances are known. These will be DS18b20 onewire. I have read from various sources that the safest way is to build a bus with a maximum length of up to 100m. I need to deploy about 30 sensors so I will certainly exceed 100m so I thought I would create for example 3-4 buses on different pins on one esp, is this possible and will it work?
  • #15 18505375
    khoam
    Level 42  
    omnixcrs wrote:
    is this possible and will it work ??
    .
    It is probably better to ask this question in the "Microcontainers" section due to its interdisciplinary nature ;)
  • #16 18505406
    omnixcrs
    Level 11  
    Ok I am already creating.

Topic summary

The discussion revolves around establishing I2C communication between a NodeMCU and a Wemos D1 mini, with the NodeMCU configured as the master and the Wemos as the slave. The user encountered issues with the communication, specifically receiving a NACK (Negative Acknowledgement) when attempting to transmit data. Various troubleshooting steps were suggested, including verifying the return value of the Wire.endTransmission() function, which indicated errors. The user tested with an Arduino Nano, which worked successfully, leading to suspicions about the Wemos D1's configuration. It was noted that the ESP8266 (NodeMCU and Wemos D1) lacks a hardware I2C controller, complicating slave mode functionality. The conversation also touched on the ESP32's limitations regarding slave mode in the Arduino HAL. Ultimately, the user considered switching to an Arduino Uno or Mega for reliable slave mode support and inquired about deploying multiple temperature sensors using DS18B20 on a long bus.
Summary generated by the language model.
ADVERTISEMENT