4

I have an Arduino Uno connected to a NodeMCU ESP01 module, communicating via serial pins. The NodeMCU is powered from the Arduino's 3.3V pin. My idea is that the ESP01 receives MQTT messages, sends them to the Arduino via serial and wait for the Arduino to reply and then publish MQTT messages back.

If I power the Arduino from my computer's USB, everything works fine.

If I use an external power supply 12V/1A, the ESP01 can publish and receive "standard" MQTT messages (meaning, it does not send messages to the Arduino and does not expect a reply). It just receives and directly replies (no Arduino involved).

The problem occurs if the ESP needs to query the Arduino for a result.

The Arduino is able to read and write (I see the correct text in the console) to the serial port, but the NodeMCU ESP01 has problems publishing MQTT messages. Sometimes it does not publish anything (the ESP probably is unable to read what Arduino sends over serial), sometimes it publishes destroyed characters (random text).

It looks like the current needed by the ESP module is not high enough, but it does not make sense for me, since the external power supply should be able to provide more current than USB. Any ideas?

This is my schematic:

enter image description here

Code:

In my ESP01 I have the following MQTT onMessage listener, If the topic is a query for the Arduino (topic is validated by the handleQuery function), then the topic is sent by UART to the Arduino, which listens for specific strings in the loop function. When the Arduino receives a string, it does some logic and writes a reply back to the ESP via UART (Serial.print()).

After the ESP sends a message to the Arduino, it sets listeners for strings, that end with character %. If the reply from the Arduino is received, then it publishes an MQTT message with the result.

function onMessage(client, topic, message)
    if handleQuery(topic.."+"..message) then
        uart.write(0,topic.."+"..message)

        uart.on("data","%", function(data)
            if data=="quit%" then
                uart.on("data") -- unregister event
            end

            if data ~= "quit%" then
                client:publish(topic.."/response","REPLY:"..data,0,0)
            end
        end,0)
    else
        client:publish(topic.."/response","REPLY: Invalid query",0,0)
    end
end

The reply from the Arduino has the following message format:

 REPLY:<value>%
 quit%

This solution works if the Arduino is connected to my desktop computer's USB. It does not work if it is powered from an external power supply. It seems like the ESP is not able to read what the Arduino wrote to UART with Serial.println() if powered from an external power source.

I have no idea why, because power supply should be able to deliver more current.

Edit:

I use the following Arduino clone: eBay link

I tried to connect the ESP01 to the Arduino's 5V output with a voltage regulator (5V should deliver more current), and again, if the USB is connected, the ESP reads UART messages with no problem. If the Arduino is powered from an external power source, the ESP reads damaged characters. The only difference is that those damaged characters seems to be always the same. So perhaps some coding problems(?) or something like that.

So far it looks like a low current value is not a problem.

Edit 2

I removed from my code print() statement from the ESP/LUA code that I used for "debbuging". It printed to serial some messages for me. It seems that it cleaned traffic on Serial line a little bit.

Now I get most of the time correct characters, but the first character is missing, so instead of:

LOW% I get OW%
HIGH% I get IGH%
29.53% I get 9.53%

And from time to time I get String =]�quit%.

Perhaps some input buffer has a problem(?).

10
  • 1
    Please post a circuit diagram or schematic. Also include your code.
    – Dat Ha
    Oct 20, 2016 at 19:43
  • 3.3v pin on the Uno is only rated for 50mA. You should provide a power supply that can provide at least 200mA.
    – gre_gor
    Oct 20, 2016 at 21:09
  • @gre_gor but why it works when Arduino is powered from USB?
    – n0hepe
    Oct 25, 2016 at 17:10
  • As @gre_gor mentioned, the Arduino UNO is incapable to provide more than 50mA The fact that it is working on most of USB-TTL is that those one can deliver more than 300mA.
    – martin
    Oct 25, 2016 at 17:35
  • 1
    The arduino outputs and should receive a 5v I/O signal. The esp8266 uses 3.3V i/o signals. The 3.3 v output from the esp8266 may not be adequate for this. I also agree with others that the arduino 3.3v supply to the 8266 is not sufficient. The wifi seems to draw quite a bit of juice. In my latest project I used a esp8266 adapter that I found on amazon. It converts the supply 5V to 3.3 as well as the i/o voltage to and from the 8266, as well as giving breadboard compatible pins. Look for esp01 adapter. Around $5 if I remember correctly.
    – john D.
    Nov 26, 2016 at 5:19

2 Answers 2

1

Can I just check when you plug your 3.3V ESP into a 12V power supply it stops working? Is there a burning smell when you do this? Are you using anything to drop the voltage to 3.3V?

You also say you are connecting the ESP to the Arduino's 5V supply. Normally that's not a good idea either.

Also have you tied the ground of the Arduino to the ESP/12V PSU? If the two devices don't share a common ground then they won't agree what 0V and so won't be able to talk to each other over serial. Just run a wire from the Gnd on the Arduino to the Gnd on the ESP and they will jump into life.

1

Use a proper level shifter on the RX and TX lines. You probably are marginal as far as signal level.

The problem is not the voltage into the ESP8266. It is the level out of the TX of the ESP8266 not being high enough for the Uno CPU. This marginal voltage can cause messed up characters. Often we can get away with it at this level but it is really a marginal situation. It is not a reliable thing to do.

Specification for Vin high is 0.7xVcc. 0.7 x 5.0v = 3.5 volts !!!!

Using a 3.3 volt level signal will often work into 5 volt logic but not always. I had learned this the hard way. I designed a medium run product that used a 3.3v derived TX signal into the 5 volt logic RX input. Worked fine in 30 prototypes. But about 20% failures when running a production order. Different batch of chips resulted in different high trip point.

Just because the practice of using 3.3volt logic into 5 volt CPUs is common it is NOT guaranteed to work. Read the spec sheet! Do the math.

5
  • there is a voltage divider to esp8266 RX pin on fritzing in Question. it is enough
    – Juraj
    Nov 17, 2018 at 18:09
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review
    – Juraj
    Nov 17, 2018 at 18:14
  • Uno will read 3.3 V as HIGH. always. official shields use it. for example Ethernet Shield for Wiznet chip and for SD card SPI MISO
    – Juraj
    Nov 18, 2018 at 7:14
  • @Juraj It does NOT always work. It often works. It is a very poor practice that marginally works.
    – Rudy
    Nov 18, 2018 at 14:11
  • sorry, you are right. and the Ethernet shield has level conversion for MISO lines
    – Juraj
    Nov 18, 2018 at 14:33

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.