Esp8266+mega 2560

Hello all, i need help with ESP8266 and mega 2560, but before that, i apologize if my english really bad and if this topic already discussed. I want to try ESP8266_shield sketch, but when i tried to get connections with the Blynk app to the Module i always get alert like this

[19] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.4.10 on Arduino Mega

[605] Connecting to myssid
[1615] ESP is not responding

why is that happend? I’m already read and try this http://help.blynk.cc/how-to-connect-different-hardware-with-blynk/arduino/esp8266-with-at-firmware, but didn’t worked, maybe i miss something. Could someone help me?
I’m try this tutorial http://www.instructables.com/id/Get-Started-With-ESP8266-Using-AT-Commands-Via-Ard/ and works (wifi conected, wifi got ip).
This my firmware:
AT version:1.1.0.0(May 11 2016 18:09:56)
SDK version:1.5.4(baaeaebb)
Ai-Thinker Technology Co. Ltd.
Jun 13 2016 11:29:20

Thank You.

1 Like

Can you supply more details on how you have physically connected the two, which pins, ESP power source, etc.

Might also benefit if you can copy your code here for us to confirm that is is setup correctly.

When doing so, please format it like this, after pasting it, for proper forum viewing. Thanks.

Blynk - FTFC

OK. First I’m use external power supply (YuRobot)image
and then I’m follow this step
Arduino --------------------------------------------------- ESP8266

TX0->1----------------------------------------------------> TXD

RX0->0----------------------------------------------------> RXD

GND ----------->Power Supply<----------------------- GND

3.3 V <-----------Power Supply-----------------------> VCC

3.3 V <-----------Power Supply-----------------------> CH_PD

This is the diagram for esp8266 and arduino mega 2560 wiring

This the sketch, my inspiration from here https://www.hackster.io/TomatoMan/robot-rover-iphone-controlled-using-blynk-joystick-572153?ref=part&ref_id=15659&offset=3

#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <Servo.h>

char auth[] = "TOKEN";
char ssid[] = "SSID";
char pass[] = "PASS";

#define EspSerial Serial1
#define ESP8266_BAUD 115200
ESP8266 wifi(&EspSerial);


//PIN MOTOR (USE L298N DRIVER)
int MOTOR1A = 22;
int MOTOR1B = 23;
int MOTOR2A = 24;
int MOTOR2B = 25;
int MOTOR3A = 30;
int MOTOR3B = 31;
int MOTOR4A = 32;
int MOTOR4B = 33;
int MOTOR5A = 28;
int MOTOR5B = 29;
int MOTOR6A = 26;
int MOTOR6B = 27;

//PIN MOTOR SPEED
int MOTOR1 = 7;
int MOTOR2 = 6;
int MOTOR3 = 5;
int MOTOR4 = 4;
int MOTOR5 = 3;
int MOTOR6 = 2;

//SERVO
Servo SERVO1, SERVO2, SERVO3, SERVO4, SERVO5, SERVO6;

void setup() {

//BLYNK
Serial.begin(9600);
delay(10);
EspSerial.begin(ESP8266_BAUD);
delay(10);
Blynk.begin(auth, wifi, ssid, pass);

//PIN SERVO
SERVO1.attach(13);
SERVO2.attach(12);
SERVO3.attach(11);
SERVO4.attach(10);
SERVO5.attach(9);
SERVO6.attach(8);

//SERVO BEGINING
SERVO1.write(125);
SERVO2.write(40);
SERVO3.write(35);
SERVO4.write(95);
SERVO5.write(125);
SERVO6.write(85);
  
//MOTOR OUTPUT
pinMode(MOTOR1A, OUTPUT);
pinMode(MOTOR1B, OUTPUT);
pinMode(MOTOR2A, OUTPUT);
pinMode(MOTOR2B, OUTPUT);
pinMode(MOTOR3A, OUTPUT);
pinMode(MOTOR3B, OUTPUT);
pinMode(MOTOR4A, OUTPUT);
pinMode(MOTOR4B, OUTPUT);
pinMode(MOTOR5A, OUTPUT);
pinMode(MOTOR5B, OUTPUT);
pinMode(MOTOR6A, OUTPUT);
pinMode(MOTOR6B, OUTPUT);

//MOTOR SPEED OUTPUT
pinMode(MOTOR1, OUTPUT);
pinMode(MOTOR2, OUTPUT);
pinMode(MOTOR3, OUTPUT);
pinMode(MOTOR4, OUTPUT);
pinMode(MOTOR5, OUTPUT);
pinMode(MOTOR6, OUTPUT);

//MOTOR BEGINING
digitalWrite(MOTOR1A, LOW);
digitalWrite(MOTOR1B, LOW);
digitalWrite(MOTOR2A, LOW);
digitalWrite(MOTOR2B, LOW);
digitalWrite(MOTOR3A, LOW);
digitalWrite(MOTOR3B, LOW);
digitalWrite(MOTOR4A, LOW);
digitalWrite(MOTOR4B, LOW);
digitalWrite(MOTOR5A, LOW);
digitalWrite(MOTOR5B, LOW);
digitalWrite(MOTOR6A, LOW);
digitalWrite(MOTOR6B, LOW);
}


void loop() {
  Blynk.run();
  
}

BLYNK_WRITE(V0) {
  
  const int X_THRESHOLD_LOW = 107; //x: 127 - 20
  const int X_THRESHOLD_HIGH = 147; //x: 127 + 20   

  const int Y_THRESHOLD_LOW = 107; //y: 127 - 20
  const int Y_THRESHOLD_HIGH = 147; //y: 127 + 20
      
  int x_position = param[0].asInt();  //Read the Blynk Joystick x Position 0-255
  int y_position = param[1].asInt();  //Read the Blynk Joystick y Position 0-255

  int x_direction;  //Variable for Direction of Joystick Movement: x= -1, 0, 1
  int y_direction;  //Variable for Direction of Joystick Movement: y= -1, 0, 1
 
  Serial.print("x_position: ");
  Serial.print(x_position);
  Serial.print("  y_position: ");
  Serial.println(y_position);

//Determine the direction of the Joystick Movement
  x_direction = 0;
  y_direction = 0;

  if (x_position > X_THRESHOLD_HIGH) {
    x_direction = 1;
  } else if (x_position < X_THRESHOLD_LOW) {
    x_direction = -1;
  }
  if (y_position > Y_THRESHOLD_HIGH) {
    y_direction = 1;
  } else if (y_position < Y_THRESHOLD_LOW) {
    y_direction = -1;
  }
//if x and y are within the threshold their values then x_direction = 0 and y_direction = 0

//Move the Rover (Rover will move in the direction of the slower wheels)
//0,0(Stop); 0,1(Forward); 0,-1(Backward); 1,1(Right up diagonal); 1,0(Right); 1,-1(Right down diagonal);
//-1,0(Left); -1,1(Left up diagonal); -1,-1(Left down diagonal)

//x = -1 and y = -1 Back Diagonal Left
  if (x_direction == -1) 
    if (y_direction == -1) {
        Serial.print("JOYSTICK: left-down DIRECTION: BACKWARD LEFT");
        Serial.print("  x_direction  ");
        Serial.print(x_direction);
        Serial.print("  y_direction  ");
        Serial.println(y_direction); 

SERVO1.write(90);
SERVO2.write(0);
SERVO3.write(90);
SERVO4.write(95);
SERVO5.write(180);
SERVO6.write(85);
digitalWrite(MOTOR1A, LOW);
digitalWrite(MOTOR1B, HIGH);
digitalWrite(MOTOR2A, LOW);
digitalWrite(MOTOR2B, HIGH);
digitalWrite(MOTOR3A, LOW);
digitalWrite(MOTOR3B, HIGH);
digitalWrite(MOTOR4A, LOW);
digitalWrite(MOTOR4B, HIGH);
digitalWrite(MOTOR5A, LOW);
digitalWrite(MOTOR5B, HIGH);
digitalWrite(MOTOR6A, LOW);
digitalWrite(MOTOR6B, HIGH);
analogWrite(MOTOR1,127);
analogWrite(MOTOR2,255);
analogWrite(MOTOR3,127);
analogWrite(MOTOR4,127);
analogWrite(MOTOR5,255);
analogWrite(MOTOR6,255);

//x = -1 and y = 0 Left on x axis     
      } else if (y_direction == 0) {
        Serial.print("JOYSTICK: left DIRECTION: TURN AROUND LEFT ");
        Serial.print("  x_direction  ");
        Serial.print(x_direction);
        Serial.print("  y_direction  ");
        Serial.println(y_direction);

SERVO1.write(35);
SERVO2.write(130);
SERVO3.write(125);
SERVO4.write(10);
SERVO5.write(35);
SERVO6.write(170);
digitalWrite(MOTOR1A, LOW);
digitalWrite(MOTOR1B, HIGH);
digitalWrite(MOTOR2A, HIGH);
digitalWrite(MOTOR2B, LOW);
digitalWrite(MOTOR3A, LOW);
digitalWrite(MOTOR3B, HIGH);
digitalWrite(MOTOR4A, LOW);
digitalWrite(MOTOR4B, HIGH);
digitalWrite(MOTOR5A, HIGH);
digitalWrite(MOTOR5B, LOW);
digitalWrite(MOTOR6A, HIGH);
digitalWrite(MOTOR6B, LOW);
analogWrite(MOTOR1,255);
analogWrite(MOTOR2,255);
analogWrite(MOTOR3,255);
analogWrite(MOTOR4,255);
analogWrite(MOTOR5,255);
analogWrite(MOTOR6,255);

//x = -1 and y = 1 Forward Diagonal Left   
      } else {
        //y_direction == 1
        Serial.print("JOYSTICK left-up DIRECTION: FORWARD LEFT");
        Serial.print("  x_direction  ");
        Serial.print(x_direction);
        Serial.print("  y_direction  ");
        Serial.println(y_direction);  

SERVO1.write(180);
SERVO2.write(90);
SERVO3.write(0);
SERVO4.write(95);
SERVO5.write(90);
SERVO6.write(85);
digitalWrite(MOTOR1A, HIGH);
digitalWrite(MOTOR1B, LOW);
digitalWrite(MOTOR2A, HIGH);
digitalWrite(MOTOR2B, LOW);
digitalWrite(MOTOR3A, HIGH);
digitalWrite(MOTOR3B, LOW);
digitalWrite(MOTOR4A, HIGH);
digitalWrite(MOTOR4B, LOW);
digitalWrite(MOTOR5A, HIGH);
digitalWrite(MOTOR5B, LOW);
digitalWrite(MOTOR6A, HIGH);
digitalWrite(MOTOR6B, LOW);
analogWrite(MOTOR1,127);
analogWrite(MOTOR2,255);
analogWrite(MOTOR3,127);
analogWrite(MOTOR4,127);
analogWrite(MOTOR5,255);
analogWrite(MOTOR6,255);

//x = 0 and y = -1 Backward
      } else 
        if (x_direction == 0) 
        if (y_direction == -1) {
        Serial.print("JOYSTICK down DIRECTION BACKWARD");
        Serial.print("  x_direction  ");
        Serial.print(x_direction);
        Serial.print("  y_direction  ");
        Serial.println(y_direction);

SERVO1.write(125);
SERVO2.write(40);
SERVO3.write(35);
SERVO4.write(95);
SERVO5.write(125);
SERVO6.write(85);
digitalWrite(MOTOR1A, LOW);
digitalWrite(MOTOR1B, HIGH);
digitalWrite(MOTOR2A, LOW);
digitalWrite(MOTOR2B, HIGH);
digitalWrite(MOTOR3A, LOW);
digitalWrite(MOTOR3B, HIGH);
digitalWrite(MOTOR4A, LOW);
digitalWrite(MOTOR4B, HIGH);
digitalWrite(MOTOR5A, LOW);
digitalWrite(MOTOR5B, HIGH);
digitalWrite(MOTOR6A, LOW);
digitalWrite(MOTOR6B, HIGH);
analogWrite(MOTOR1,255);
analogWrite(MOTOR2,255);
analogWrite(MOTOR3,255);
analogWrite(MOTOR4,255);
analogWrite(MOTOR5,255);
analogWrite(MOTOR6,255);

//x = 0 and y = 0 Stop
      } else if (y_direction == 0) {
        Serial.print("JOYSTICK: centered DIRECTION: STOP");
        Serial.print("  x_direction  ");
        Serial.print(x_direction);
        Serial.print("  y_direction  ");
        Serial.println(y_direction);

SERVO1.write(125);
SERVO2.write(40);
SERVO3.write(35);
SERVO4.write(95);
SERVO5.write(125);
SERVO6.write(85);
digitalWrite(MOTOR1A, LOW);
digitalWrite(MOTOR1B, LOW);
digitalWrite(MOTOR2A, LOW);
digitalWrite(MOTOR2B, LOW);
digitalWrite(MOTOR3A, LOW);
digitalWrite(MOTOR3B, LOW);
digitalWrite(MOTOR4A, LOW);
digitalWrite(MOTOR4B, LOW);
digitalWrite(MOTOR5A, LOW);
digitalWrite(MOTOR5B, LOW);
digitalWrite(MOTOR6A, LOW);
digitalWrite(MOTOR6B, LOW);
analogWrite(MOTOR1,0);
analogWrite(MOTOR2,0);
analogWrite(MOTOR3,0);
analogWrite(MOTOR4,0);
analogWrite(MOTOR5,0);
analogWrite(MOTOR6,0);

//x = 0 and y = 1 Forward 
      } else {
        //y_direction == 1
        Serial.print("JOYSTICK: up DIRECTION: FORWARD");
        Serial.print("  x_direction  ");
        Serial.print(x_direction);
        Serial.print("  y_direction  ");
        Serial.println(y_direction);

SERVO1.write(125);
SERVO2.write(40);
SERVO3.write(35);
SERVO4.write(95);
SERVO5.write(125);
SERVO6.write(85);
digitalWrite(MOTOR1A, HIGH);
digitalWrite(MOTOR1B, LOW);
digitalWrite(MOTOR2A, HIGH);
digitalWrite(MOTOR2B, LOW);
digitalWrite(MOTOR3A, HIGH);
digitalWrite(MOTOR3B, LOW);
digitalWrite(MOTOR4A, HIGH);
digitalWrite(MOTOR4B, LOW);
digitalWrite(MOTOR5A, HIGH);
digitalWrite(MOTOR5B, LOW);
digitalWrite(MOTOR6A, HIGH);
digitalWrite(MOTOR6B, LOW);
analogWrite(MOTOR1,255);
analogWrite(MOTOR2,255);
analogWrite(MOTOR3,255);
analogWrite(MOTOR4,255);
analogWrite(MOTOR5,255);
analogWrite(MOTOR6,255);

//x = 1 and y = -1 Backward Diagonal Right
      } else 
        //x_direction == 1
        if (y_direction == -1){ 
        Serial.print("JOYSTICK right-down DIRECTION: BACKWARD RIGHT");
        Serial.print("  x_direction  ");
        Serial.print(x_direction);
        Serial.print("  y_direction  ");
        Serial.println(y_direction);

SERVO1.write(180);
SERVO2.write(90);
SERVO3.write(0);
SERVO4.write(95);
SERVO5.write(90);
SERVO6.write(85);
digitalWrite(MOTOR1A, LOW);
digitalWrite(MOTOR1B, HIGH);
digitalWrite(MOTOR2A, LOW);
digitalWrite(MOTOR2B, HIGH);
digitalWrite(MOTOR3A, LOW);
digitalWrite(MOTOR3B, HIGH);
digitalWrite(MOTOR4A, LOW);
digitalWrite(MOTOR4B, HIGH);
digitalWrite(MOTOR5A, LOW);
digitalWrite(MOTOR5B, HIGH);
digitalWrite(MOTOR6A, LOW);
digitalWrite(MOTOR6B, HIGH);
analogWrite(MOTOR1,255);
analogWrite(MOTOR2,127);
analogWrite(MOTOR3,255);
analogWrite(MOTOR4,255);
analogWrite(MOTOR5,127);
analogWrite(MOTOR6,127);

        
//x = 1 and y = 0 Right on x-axis
      } else 
        if (y_direction == 0){ 
        Serial.print("JOYSITCK: right DIRECTION: TURN AROUND RIGHT");
        Serial.print("  x_direction  ");
        Serial.print(x_direction);
        Serial.print("  y_direction  ");
        Serial.println(y_direction);

SERVO1.write(35);
SERVO2.write(130);
SERVO3.write(125);
SERVO4.write(10);
SERVO5.write(35);
SERVO6.write(170);
digitalWrite(MOTOR1A, HIGH);
digitalWrite(MOTOR1B, LOW);
digitalWrite(MOTOR2A, LOW);
digitalWrite(MOTOR2B, HIGH);
digitalWrite(MOTOR3A, HIGH);
digitalWrite(MOTOR3B, LOW);
digitalWrite(MOTOR4A, HIGH);
digitalWrite(MOTOR4B, LOW);
digitalWrite(MOTOR5A, LOW);
digitalWrite(MOTOR5B, HIGH);
digitalWrite(MOTOR6A, LOW);
digitalWrite(MOTOR6B, HIGH);
analogWrite(MOTOR1,255);
analogWrite(MOTOR2,255);
analogWrite(MOTOR3,255);
analogWrite(MOTOR4,255);
analogWrite(MOTOR5,255);
analogWrite(MOTOR6,255);

//x = 1 and y = 1 Forward Diagonal Right
      } else { 
        //y_direction == 1
        Serial.print("JOYSTICK: right-up DIRECTION: RIGHT"); 
        Serial.print("  x_direction  ");
        Serial.print(x_direction);
        Serial.print("  y_direction  ");
        Serial.println(y_direction);

SERVO1.write(90);
SERVO2.write(0);
SERVO3.write(90);
SERVO4.write(95);
SERVO5.write(180);
SERVO6.write(85);
digitalWrite(MOTOR1A, HIGH);
digitalWrite(MOTOR1B, LOW);
digitalWrite(MOTOR2A, HIGH);
digitalWrite(MOTOR2B, LOW);
digitalWrite(MOTOR3A, HIGH);
digitalWrite(MOTOR3B, LOW);
digitalWrite(MOTOR4A, HIGH);
digitalWrite(MOTOR4B, LOW);
digitalWrite(MOTOR5A, HIGH);
digitalWrite(MOTOR5B, LOW);
digitalWrite(MOTOR6A, HIGH);
digitalWrite(MOTOR6B, LOW);
analogWrite(MOTOR1,255);
analogWrite(MOTOR2,127);
analogWrite(MOTOR3,255);
analogWrite(MOTOR4,255);
analogWrite(MOTOR5,127);
analogWrite(MOTOR6,127);
  
      }
  }

This information enough? Did I miss something?

1 Like

OK, since you cannot use multiple things at once on a serial port… and the Mega has three more :wink: switch your ESP to pins 18(TX1) & 19(RX1) and use Serial1 instead for connection.

https://www.arduino.cc/en/Reference/Serial

EDIT Ahh, I see your sketch already is using Serial1, so that is why you can’t connect to the ESP… you have it connected incorrectly. Switch to those pins listed above.

Aaaahh, okay, i will try it and update later… Thank you :grin::grin:

Update: I change TXD from ESP8266 and connect to RX1 pin 19 from arduino, RXD from ESP8266 and connect to TX1 pin 18 from arduino and it’s work. I’m get this from my serial monitor
[19]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ / '/
/
//_, /////_
/
__/ v0.4.10 on Arduino Mega

[605] Connecting to myssid
[3655] AT version:1.1.0.0(May 11 2016 18:09:56)
SDK version:1.5.4(baaeaebb)
Ai-Thinker Technology Co. Ltd.
Jun 13 2016 11:29:20
OK
[6788] +CIFSR:STAIP,“xxx.xxx.xxx.xxx”
+CIFSR:STAMAC,“xx:xx:xx:xx:xx:xx”
[6796] Connected to WiFi
[17000] Ready (ping: 12ms).

