0

I am currently working on my FYP. I need to control 15 servos (13 for x2 Robotic Arms + 2 for Camera) and 4 motors of my Robotic kit via webserver. I have the following options:

  1. NodeMCU
  2. Arduino Mega + ESP8266

Now since NodeMUC has only 10 digital pins the only option I am left with is (Arduino Mega+Esp8266). I have used the following code to control servo on a NodeMCU.

#include <Servo.h>
#include <ESP8266WiFi.h>

Servo servo;

const char* ssid = "ssid";
const char* password = "password";
WiFiServer server(80);
void setup() {
  servo.attach(4); //or any pin

  servo.write(0);

  Serial.begin(115200);
  delay(10);

  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");

  // Start the server
  server.begin();
  Serial.println("Server started");

  // Print the IP address
  Serial.print("Use this URL to connect: ");
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Serial.println("/");

}

void loop() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }

  // Wait until the client sends some data
  Serial.println("new client");
  while(!client.available()){
    delay(1);
  }

  // Read the first line of the request
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush();
  if (request.indexOf("/?30") != -1)  {
    servo.write(30);
  }

//
  if (request.indexOf("/?90") != -1)  {
    servo.write(180);

  }

  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println(""); //  do not forget this one
  client.println("<!DOCTYPE HTML>");
  client.println("<html>");

  client.println("<br><br>");
  client.println("<a href=\"/?30\"\"><button>30</button></a>");
  client.println("<a href=\"/?60\"\"><button>60</button></a>");
  client.println("<a href=\"/?90\"\"><button>90</button></a>");
  client.println("<a href=\"/?120\"\"><button>120</button></a>");
  client.println("<a href=\"/?150\"\"><button>150</button></a>");
  client.println("<a href=\"/?180\"\"><button>180</button></a>");
//  client.println("<a href=\"/TIMER=30\"\"><button>Thirty Mins</button></a><br />");
  client.println("</html>");

  delay(1);
  Serial.println("Client disonnected");
  Serial.println("");

}

My question is that the can the code written for NodeMCU be used with ESP8266 to control Arduino Digital Pins? I want the same code to be used.

PS : I don't want to use SoftwareSerial library and ATC commands.

Or some alternative to NodeMCU with same functionality as NodeMCU but with more GPIO pins.

  • you could try Standard Firmata sketch in Arduino and FirmataMaster library in ESP8266 – Juraj Nov 7 '17 at 7:40
  • thanks! but can the same code for NodeMCU be used for ESP2866 also. – Saad Saeed Nov 7 '17 at 13:22
  • your sketch looks like you use the Arduino core for esp8266 on the NodeMCU hardware – Juraj Nov 7 '17 at 13:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.