Robot with Esp8266 Shield and Arduino Nano

Hi MakerD,
I ordered two NodeMCU with the the chip CH340G instead of the CP2102, I’ve been using a small converter with the CH340 to flash and program the ESP8266 as Standalone and an Arduino Pro Mini and it works like a charm.
At the moment I use the ESP8266 as a Shield for the Arduino to play with Blynk, I’m not using the Arduino in place of the CP2102, the little converter does this work.

I’ll have a look at Windows 10, many thanks for your advices,

1 Like

Sounds pretty awesome. I look forward to many awesome projects to come. I got two of them with the motor driver boards as well. Ive been able to the shield pretty easily with the romeo ble boards that are UNO compatible. I also tried the hardware serial on the Mega that works much better since there are additional serial ports. Software serial is cool, but if your ESP has 115200 baudrate it wont work unless you flash with firmware the does 9600. 9600 is a limitation to software serial since its not a true serial port. Also, it drops the wifi a lot more. If you need to send a lot of signals in a short period of time it will drive you crazy. I think it would be ok for something like data monitoring. You’re more than welcome. Your project is helping me a lot as well.

Here is what I have so far to control the NodeMCU using the ESP8266 Standalone example and your code as a template. I have added steering that is working for now but just for forward and not reverse. I will add reverse steering tomorrow and next week, I will work on tuning the performance. By the way, the single joystick is no longer available so I used the 2 axis joystick in merge mode and adjusted the code accordingly.

//#define BLYNK_DEBUG
//#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>


int motorA ;
int motorB ;
int X=0;
int Y=0;
int factor=0;
int maximo=0;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "b41ff7f1659b4badb694be4c59601c2c";

void setup()
{
  // Set console baud rate
  Serial.begin(9600);


 Blynk.begin(auth,"100Grand","Mob4life");

 pinMode(motorA, OUTPUT); 
 pinMode(motorB, OUTPUT);
 pinMode(0,OUTPUT);
 pinMode(2,OUTPUT);

}

 BLYNK_WRITE(V1) 
{
  int X1 = param[0].asInt();
  X=X1;
  int Y1 = param[1].asInt();
 Y=Y1;
 
}

 BLYNK_WRITE(V0)//      slider  de 100 a 255!!!!
{
 int vel = param.asInt(); 
 maximo=vel;
}

void loop()
{

  if(X == 128  &&  Y == 128)  //  Stop
  {
   motorA = 0;
   motorB = 0;
   analogWrite(5, motorA);  
   analogWrite(4, motorA);
   analogWrite(0, motorB);  
   analogWrite(2, motorB);
   } 
    
   if(X > 123 && X < 132 && Y >= 129)   //Forward
  {
    motorA = Y;
    motorB = Y;
    
    motorA = map(motorA, 129,255 , 450,maximo);
    analogWrite(5, motorA);
    digitalWrite(0,LOW);
    motorB = map(motorB, 129,255 , 450,maximo);
    analogWrite(4, motorB);
    digitalWrite(2,HIGH);
  }

 else if(X > 123 && X < 132 && Y <= 127)   //Reverse
  {
    motorA = Y;
    motorB = Y;
    
    motorA = map(motorA, 127,0 , 450,maximo);
    analogWrite(5, motorA);
    digitalWrite(0,HIGH);
    motorB = map(motorB, 127,0 , 450,maximo);//something is wrong with HIGH signal
    analogWrite(4, motorB);
    digitalWrite(2,LOW);
  }

  else if(Y > 123 && Y < 132 && X <= 127)   //Left
  {
    motorA = X;
    motorB = X;
    
    motorA = map(motorA, 127,0 , 450,maximo);
    analogWrite(5, motorA);
    digitalWrite(0,HIGH);
    motorB = map(motorB, 127,0 , 450,maximo);//something is wrong with HIGH signal
    analogWrite(4, motorB);
    digitalWrite(2,HIGH);
  }

   else if(Y > 123 && Y < 132 && X >= 127)   //Right
  {
    motorA = X;
    motorB = X;
    
    motorA = map(motorA, 129,255 , 450,maximo);
    analogWrite(5, motorA);
    digitalWrite(0,LOW);
    motorB = map(motorB, 129,255 , 450,maximo);//something is wrong with HIGH signal
    analogWrite(4, motorB);
    digitalWrite(2,LOW);
  }

   if(X >= 129 && Y >= 129)   //Forward Right Steering
  {
    motorA = Y;
    motorB = Y;
    factor = X;
    factor= map(factor,129,255, 0,200);
    
    motorA = map(motorA, 129,255 , 450,maximo);
    analogWrite(5, motorA);
    digitalWrite(0,LOW);
    motorB = map(motorB, 129,255 , 450,maximo);
    analogWrite(4, (motorB-factor));
    digitalWrite(2,HIGH);
  }

  else if(X <= 127 && Y >=129)   //Forward Left Steering
  {
    motorA = Y;
    motorB = Y;
    factor = X;
    factor= map(factor,127,0, 0,150);
    
    motorA = map(motorA, 129,255 , 450,maximo);
    analogWrite(5, (motorA-factor));
    digitalWrite(0,LOW);
    motorB = map(motorB, 129,255 , 450,maximo);
    analogWrite(4, motorB);
    digitalWrite(2,HIGH);
  }
  
 Blynk.run();
}
2 Likes

