HOME - - - - - - - - Table of contents, my Arduino "How To" articles
Other material for programmers     

Using Servos with Arduinos

In general, and in an ESP8266 environment

filename: aht3servo.htm

This is not an "important", or "big" tutorial. And most of the help and advice is in the comments in the code.

The "big secret", such as it is, is that you aren't free to put servos on whatever pin you wish to.

The rules for "ordinary" Arduinos are well covered elsewhere.

For the Sparkfun ESP8266 Thing Dev, I found that pins 2, 5 and 13 worked. Others may work, too... but I am pretty sure that the number that will is limited... the pin has to have PWM generation functionality. Pins that did not work for me: 4, 14, A0.

Here's the code...

//ESP8266Thing-Servo-basic
//Written with Arduino IDE 1.8.1
//Put in a Sparkfun ESP8266 "Thing Dev" (WRL-13711)
//Started 16 Mar 19

#define sPrgm "ESP8266Thing-Servo-basic" //no ; here
#define sVers "16Mar19"

//MOSTLY "works"... just once in a while, especially when starting
//  up, the movement is hesitant. This may be due to running it on
//  3v3. I hope that's all it is!

//Successfully used "Micro Servo 9g / SG90" using the 3v3 from the ESP8266,
//  and 3v3 PWM signal.

//Thanks to ...
//https://circuits4you.com/2019/01/12/esp8266-servo-motor-control/
//.. for much of what is here.

#include <Servo.h>/(Ordinary one)

//"#define ServoPin 14   //D5 is GPIO14" << Didn't work, despite being pp
//https://circuits4you.com/2019/01/12/esp8266-servo-motor-control/
//#define ServoPin D5 //Wouldn't compile
//Also did not work: 14, A0,
//#define ServoPin 2 //Worked!
//Also worked: 5,13 //(5 has on-board LED on it.
//           13 needed for SPI if you want to use that.
#define ServoPin 2// no ; here

Servo MyServo;  // create servo object to control a servo

void setup() {
  delay(500);
  Serial.begin(19200);
  delay(200);
  Serial.println();
  Serial.println("Welcome to servo motor on Sparkfun ESP8266 Dev Thing demo.");
  Serial.println("Program name: ");
  Serial.print(sPrgm);
  Serial.print(", version: ");
  Serial.println(sVers);
  Serial.println();

  MyServo.attach(ServoPin); // attaches the servo
    delay(200);//without this, the servo sometimes
  //"stutters" a bit before it "gets going" with
  //what loop() tells it to do. Only briefly.
  //This only tested on 3v3 so far. Stutter may
  //disappear on 5v Vcc and data to servo.
}

void loop() {
  // put your main code here, to run repeatedly:
MyServo.write(10);   // tell servo to go to position
  delay(800);
MyServo.write(50);   // tell servo to go to position
  delay(800);
  }




   Search this site or the web        powered by FreeFind
 
  Site search Web search
Site Map    What's New    Search

The search engine is not intelligent. It merely seeks the words you specify. It will not do anything sensible with "What does the 'could not compile' error mean?" It will just return references to pages with "what", "does", "could", "not".... etc.
In addition to the tutorials for which this page serves as Table of Contents, I have other sites with material you might find useful.....

Sequenced set of tutorials on Arduino programming and electronics interfacing.
Tutorials about the free database supplied with Open Office/ Libre Office.

Some pages for programmers.
Using the parallel port of a Windows computer.


If you visit 1&1's site from here, it helps me. They host my website, and I wouldn't put this link up for them if I wasn't happy with their service.




Ad from page's editor: Yes.. I do enjoy compiling these things for you... hope they are helpful. However.. this doesn't pay my bills!!! If you find this stuff useful, (and you run an MS-DOS or Windows PC) please visit my freeware and shareware page, download something, and circulate it for me? Links on your page to this page would also be appreciated!

Click here to visit editor's Sheepdog Software freeware, shareware pages.. Material on this page © TK Boyd 3/19


And if you liked that, or want different things, here are some more pages from the editor of these tutorials....

Click here to visit the homepage of my biggest site.

Click here to visit the homepage of Sheepdogsoftware.co.uk. Apologies if the "?FrmAht" I added to that link causes your browser problems. Please let me know, if so?

Click here to visit editor's pages about using computers in Sensing and Control, e.g. weather logging.



To email this page's editor, Tom Boyd.... Editor's email address. Suggestions welcomed!


Valid HTML 4.01 Transitional Page has been tested for compliance with INDUSTRY (not MS-only) standards, using the free, publicly accessible validator at validator.w3.org. Mostly passes.

AND passes... Valid CSS!


Why does this page cause a script to run? Because of the Google panels, and the code for the search button. Why do I mention the script? Be sure you know all you need to about spyware.

....... P a g e . . . E n d s .....