BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Esp8266 as Uno WiFi shell in home robot


#1

Hey there.
Trying to integrate Blynk to my home WiFi robot… I took this project from https://goo.gl/QK3R5g. So I changed code and it’s now looks like that https://pastebin.com/3Vp9EjzS, but not changed what i need most - I need so “cm1”, also executed as V0 pin trigger (when it changing its state to 1 from 0) , and V0 executed as button in Blynk app. How I can change it in code? Thank you.


#2

You could start by posting the formatted code here.


#3
#include <SoftwareSerial.h>
#include <Stepper.h>
#include <ESP8266_HardSer.h>
#include <BlynkSimpleShieldEsp8266_HardSer.h>

//definition of variables
#define BLYNK_DEBUG

#define BLYNK_PRINT Serial
#define EspSerial Serial

ESP8266 wifi(EspSerial);
char auth[] = "???"; //Ключ к Блинку

const int stepsPerRevolution = 500;
int state = 5;

Stepper rightStepper(stepsPerRevolution, 8,9,10,11);
Stepper leftStepper(stepsPerRevolution, 4,5,6,7);

//*****
//SETUP
//*****
void setup()
{
  //start communication
  Serial.begin(9600);
  EspSerial.begin(115200);

  Blynk.begin(auth, wifi, "???", "???");//Точка доступа и пароль

  //Define motor speed
  rightStepper.setSpeed(60);
  leftStepper.setSpeed(60);
}

void loop()
{
Blynk.run();


  if (EspSerial.available())  //verify incoming data
  {
    if (EspSerial.find("+IPD,")) //if there is a message
    {
      String msg;
      EspSerial.find("?"); //look for the message
      msg = EspSerial.readStringUntil(' '); //read whole message
      String command = msg.substring(0, 3); //first 3 characters = command
      String valueStr = msg.substring(4);   //next 3 characters = value
      int value = valueStr.toInt();
      if (DEBUG) {
        Serial.println(command);
        Serial.println(value);
      }move forward
      if(command == "cm1") {
          state = 1;
      }

      //move backward
      if(command == "cm2") {
          state = 2;
      }

      //turn right
      if(command == "cm3") {
          state = 3;
       }

       //turn left
       if(command == "cm4") {
          state = 4;
       }

       //do nothing
       if(command == "cm5") {
          state = 5;
       }

 

//move forward
  if (state == 1) {
    rightStepper.step(1);
    leftStepper.step(-1);
  }
  //move backward
  if (state == 2) {
    rightStepper.step(-1);
    leftStepper.step(1);
  }
  //move right
  if (state == 3) {
    rightStepper.step(1);
    leftStepper.step(1);
  }
  //move left
  if (state == 4) {
    rightStepper.step(-1);
    leftStepper.step(-1);
  }
  //do nothing
  if (state == 5) {
  }

}

Here is the unformatted code. I need so robot understand cm1 command for triggering button from Blynk, as V0, for example. How I need to change it here.


#4

Sorry. It’s formatting not important for now. Problem in correct command. Pardon for my english. I’m not sure what Blynk library already know, so there some code, that possible even not required.


#5

No it’s not important but it’s vital if you want help.

Does the sketch compile as you have some very old libraries?

Are you using an Uno and an ESP01? If not what are you using?


#6

I have installed 0.34 Blynk libraries, as newer don’t have some shield libraries, that I was need. It’s nothing saying about them when compiling. Except if not mess with “cm1” parameters what i trying. Uno and esp-12f.


#7

You will not get much assistance here if you insist on using old libraries… we don’t like to work in the past :wink:

Please confirm the exact hardware you are using.


#8

This


#9

I was trying to determine if they are discrete components or the “problematic” UNO WiFi board.

@Cookins Regardless of the hardware and possibly even the age of the libraries, the code you are using is not really well laid out for use with the Blynk libraries, as you have everything lumped into the void loop(). Blynk requires a constant link to the server, so using timed functions for all other IO is necessary.

There have been many different robot type controls in this forum, but I suspect most use DC motors and motor controllers, as Steppers require precise timing that can be difficult to manage simultaneously with with Blynk’s timing requirements.

I suspect you will need to completely redesign your code to work properly with both steppers and Blynk in a differentially driven robot. Search this forum for Steppers for more info.


#10

That isn’t what I asking… I asking for myself, like what command must be there for button worked! As I understand your can’t help me with sketch then maybe you can say what command must be there so it react on buttons. Even if there DC motors, not steppers.


#11

@Cookins would I by right in thinking you haven’t studied any of the basics of Blynk and that you have gone straight to robotic control?


#12

Start by reading the documentation here: http://docs.blynk.cc/#intro

Then you might be able to better understand how to make that mysterious “button command that makes motors work:stuck_out_tongue_winking_eye:

And you might also want to search around this forum for others examples of robots… like mine for instance:


#13

Will do so then. Assist looking at your project. Nice one. Prepare for questions barrage! :smile: