Esp8266 module (xbee compatible) not working on arduino

Hello to everyone,

i have recently bought an esp8266 module from dfrobot. It comes with xbee design.

I cannot communicate with it when connected to arduino.

I tested the module with an USB adapter and AT commands, and it connect to my home network with no issues.

The module description is here → this

For the moment i am just trying to connect to the access point using arduino.

The module is on the USB adapter, which has an FTDI connector. As in the wiki page of dfrobot (link above) i have connected RX-TX-GND of the adapter to the arduino pins 11-10-GND.

Here is the code:

#include "esp8266.h"
#include "SoftwareSerial.h"

#define	ssid		"this is my ssid"		
#define	password	"this is my pwd"

Esp8266 wifi;
bool flag=false;

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

void setup() {

	delay(2000);				
	pinMode(13, OUTPUT);

	mySerial.begin(9600);	
							
	Serial.begin(9600);					
	wifi.begin(&Serial, &mySerial);  

	
	 

	if (wifi.connectAP(ssid, password)) {	 
		flag = true;
		wifi.debugPrintln("connected to AP"); 
	} else { 
		wifi.debugPrintln("connect Fail");								
	}


	
}

void loop() {
	if (flag) {
	  digitalWrite(13, HIGH);   
	  delay(500);              
	  digitalWrite(13, LOW);   
	  delay(500);              
	}
}

OF COURSE i have set my real ssid and password :slight_smile:

What i get, on the debug serial, is “connect fail”.

I wrote to dfrobot, they suggested me to update the firmware, and thats what i did. I’m using v0.9.2.2 AT Firmware. Baudrate changed from 115200 to 9600 (tested on the usb adapter and succesfully connected with AT commands). No way to make it connect to a network (tryied 3 different router with different security settings) using a sketch on arduino.

So, reading around the net i have found out a sketch to use AT commands sending them from arduino, but i dont get any answer from the esp. Here is the code:

#include <SoftwareSerial.h>
 
SoftwareSerial esp8266(10,11);

void setup()
{
  Serial.begin(9600);
  esp8266.begin(9600);
}
 
void loop()
{
  if(esp8266.available())
  {
    while(esp8266.available())
    {     
      char c = esp8266.read(); // read the next character.
      Serial.write(c);
    } 
  }
 
 
 
  if(Serial.available())
  { 
    delay(1000);
   
    String command="";
   
    while(Serial.available()) // read the command character by character
    {       
      command+=(char)Serial.read();
    }
    esp8266.println(command); // send the read character to the esp8266
  }
}

Can someone help me please?

Thanks in advance, and sorry for the long post and my bad english!

ps: i forgot to say i used same wiring/sketch on uno rev3 (original) and mega2560 (compatible) with same results… also on this shield removing software serial from the sketch and trying to connect directly.

Hello,

can someone please help me?

So, reading around the net i have found out a sketch to use AT commands sending them from arduino, but i dont get any answer from the esp. Here is the code:

Of course you don't. Serial data arrives very slowly. If you are using the Serial Monitor to send data, and type AT, and press send, the 'A' will be sent, then the 'T' will be sent. If you have line ending set to other than none, the line ending character(s) will be sent, one at a time.

The Arduino can read serial data faster than it arrives. So, it reads the A, and, since there is no more data to read, it sends that to the ESP, followed be a carriage return and line feed. The ESP does not know what to do with the A command, so it ignores it.

Then, several iterations of loop() later, the 'T' arrives, so you send that and a carriage return and line feed to the ESP. It doesn't know what to do with the T command, so off to the bit bucket it goes.

You need to read AND STORE the data until the end of packet marker arrives. Then, you can send the command to the ESP.

PaulS:
You need to read AND STORE the data until the end of packet marker arrives. Then, you can send the command to the ESP.

Hi PaulS,

thanks for the answer!

I will try this out tomorrow, i just have half idea :slight_smile:

What about the first sketch? Can you see some mistake in it too?

If you load a non serial program on the arduino (like blink example), then you can connect the esp8266 module to the arduino tx/rx/gnd pins and directly communicate with the esp8266 module using the serial monitor. You may need to reduce the arduino tx voltage to ~3.3v, ensure that baud rates match, and set cr/lf on the serial monitor if needed.

zoomkat:
If you load a non serial program on the arduino (like blink example), then you can connect the esp8266 module to the arduino tx/rx/gnd pins and directly communicate with the esp8266 module using the serial monitor. You may need to reduce the arduino tx voltage to ~3.3v, ensure that baud rates match, and set cr/lf on the serial monitor if needed.

Hi Zoomkat,
thank you too!
I have just tryied loading a sketch just with empty setup and loop, connecting the module to pins 0-1, but it is not working. Actually, to be sure i didn't any mistake in the wiring (even if almost impossible...), i have tryied the module on the expansion slot of the relay shield, which communicate on pins 0-1.
Nothing worked.

Baudrate is set correctly (tested with the usb adapter).

cr/lf is needed and set (also tested with the usb adapter).

How do i reduce tx voltage? Is it possible via software (i will need to make it work on the relay shield)? :open_mouth:

