Post topics, source code that relate to the Arduino Platform

User avatar
By aftrumpet
#4360 I am trying to interface the Arduino Mega with an ESP8266. My connections are as follows:
  • RX -> Pin 1 (TX)
  • TX -> Pin 0 (RX)
  • GND -> GND
  • VCC -> 3.3V
  • Four middle pins -> 3.3V
I have also tried letting the GPIO pins float, with the same result.

I am using this code to send and receive messages--basically just the Software Serial example--with a debugging cable from the Arduino to the computer that I am using to send messages to mySerial.

Code: Select all#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup() 
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  mySerial.println("Hello, world?");
}

void loop() // run over and over
{
  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());
}


On every valid command I try (even just plain "AT") I get ERROR. Some things to note:
  • My module is definitely 9600 baud, the other bauds don't send comprehensible messages.
  • When I don't enter a valid command, I get "wrong syntax", which is correct.
  • The blue light blinks whenever I enter a command.
  • I have gotten the startup message before by toggling the reset pin, but still get ERROR afterwards.

Could anyone pinpoint what I am doing wrong here?
Last edited by aftrumpet on Tue Dec 09, 2014 11:10 am, edited 1 time in total.
User avatar
By alonewolfx2
#4376 I think your problem is cr lf. Can you try this.
Code: Select all void loop() // run over and over
{
  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read()+"\r\n");
}
User avatar
By villTech
#4379 based on your post, is it correct that your esp tx rx is connected to mega d0 and d1 (tx0 rx0 respectively) and you are running softserial on pin11 pin12 on your mega?

btw, it would be better to use mega's other hardware uart (serial1 serial2 serial3) than soft serial.
User avatar
By aftrumpet
#4402
alonewolfx2 wrote:I think your problem is cr lf. Can you try this.
Code: Select all void loop() // run over and over
{
  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read()+"\r\n");
}


I was using the Arduino serial monitor, and changed the output to "Both NL & CR" and it worked! Thank you!