Thank you @Gunner Sir… :grin::grin::grin:

2 Likes

No problem… I have a “similar” setup myself… well, somewhere under all the wires and components :slight_smile:

The ESP-01 is on the breadboard at mid left.

It’s amazing the amount of people with the same mistake…

Think about below picture…

image

Tx -------> Rx
Rx <-------Tx

As easy as that… :wink:

2 Likes

Ah, but this OP issue was not mixing up RX and TX, but using the wrong RX/TX pins in for first place.

Like your diagram, only one person is turned away and communicating with an uninterested cat instead :stuck_out_tongue:

@psoro nice illustration. I’ll publish it somewhere under my name :slight_smile:

Oh! I should have included the copyright… :wink:

2 Likes

Sir @Gunner, how you connected your esp8266 module with power supply module?? Do you use resistor, capacitor, etc or just directly connect from your power supply module? I have problem with esp and connection, if i already conected, it just connected for under 1 minute (because i put all of my module in mobile robot and if i controlled my robot to move, maybe just move +/-30cm and connection resetting, or if want to go through some obstacles, after reach the obstacles and little bump with the obstacles, connection resetting too). I thing that happend because vibration or shock when i controlled my robot to move make the wiring from my power supply module to esp not connected so well, or something else.

Thank you in advance… :grinning::grinning:

Well, that particular setup I showed above doesn’t move around, nor does it have any motors that can draw heavy current and cause brownout/resets.

But I used a breadboard PSU with 3.3v for the ESP-01. I have also added in a couple of capacitors (one electrolytic on the breadboard and one tantalum on the ESP) across the 3.3v and GND to help smooth out the power.

I used 5v from PSU to servo motor (i used 6 servos) and arduino, then 3.3v from PSU to ESP8266, is that possible to cause brownout/resets? What capacitor (both, capacitor on the breadboard and ESP) you used? i wan to try used capacitor too… :grinning::grinning:

What type & capacity of PSU? You will want to have more than enough current capacity for both the 5v (depends on the servos) and the 3.3v (min 800mA - preferably 1A).

Most any capacitor should work, I am using a 16v 470uf electrolytic… dont remember the tantalum, but again not super critical. Google for details.

I used same as yours from Ywrobot, and my power supply from lipo battery 7.4v 2s 25C. So the connection like this?

Should be OK for light duty use, but NO good for Servos!

Those simple breadboard PSU’s are minimalistic for current capacity… I think they are rated for around 700mA max, which is why I have the caps in the first place :wink: but I think I am still having power issues at times.

EDIT - in fact, I just realised I was also running my DHT22 on the 3.3v rail… no need for that, so I have since moved it to the 5v rail so that only the ESP-01 is on the 3.3v.