How do i reduce tx voltage? Is it possible via software (i will need to make it work on the relay shield)?

You can put two small diodes between the arduino tx and the ESP rx to drop the voltage from 5.0v to ~3.6v, which may be close enough to 3.3v.

zoomkat:
You can put two small diodes between the arduino tx and the ESP rx to drop the voltage from 5.0v to ~3.6v, which may be close enough to 3.3v.

I don't think that will work, as a low signal will not be able to sink since current flow is one way for diode.

The typical way this is done for ARM processors (esp8266 is ARM based) is to use a resistor in series to limit the current to the 3.3v side pin. 1k should be fine.

I don't think that will work, as a low signal will not be able to sink since current flow is one way for diode.

Put the diode band ends toward the tx pin. Then the tx can pull the rx low (current flow from rx to tx) and block current flow from the high (5v) tx into the rx.

Edit: just thinking about the way TTL works, probably only one diode is needed with the band to the tx as the diode will function to prevent the tx from feeding the 5.0v to the 3.3v pin. Voltage blocking instead of voltage reduction.

Hello everyone!

Before trying to reduce tx pin voltage on the arduino i would like to do a few more attempts to make it work on the relay shield (which is why i have bought an esp8266 with xbee design XD).

I have made some changes to the first sketch, just another led, which will turn on if the connection got failed!

Now the strange comes in: the shield has a switch to avoid interferences between xbee module and arduino when loading sketches.
So, when switch is on programming mode, “fail led” turns on, but when i put the switch on the normale mode (arduino is free to communicate with the module) no leds turns on.

What sounds very strange to me is that the blink is at the very beginning of the setup, before any serial opening. Can this be because of the arduino tx voltage?

#include "esp8266.h"

#define  ssid    "myrealssid"     
#define password  "myrealpwd"

Esp8266 wifi;
bool flag = false;

void setup() 
{
  pinMode(2,OUTPUT);
  pinMode(3,OUTPUT);

  //relay
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(7,OUTPUT);
  pinMode(8,OUTPUT);

  for(int i=2;i<=8;i++)
  {
    if(i!=4)
    {
      digitalWrite(i,LOW);
    }
  }

  for(int i=2;i<=3;i++)
  {
    digitalWrite(i,HIGH);
    delay(500);
    digitalWrite(i,LOW);
  }
    
  delay(2000);
  
  Serial.begin(9600);
  wifi.begin(&Serial);

  if (wifi.connectAP(ssid, password)) 
  {
    flag = true;
    digitalWrite(2,HIGH);
    digitalWrite(3,LOW);
  } 
  else 
  {
    digitalWrite(3,HIGH);
    digitalWrite(2,LOW);
  }
}

void loop() {
  if (flag) 
  {        
    digitalWrite(2,HIGH);    
    digitalWrite(3,LOW);
  }
  else
  { 
    digitalWrite(3,HIGH);
    digitalWrite(2,LOW);
  }
}

Can i mesure the voltage of the rx pin on the relay shield with a common tester?

I have just tryied loading a sketch just with empty setup and loop, connecting the module to pins 0-1, but it is not working. Actually, to be sure i didn't any mistake in the wiring (even if almost impossible...),

If you don't connect the grounds, you may have issues.

zoomkat:
If you don't connect the grounds, you may have issues.

I did, here is a couple of pictures of the wirings i tryied, with the module on the relay shield (microbot) and on the usb adapter (df robot).

I'm a newbie on arduino, maybe i'm doing stupid mistakes, but... :-*

I did, here is a couple of pictures of the wirings i tryied, with the module on the relay shield (microbot) and on the usb adapter (df robot).

Maybe you should disconnect any/all that stuff and just try simple communication between the serial monitor and the ESP.

I forgot the pics XD

@zoomkat
what do you mean?
Using the usb adapter directly connected to the pc (no arduino) and the serial monitor i can connect, using AT commands.
Using the usb adapter and connecting it to arduino (doesnt matter if the “power line” comes from arduino or from usb source) with a “blank” sketch it gives back nothing when sending AT commands from the serial monitor.

Using the usb adapter and connecting it to arduino (doesnt matter if the "power line" comes from arduino or from usb source) with a "blank" sketch it gives back nothing when sending AT commands from the serial monitor.

Why are you using the USB adapter? What I described did not include an additional USB adapter as the arduino actually has a USB adapter built in. What I described is serial monitor > arduino > ESP.

zoomkat:
Why are you using the USB adapter? What I described did not include an additional USB adapter as the arduino actually has a USB adapter built in. What I described is serial monitor > arduino > ESP.

I will try this out!

Today i have noticed something else. If i connect the esp to the pc, via usb adapter, it connects itself to my home network, i dont know why but it stored my ssid e pwd in its flash memory. Can this be the cause of the problem?

Tryied connecting the module itself to arduino, on pins 0-1.

If i load a blank sketch i can communicate with the module using AT commands.
If i load the sketch it does not connect. I tryied with the module on pins 0-1 (no softwareSerial) and on pins 10-11 (using softwareSerial). No way to see it connected on my router!

I am really confused!