Skip to main content
Arduino

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

ESP01 connected to Arduino can't read from UART while connected from external power source

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(?).

Answer*

Draft saved
Draft discarded
Cancel
5
  • there is a voltage divider to esp8266 RX pin on fritzing in Question. it is enough Commented 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 Commented 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 Commented Nov 18, 2018 at 7:14
  • @Juraj It does NOT always work. It often works. It is a very poor practice that marginally works. Commented Nov 18, 2018 at 14:11
  • sorry, you are right. and the Ethernet shield has level conversion for MISO lines Commented Nov 18, 2018 at 14:33

lang-cpp

AltStyle によって変換されたページ (->オリジナル) /