2nd EDIT - Depending on the quality of the servos, you could probably run them directly off of the 7.2v batteries… I know I have even pushed servos up to 9v in the past… but usually kept in between 6-8v

So i can said, if i used that PSU just for esp from 3.3v and arduino from 5v, and run servos directly to battery, maybe can minimize power issues, right? :wink:
Note: i used mg90s servos and they worked between 4.8 and 6v in datasheet

The Arduino already has a regulator, so it can run directly off the batteries. Plug into the vin pin, NOT the 5v pin.

Then if the single 3.3v rail doesn’t seem to be enough for the ESP, you can switch both of the Ywrobot PSU rails to 3.3v and wire the positives in parallel for double the current of just one rail.

Aah, ok… I will try it… Thank you Sir @Gunner :grinning:

Update: I try to change my power supply wiring become:
Battery1 --> step down module --> servo
Battery1 --> motor driver --> motor DC
Battery1 --> Ywrobot PSU --> 16 470uf capacitor --> ESP8266
Battery1 --> Arduino Mega 2560

and my esp connection more stable…

Note: my wiring was:
Battery1 --> Motor driver --> motor DC
Battery1 --> Ywrobot PSU 3.3v–> ESP8266
Battery1 --> Ywrobot PSU 5v --> Servo and Arduino Mega 2560

this make my ESP always resetting if my servo worked…

2 posts were split to a new topic: Problem with Mega and ESP-01