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:
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.