Ok guys so a couple of ESP modules I ordered arrived yesterday. I have wired them up as per psoro’s schematic except I am using a separate 5V supply for now (not from the Nano). Nice red LED on the voltage regulator. I have a basic sketch with authorisation code, SSID and password and it all compiles ok.

I need to move back a step because I notice the ESP is booting to access point mode. It shows up as ESP_11XXXX without any security. In fact some of my Pi’s are automatically connecting to the access point. The IP addresses of devices connecting to the ESP are 192.168.4.1 and 192.168.4.2 etc.

The firmware on the ESP is believed to be version 0.50.0.0 SDK 1.4.0. I have ttl2USB adapters if needed. Am I right in thinking I need to send AT commands to the ESP to change from an access point to connecting to my router? Is it not possible to make the changes via a browser? Can someone direct me towards up to date information for the initial setting up of the ESP’s?

EDIT: I found the full set of AT commands and all is working fine now.

1 Like

Hi Costas!
I’m happy to read you did it! Enjoy playing with the ESP and Blynk!

1 Like

The trick is that software serial is limited to 9600 BPS so if your ESP is stuck at 115200 like many are then that will make it not work. Any firmware that gives you 9600 should work. I used the 9.5 for arduino communication.

Hi!

Your project is really awesome, I’m doing something very similar. The only problem I seem to be having is lag between the time the Blynk app sends a command, and the time the ESP8266 processes and sends to Arduino.

Did you have to do anything special to reduce this lag? I have basically the same code as you, with the same setup. I do receive the commands and my motors respond properly, but there’s almost 3 seconds between the action I do on the Blynk app, and the response.

Did you tweak baud rates?
Are you connecting to the Blynk servers or your own local server?

Any small tidbits would be a great help!

Hi cyberbum,
The Local Server did the trick! It works without lags. Use it if you have a chance.

Kind regards

Hi!

Thanks for replying:) How about your ESP8266, do you know which version of the firmware you are running?

I have a local server, and I’ve updated my ESP8266 firmware to 1.5.1 (latest), so there were some improvements but not enough. Basically when I slide up a joystick in the Blynk Android app, it takes about 2 seconds for it to be processed and seen (wheel turning). It used to be almost 5 seconds before. It’s not enough close to what you have in your video, which looks like < 500ms response.

Have you tried running older firmware like 0.9.2? I think I use that and it works pretty nice.

It could be a matter of interference on your wifi network from surrounding networks (it usually is …) or just a generally bad connection.

I know it’s a bit stupid, but can you try with ethernet? That way you should be able to determine where the lag is coming from.

Hi! Thanks for replying:)

I think I’ll have to test the ESP directly (no Blynk) using Arduino + ESP. That way I can measure if the ESP is actually performing well. I’ll post with more information soon (in case others run into problems like mine).

Hi!
The firmware I use is “AI-v0.9.5.0 AT”
I agree with @Lichtsignaal, it could be a bad connection.

The only thing I have seen (as all of you) is that the ESP has little coverage, if I go with the Robot far from the router the signal is lost really fast…

Thanks for the info! I did try this: instead of a slider in Blynk, I tried using a push button. When I receive its value I just set it to 255 or 128 (no movement).

With that, the latency is very small (I’d say 300-500ms for my motor to react), much better! When I try using the slider, I notice that the data is received, but it’s very slow to stream in.

Still investigating…

I’ve done some more tests, but not yet done. I took Blynk out of the equation to see if it’s hardware related. I run the WifiEsp library and use a modified WebServer. I coded an app for iOS using Cocos2dx (for UI), and I run the app with the Simulator.

