arduino nano to esp8266 serial communication.
Posted: Fri Dec 29, 2017 9:20 pm
Hi! Hoping I can get some help. I have a basic understanding of arduinos and arduino code. Nevertheless, I decided to take the plunge with buying myself a few esp8266 -01s's along with some other microelectronics to try and take on a project I've had in the back of my head forever.
Here's whats going on. As of right now, I've got one esp8266 running off of one of these https://www.aliexpress.com/item/OPEN-SM ... 0.0.y300un
I've got code running on the esp so that I can open the serial monitor on the esp and dependent on whether I type a 1 or a 2 into the serial monitor the built-in LED on the esp will either turn on or off. This is working fine. Here's the code
#define LED_BUILTIN 2
void setup() {
pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output
Serial.begin(115200);
while (!Serial);
Serial.println("Input 1 to turn LED on and 2 for off");
delay(1000);
}
// the loop function runs over and over again forever
void loop() {
if (Serial.available())
{
int state = Serial.parseInt();
if (state == 1)
{
digitalWrite(LED_BUILTIN, LOW);
Serial.println("LED ON");
}
if (state == 2)
{
digitalWrite(LED_BUILTIN, HIGH);
Serial.println("LED OFF");
}
}
}
However, when I try to plug in that very same ESP into my arduino circuit, pic included, (https://imgur.com/buwdO6m) I get no response from the esp's LED when I type into the nano's serial monitor.
This is the code I have running on the nano
#include <SoftwareSerial.h>
SoftwareSerial ESPserial(3, 2); // RX | TX
void setup()
{
Serial.begin(9600); // communication with the host computer
//while (!Serial) { ; }
// Start the software serial for communication with the ESP8266
ESPserial.begin(9600);
Serial.println("");
Serial.println("Remember to to set Both NL & CR in the serial monitor.");
Serial.println("Ready");
Serial.println("");
}
void loop()
{
// listen for communication from the ESP8266 and then write it to the serial monitor
if ( ESPserial.available() ) { Serial.write( ESPserial.read() ); }
// listen for user input and send it to the ESP8266
if ( Serial.available() ) { ESPserial.write( Serial.read() ); }
}
I've been tearing my hair out all day trying to figure out what's going on, I'm almost positive I've got my wires properly hooked up. I've got an external power supply dropped down to 3.3v supplying the wifi board. apart from that the only things plugged into my esp right now are power, ground, tx, rx, and rst. plugging CH_PD, or in my case, EN into 3.3v on the arduino doesnt seem to help either. Anyways, I'm past my area of understanding with this stuff so I'm hoping someone can help me get sorted and on the right track again.
Here's whats going on. As of right now, I've got one esp8266 running off of one of these https://www.aliexpress.com/item/OPEN-SM ... 0.0.y300un
I've got code running on the esp so that I can open the serial monitor on the esp and dependent on whether I type a 1 or a 2 into the serial monitor the built-in LED on the esp will either turn on or off. This is working fine. Here's the code
#define LED_BUILTIN 2
void setup() {
pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output
Serial.begin(115200);
while (!Serial);
Serial.println("Input 1 to turn LED on and 2 for off");
delay(1000);
}
// the loop function runs over and over again forever
void loop() {
if (Serial.available())
{
int state = Serial.parseInt();
if (state == 1)
{
digitalWrite(LED_BUILTIN, LOW);
Serial.println("LED ON");
}
if (state == 2)
{
digitalWrite(LED_BUILTIN, HIGH);
Serial.println("LED OFF");
}
}
}
However, when I try to plug in that very same ESP into my arduino circuit, pic included, (https://imgur.com/buwdO6m) I get no response from the esp's LED when I type into the nano's serial monitor.
This is the code I have running on the nano
#include <SoftwareSerial.h>
SoftwareSerial ESPserial(3, 2); // RX | TX
void setup()
{
Serial.begin(9600); // communication with the host computer
//while (!Serial) { ; }
// Start the software serial for communication with the ESP8266
ESPserial.begin(9600);
Serial.println("");
Serial.println("Remember to to set Both NL & CR in the serial monitor.");
Serial.println("Ready");
Serial.println("");
}
void loop()
{
// listen for communication from the ESP8266 and then write it to the serial monitor
if ( ESPserial.available() ) { Serial.write( ESPserial.read() ); }
// listen for user input and send it to the ESP8266
if ( Serial.available() ) { ESPserial.write( Serial.read() ); }
}
I've been tearing my hair out all day trying to figure out what's going on, I'm almost positive I've got my wires properly hooked up. I've got an external power supply dropped down to 3.3v supplying the wifi board. apart from that the only things plugged into my esp right now are power, ground, tx, rx, and rst. plugging CH_PD, or in my case, EN into 3.3v on the arduino doesnt seem to help either. Anyways, I'm past my area of understanding with this stuff so I'm hoping someone can help me get sorted and on the right track again.