Connect ESP 8266 nodemcu to Arduino

Hello,

I want to connect ESP 8266 nodemcu module to my arduino to control 4 separated motors by my browser.
I faced some starting problems. First of all, How can I establish the connection between them? and my code will be sketched in the arduino or wifi module?

I have some bases to coding the controlling code for my needs, but i miss the basics of WiFi using because of it’s my first use.

Noting that I have ESP 8266 nodemcu module as shown in figure

What is the function of the Arduino here? Doesn't seem to be needed.

Two separate microcontrollers; two separate sketches. Communocation between the two is commonly Serial, can also be I2C or SPI.

Mind the voltages. NodeMCU is 3.3V and can't handle 5V signals. Many Arduinos work at 5V.

wvmarle:
What is the function of the Arduino here? Doesn't seem to be needed.

Two separate microcontrollers; two separate sketches. Communocation between the two is commonly Serial, can also be I2C or SPI.

Mind the voltages. NodeMCU is 3.3V and can't handle 5V signals. Many Arduinos work at 5V.

I have 4 motors to control. And only one analog pin is available in this WIFI module, So it seems unable to do this task without arduino
Am i right ?

I don't know - why do you need an analog input to control motors in the first place? You said your inputs come from the web.

It's also got 11 digital I/O pins. Just mind that some have special functions as well. Start with this ESP8266 guide to learn more about this processor.

@OP
I own a similar ESP8266 board (NodeMCU1.0-12E Module), and it works well with Arduino UNO (without any level shifters; NodeMCU's pins are 5V tolerant) over I2C Bus and UART port.

GolamMostafa:
NodeMCU's pins are 5V tolerant

No, they're NOT. Don't connect 5V to those pins directly.

I2C works safely if you pull it up to 3.3V; for serial you need a resistor on Arduino's Tx line (which forms a voltage divider with the NodeMCU to get to safe voltage - you'll have to look up the values).

I2C will work if you pull it up with a large enough resistor to 5V, but you're taxing the clamping diodes.

A direct 5V connection to the NodeMCU's pins WILL kill the device.

wvmarle:
No, they're NOT. Don't connect 5V to those pins directly.

I2C works safely if you pull it up to 3.3V; for serial you need a resistor on Arduino's Tx line (which forms a voltage divider with the NodeMCU to get to safe voltage - you'll have to look up the values).

I2C will work if you pull it up with a large enough resistor to 5V, but you're taxing the clamping diodes.

A direct 5V connection to the NodeMCU's pins WILL kill the device.

This is the document based on which I connected my ESP with Arduino UNO using I2C Bus and UART Port; I found them working.
esp5Vtolerant.png

esp5Vtolerant.png

Another option would be to add additional A/D capability to the ESP8266 by way of an external board.

ebay A/D board

This option is not very fast (80 samples / second) but is really low noise and great of noisy environments.

Not really sure if it better than using an Arduino as a secondary A/D but it does work well. I guess it comes down to personal preference (and available parts).

@GolamMostafa in 8266-01 they are not 5v tolerant. I burned tx pin on one module after about one month of continuous heavy use.

Was connected to uno without level shifter. Which i think means if communication between 2 is not heavy then esp may live longer.

Odd, I'd expect you to kill the Rx instead. The Tx is managed by the ESP itself - it's the ESP's Rx where the Arduino's voltages appear. All you need is a voltage divider in the Arduino Tx to ESP Rx.

GolamMostafa:
I own a similar ESP8266 board (NodeMCU1.0-12E Module), and it works well with Arduino UNO (without any level shifters; NodeMCU's pins are 5V tolerant) over I2C Bus and UART port.

This is the document based on which I connected my ESP with Arduino UNO using I2C Bus and UART Port; I found them working.

For reference, that article and the tests (that seem to demonstrate 5V tolerance) were discussed here. Unfortunately, none of the responses addressed the tests and test results.

wvmarle:
Odd, I'd expect you to kill the Rx instead. The Tx is managed by the ESP itself - it's the ESP's Rx where the Arduino's voltages appear. All you need is a voltage divider in the Arduino Tx to ESP Rx.

you are right I meant RX.

wvmarle:
voltages appear. All you need is a voltage divider in the Arduino Tx to ESP Rx.

Actually, a diode.

This is an important trick to be learned from the Adafruit Huzzah ESP8266 breakout.

The level converter is a single diode. That's it!


Clearly, the ESP8266 contains an internal pull-up, so you might or might not need to add a pull-up to your 3.3 V device. You are driving it with an Arduino, so if needed, pick your value - 1k, 3k3 - whatever. This will in any case be faster than a resistive divider.

It turns out to be a quite brilliant solution!

When the input from the Arduino (or other device) is pulled LOW, the diode pulls the output LOW within 0.7 V. The diode impedance is very low (tens of Ohms) and 0.7 V will be well within the tolerance of any 3.3 V device as a logic LOW, so delay at this point is negligible.

Correspondingly, when the input from the Arduino (or other device) is pulled HIGH, either the built-in pull-up of the 3.3 V device (as in the ESP8266) will itself pull the input up to its own HIGH level, or in case this is not sufficiently fast, a pull-up to the 3.3 V supply can be added. Given that it is an Arduino pin driving the circuit, the pull-up can be as low as necessary to achieve the required speed, down to 330 Ohms or so.

The arrangement is both simple, and immediately fills virtually all requirements for level shifting.

Even better!

I remember our ESP8266 expert PieterP suggest the voltage divider with a single resistor, taking advantage of the internal one, but couldn't remember the details. That must have been a pull-down. No matter, this diode solution is even better indeed. Just have to be really careful which wire goes where, which with serial is very easy to do wrong.