I basically establish a TCP connection to my ESP, and send data. I can see from the output that it is much faster. I still have more testing to do, but it does seems that there’s some kind of buffering that is happening that can slow down reception of data.

That would explain by a Blynk joystick could introduce latency because it sends many packets.
On the Blynk side, I turned on tracing on my local server. I did notice that from my Android app to the local server, there could be large hiccups (greater than 2 seconds) when receiving a hardware pin message. I’d imagine there’s a certain amount of latency from Android app -> Local Server, and then Local Server-> ESP hardware.

I’ll do more tests tonight to come up with a conclusion, but it’s starting to look that in my case, using Blynk does not allow me to have enough responsiveness to drive my little robot vehicle.

The only thing I find maddening is that psoro’s vehicle works so well!! I wish mine would’ve worked so nicely without much latency.

Do you connected to local server via local IP? Did you used local Wi-Fi on phone?

1 Like

Hi cyberbum,
I’m afraid I can’t help you as I wanted, it seems your knowledge regarding ESP is bigger than mine…
What I can tell you is the rest of my set up but it’s so simple that I think it wouldn’t help you…

This is where Blynk enters… It does the “magic” and everything works…

Just one silly thing I remember regarding my Rpi as local server, at first, I used a WiFi Dongle and I changed to the RJ45 network socket… Time ago the WiFi signal from my old router was really bad, I’ve got a new router but I’m still using the RJ45.

Hopefully someone will be able to help you.

Regards

Hi!

Yes I was connected to a local server (running on my macbook) using IP. I was also on my local Wifi with my Android phone. My wifi doesn’t have much interference, and I have already run a peer to peer app on my Android to my macbook with very low latency.

Hi all,

Ok, so I finally got my robot car to respond with under 100 ms or so latency (basically I don’t notice it anymore, it’s near instant while moving the joystick). Unfortunately, I couldn’t do it with Blynk, I wrote my own iOS app using Cocos2dx for the UI, and connect via tcp to my ESP8266-01 to send data.

Here’s what I found:
-The Blynk single axis joystick (though I’ve noticed they have been removed) will send values as fast (or so it seems) as you move the slider. All this data is first sent to the local server (already incuring latency + processing time). It is then forwarded to my ESP (adding more latency from server to my ESP). Maybe it’s my ESP hardware, but it’s not super fast to process tons of data. I didn’t analyze how much data it receives from the local server, but it was large enough to that my ESP had trouble keeping up.

-The “hiccups” I would see on the local server that I mentioned above. Sometimes, it seemed when the local server processed a heartbeat message, it would seem to not process my hardware message quickly there-after. Not 100% sure, just sometimes I noticed while tailing logs. The bad thing was sometimes this hiccup would be when sending the “center” value, to stop my motors from spinning. If I was testing it out on the ground, my robot would’ve basically crashed in a wall.

-So my final solution was using my own slider/joystick, and throttle updates to about one update per 200 milliseconds, except when my slider falls back to the center position, which basically shuts off the motors. I send basically 3 bytes : one byte for vertical/horizontal axis, one byte for value (0-255), and a terminating byte. This lets my ESP “breathe” more easily and allows to process more data rapidly.

All of this leads to me being able to control my robot RC with fairly low latency.

Some questions for the Blynk guys:
-Are you going to open-source the app code as well? It would’ve been nice to see how the widgets send their data (how often, how large the data is)
-Will it be possible to directly connect to hardware, rather than passing by a server? It adds unnecessary latency for projects that require low-latency communication
-Why did you kill the single-axis widget?:slight_smile:

Hello. Most probably weak point in your setup is ESP or wiring. @vshymanskyy was able to build copter via Blynk with low latency.

No.

It would’ve been nice to see how the widgets send their data (how often, how large the data is)

This info is open. Briefly - 5 bytes header + body. Body is usually 8-12 bytes. You may think that this is a lot. But considering TCP/IP packet header itself (40 bytes) this not much. So your packet is 43 bytes. Blynk packet is ~55 bytes. So in terms of latency this is almost the same. Also for joystick and slider we cut 2/3 of events, cause our tests show that most of hardware cannot handle such load. And ESP if one of the weakest chip here.

Yes, we even have internal prototype for that. See our roadmap here. You may vote for direct connect to make it happen faster :wink:.

It repeats the functionality of slider.

The copter example wasn’t good for me, he is using an ESP8266 ESP-07 ESP-12, already better than the ESP-01 because it has more GPIO pins than the ESP-01.

I think the weak point is the ESP. If wiring was the problem, my non-Blynk code setup would’ve had the same problems.

Thanks!