Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know that I can connect an ESP8266 with an Arduino Uno at pins 0 and 1, which is Rx and Tx, and enter commands manually in the serial monitor the commands to test it.

I had tried to use software serial and altserial to connect an ESP8266 to other pins, but it was error prone at sometimes.

My question is that how to use an automated program to control an ESP8266 when I connect the ESP8266 with an Arduino Uno at pins 0 and 1.

Sample code would be helpful.

Edit: I have added a simple program to blink led when it get response but it is not working. could you look at it too?

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  delay(3000);
  pinMode(12,OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(12,LOW);
  delay(2000);
  Serial.println("AT");
  if(Serial.available())
  {
    digitalWrite(12,HIGH);

    while(Serial.available())
    {
      char c=Serial.read();
    }

    delay(2000);
  }

}
share|improve this question
    
What are you trying to achieve here using esp8266 and arduino? You said connecting using software serial was error prone. What do you mean? Were you getting junk values in the serial monitor? or something else.. please be specific. There could be a lot of issues related to power supplied or the buad rate or even loose connections... – Sherin Mathew Nov 30 '15 at 11:15
    
Remember that the TX pin on the arduino puts out 5v logic levels, while the ESP8266 require 3.3v logic level. You can create a buffer using a simple diode (cathode on the Arduino TX pin, anode on the ESP RX pin) – Gerben Nov 30 '15 at 13:53

The problem with using pins 0 and 1 is that they are also used to communicate with the PC for both serial monitoring and programming.

If you attach an ESP8266 to pins 0 and 1 chances are you will fail when uploading a new sketch - you will have to disconnect the ESP8266 every time you need to upload a new sketch - that is why most people use SoftwareSerial.

Also if you are using pins 0 and 1 for the ESP8266 you cannot then also use the serial monitor to see what is going on with your program and thus be able to debug it when it's not working.

If you're OK with both those caveats then by all means go ahead and use pins 0 and 1. You use it in exactly the same way as using SoftwareSerial but you don't need to define an object first - you just use the pre-defined Serial object.

One important thing to remember with the ESP8266 is that the default firmware's AT command interface is ropey as hell. It's most likely that which is tripping you up not your SoftwareSerial. You have to get the timing right with it from what I remember - always impose a 1 second delay after sending each command - it's the delay that terminates the command, not a carriage return (although I think a CR is also needed). Maybe later versions have been improved since, but that's one really good reason to directly program the ESP8266 and implement your own protocol for communicating. My ICSC library is a good candidate for communicating between the two - it runs on both the ESP8266 and the Arduino.

share|improve this answer
    
I tried a simple program to send AT commands via serial which is connected to esp8266. I added an led to blink when i got the response so that i could know it is working. But the led is not blinking. – abdul rahuman Nov 30 '15 at 16:13
    
i have added it in the question. – abdul rahuman Nov 30 '15 at 16:18
    
@abdulrahuman You're program is expecting a response from the ESP module before the serial command has had a change to get there and be processed. Your whole serial reading methodology is flawed. – Majenko Nov 30 '15 at 16:20
    
could you please be specific about where in the program should I change. I am beginner. A sample code could help better. – abdul rahuman Nov 30 '15 at 16:23
    
@abdulrahuman hacking.majenko.co.uk/reading-serial-on-the-arduino – Majenko Nov 30 '15 at 16:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.