2

I'm trying to connect an Arduino nano to a NodeMCU 1.0 via the hardware UART, in order to send information one way from the Arduino to the NodeMCU (and from there to the network). I'm connecting the Arduino TX to the NodeMCU RX via a reduction of voltage from 5V to 3.3V but I'm getting nothing read at the serial. The connectivity part is tested, since if I connect the NodeMCU via USB and write something with the Serial monitor, the data appears on the server.

Is there anything missing from the code on either parts?

The circuit is connected as follows: enter image description here

and the code that runs on the Arduino (as a test) simply sends a string over and over, but at a low rate void setup() { Serial.begin(115200); while (!Serial) delay(10); pinMode(LED_BUILTIN,OUTPUT); }

void loop() {
  digitalWrite(LED_BUILTIN,HIGH);
  delay(100);
  digitalWrite(LED_BUILTIN,LOW);
  delay(100);
  Serial.println("Hello");
}

The code that runs on the NodeMCU is as follows:

WiFiClient client;

void connect_to_wifi()
{
  WiFi.begin(ssid, password);
  int tries=0;
  for(tries=0;tries<20 && WiFi.status()!=WL_CONNECTED;++tries)
  {
    digitalWrite(D0,(tries&1)==1?HIGH:LOW);
    Serial.print(".");
    delay(500);
  }
  if (tries>=20)
  {
    status=0;
    Serial.println("Failed to connect to WiFi");
  }
  else
  {
    Serial.println("Connected to WiFi");
    if (client.connect(addr, port))
    {
      Serial.println("Connected to server");
      client.println("Connected");
    }
    else
    {
      Serial.println("Failed to connect to server");
      status=0;
    }
  }
}

void setup() {
  pinMode(D0,OUTPUT);
  digitalWrite(D0,LOW);
  Serial.begin(115200);
  while (!Serial) delay(10);
  connect_to_wifi();
}

void loop() {
  if (status==0)
  {
    digitalWrite(D0,HIGH);
    delay(300);
    digitalWrite(D0,LOW);
    delay(300);
  }
  else
  {
    digitalWrite(D0,HIGH);
    delay(100);
    digitalWrite(D0,LOW);
    delay(100);
    int av=Serial.available();
    if (av>0)
    {
      client.println(av);
      for(int i=0;i<av;++i)
      {
        int c=Serial.read();
        client.print(char(c));
      }
    }
  }
}

EDIT 1:

I connected a scope to see the serial signal and see only high. I then disconnected the NodeMCU and see a valid signal coming out of the Arduino.

Then I moved the receiving part to D5 on the NodeMCU and used a version of SoftwareSerial for this board, which worked.

For some reason, the hardware Rx is pulled high no matter what. I would prefer to use hardware Serial, but if no solution can be found, I guess I will have to do with Software.

  • Your schematic is showing 3 resistors and only 2 are needed to a 5v to 3.3v logic adapter. Could you provide more details about that interface ? – J. Piquard Dec 30 '16 at 21:22
  • The hardware receive pin is probably being driven high by the node MCU's onboard USB-serial chip, and your voltage divider means the signal from the arduino will clearly loose that battle. See if you can disable the USB serial chip, perhaps by holding it in reset, or if there's a way to cut the connection. If you have the CH340 version try making R10 a lot bigger, or else maybe put a diode in your level shifter or switch to a MOSFET style level converter so that you can actively drive low. – Chris Stratton Dec 31 '16 at 0:47
  • The reason for the 3 resistors is to make a 2/3 divider using 3 identical resistors. Regarding a level shifter, I have tried that before and it didn't help. If there's nothing that can easily be done in software to remove the pullup on the Rx pin, I'll settle for soft serial on another pin. Thanks for the suggestions. – Photon Dec 31 '16 at 10:37
  • What about using a optocoupler to handle the different voltage issue? – Bogarth Oct 16 '17 at 2:01

Your Answer

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

Browse other questions tagged or ask your own question.