Go Down

Topic: Arduino connecting to Internet (Read 446 times) previous topic - next topic

mikaeehl

I'm stuck with this problem for a few days already. I cant seem to make my esp8266 work without bypassing the arduino. I am trying to send data to my own hosted server. I can only do the AT command if the reset and gnd of arduino is shorted. I am supplying the esp8266 with external power source. I cant do AT command if the arduino is working normally. Any solution to this? I'm a newbie so please bear with me. Thank you!!

pert

Please give more details of what you're trying to accomplish.

I can only do the AT command if the reset and gnd of arduino is shorted.
By this I assume you are sending the AT command from Serial Monitor to the ESP8266, correct?

I cant do AT command if the arduino is working normally.
This is where it's less clear. Do you want to send AT commands from the Arduino sketch to the ESP8266 or do you still want to send AT commands from the Serial Monitor to the ESP8266?

mikaeehl

Please give more details of what you're trying to accomplish.
By this I assume you are sending the AT command from Serial Monitor to the ESP8266, correct?
This is where it's less clear. Do you want to send AT commands from the Arduino sketch to the ESP8266 or do you still want to send AT commands from the Serial Monitor to the ESP8266?
Hello! I am trying to send AT commands with the arduino sketch. but I think i can only access the AT commands of esp8266 if the reset of arduino is grounded. I have a sketch where the ARduino is sending AT commands to the esp8266 like this:

Quote
void reset() {

  esp.println("AT+RST");
  delay(1000);
  if (esp.find("OK") ) Serial.println("Module Reset");

}

//connect to your wifi network

void connectWifi() {

  String cmd = "AT+CWJAP=\"" + ssid + "\",\"" + password + "\"";
  esp.println(cmd);
  delay(4000);
  if (esp.find("OK")) {
    Serial.println("Connected!");

  }

  else {

    connectWifi();

    Serial.println("Cannot connect to wifi");
  }

}
nothing is appearing in the serial monitor. Thanks in advance!

pert

You need to change the wiring. When you're using the Arduino as a USB-serial adapter to sent AT commands to the ESP8266 from the Serial Monitor, as you have done, the correct wiring is RX-RX, TX-TX. To send AT commands from your Arduino sketch running on the Arduino to the ESP8266 that is not the correct wiring. You need to change it to RX-TX, TX-RX.

mikaeehl

You need to change the wiring. When you're using the Arduino as a USB-serial adapter to sent AT commands to the ESP8266 from the Serial Monitor, as you have done, the correct wiring is RX-RX, TX-TX. To send AT commands from your Arduino sketch running on the Arduino to the ESP8266 that is not the correct wiring. You need to change it to RX-TX, TX-RX.
I tried what you said. the blue LED is constantly blinking at baud rate of 115200. I also tried changing the baud at 9600 in the code and serial monitor. The blinking stopped. I uploaded this code:
Quote
#include <SoftwareSerial.h>

SoftwareSerial esp(6, 7);// RX, TX

void setup() {
  // put your setup code here, to run once:
  esp.begin(115200);
  Serial.begin(115200);
}

void loop() {
  // put your main code here, to run repeatedly:
  esp.println("AT+RST");
  delay(1000);
  if (esp.find("OK") ) Serial.println("Module Reset");
}
But nothing shows up in the serial monitor. Why is that?

pert

SoftwareSerial doesn't work reliably at 115200 baud. You need to connect it back up as before and send the correct AT command from the Serial Monitor to change the baud rate. Use 9600 to be safe. Later after it's working you can increase the speed.

mikaeehl

SoftwareSerial doesn't work reliably at 115200 baud. You need to connect it back up as before and send the correct AT command from the Serial Monitor to change the baud rate. Use 9600 to be safe. Later after it's working you can increase the speed.
I already tried changing the baudrate in my arduino sketch to 9600, but nothing shows up in the serial monitor.

pert

You need to configure the ESP8266 to run at 9600 first by sending it the AT command that configures it to use a different baud rate.

mikaeehl

You need to configure the ESP8266 to run at 9600 first by sending it the AT command that configures it to use a different baud rate.
Hello! i configured it using AT+CIOBAUD=9600. on my setup i use the same baud rate. nothing shows in the serial monitor. i dont know why :(

pert

Which Arduino are you using?

How is the ESP8266 connected to the Arduino?

mikaeehl

Which Arduino are you using?

How is the ESP8266 connected to the Arduino?
Im really thankful you're replying to me. I am using Arduino Mega 2560. The esp8266 is supplied with external power. The connections are:

Arduino      ESP8266

Gnd       -      GND
TX         -      RX (voltage divider 3.3v)
RX         -      TX
                    CH_PD    3.3v (external)
                    Vcc    3.3v (external


pert

Pin 6 can't be used for RX using SoftwareSerial library on Arduino Mega 2560. See:
https://www.arduino.cc/en/Reference/SoftwareSerial
Quote
Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69).

mikaeehl

Pin 6 can't be used for RX using SoftwareSerial library on Arduino Mega 2560. See:
https://www.arduino.cc/en/Reference/SoftwareSerial
The tx and rx pins are connected to 0 and 1. i also tried connecting it to pin 2 and 3, 4 and 5, 15 and 14. but still no luck in getting something from the serial monitor.

pert

Please read this:
https://www.arduino.cc/en/Reference/SoftwareSerialConstructor

As you can see the syntax is this:
Code: [Select]
SoftwareSerial mySerial (rxPin, txPin);

So you need to do two things:
  • Configure the SoftwareSerial library to use an RX pin that is supported on the Mega.
  • Actually connect the ESP8266 to the pins that you have configured the SoftwareSerial library to use.

mikaeehl

Please read this:
https://www.arduino.cc/en/Reference/SoftwareSerialConstructor

As you can see the syntax is this:
Code: [Select]
SoftwareSerial mySerial (rxPin, txPin);

So you need to do two things:
  • Configure the SoftwareSerial library to use an RX pin that is supported on the Mega.
  • Actually connect the ESP8266 to the pins that you have configured the SoftwareSerial library to use.

Today I used this code and try it:

Quote
#include <SoftwareSerial.h>

const byte rxPin = 0; // Wire this to Tx Pin of ESP8266
const byte txPin = 1; // Wire this to Rx Pin of ESP8266

// We'll use a software serial interface to connect to ESP8266
SoftwareSerial ESP8266 (rxPin, txPin);

void setup() {
  Serial.begin(9600);
  ESP8266.begin(9600); // Change this to the baudrate used by ESP8266
  delay(1000); // Let the module self-initialize
}

void loop() {
  ESP8266.print("AT");
  delay(500);
  while (ESP8266.available()){
     String inData = ESP8266.readStringUntil('\n');
     Serial.println("Got reponse from ESP8266: " + inData);
  } 
}
Still no luck. im getting a bit frustrated in doing this. it has been days of research already. i've seen some that they got it fast and no problem.

Go Up