Coder Social home page Coder Social logo

esp32servo360's Introduction

ESP32Servo360.h

Version 0.2.2

Control Parallax High Speed 360° servos with ESP32 boards. Works with interrupts and multitasking (FreeRTOS).
About this motor:

How to

Suggested equipment

  • 6V 2A power supply.
  • ESP32 Dev board.
  • Breadboard.
  • Jumper wires.
  • Parallax High Speed 360° servos
  • Micro USB to USB 2.0

Installation for ESP32 boards

  1. Download the latest Arduino IDE then open it.
  2. Download the ESP32Servo360 library from Sketch > Include Library > Manage Libraries..., search for ESP32Servo360 and install the latest release.
  3. Go to File > Preferences, add https://dl.espressif.com/dl/package_esp32_index.json to Additional Boards Manager URLs, don't forget to separate the URLs with a comma.
  4. In Board > Boards Manager, search and install the latest core esp32.

Connecting the ESP32 to a Servo

wiring

  1. Wire like the image above. Some pins may not work properly (GPIO0 for instance). Make sure to connect the ESP32 GND pin to the ground of the 6V power supply.
  2. Connect your esp32 to your computer and the motor to your 6V power supply.
  3. On Arduino IDE, find your board in Tools > Port. Mine, shows as /dev/cu.SLAB_USBtoUART.
  4. In Board > Boards Manager > ESP32 Arduino, select "DOIT ESP32 DEVKIT V1".
  5. Run one of the examples (File > Examples > ESP32Servo360). Check if the pins matches the code servo.attach(4, 16).

Instantiation

ESP32Servo360 servo;

Or

ESP32Servo360 servo([int offsetAngle], [int rpm], [int deceleration], [int minPulseWidth], [int maxPulseWidth], [int channel]);

Set optionnal parameters directly at the creation of an instance.

  • offsetAngle Default is 0 degrees.
  • rpm Default speed of the servo (Turns per Minute). Maximum is 140.
  • deceleration Ease-out. By default, deceleration starts at 70 degrees from target angle.
  • minPulseWidth PWM signal of the Hall Sensor at 0 degrees. Default is 32.
  • maxPulseWidth PWM signal of the Hall Sensor at ~360 degrees. Default is 1067.
  • channel ESP32 LEDC channel used to send the PWM signal to the motor. Automatic by default.

Methods

Settings

servo.adjustSignal(int minPulseWidth, int maxPulseWidth)

For better readable angle accuracy, manually set the PWM signal of the internal Hall Effect Sensor.

  • Default minPulseWidth is 32. Signal at 0 degrees.
  • Default maxPulseWidth is 1067. Signal at ~360 degrees.
  • Get the values with the method servo.calibrate();.

servo.attach(int controlPin, int feedbackPin)

Attach to the correct pins of your servo.

  • controlPin is the white cable.
  • feebackPin is the yellow cable.

servo.calibrate()

For better readable angle accuracy, automatically set the PWM signal of the internal Hall Effect Sensor.
The servo will turn and give you the result through Serial.

servo.detach()

Disconnect the servo from its pins.

servo.setDeceleration(int deceleration)

To prevent any bouncing, especially due to high RPM.
You can start the deceleration to a higher angle from the target angle.
Default is set to 180 degrees.

servo.setOffset(int offsetAngle)

If you decide to change the orientation of your motor, you can offset its zero position.

servo.setSpeed(float rpm)

Change the maximum RPM (Rotation Per Minute) of your servo. Default is 70 RPM.

servo.setAdditionalTorque(float force)

For easing rotations only, add more force when speed is minimal (at start & end of movement).
Default is 5.

servo.setMinimalForce(float force)

Minimal force required for the servo to move. minimal force may barely move the servo, bigger force may do infinite bounces.
Default is 7.

Actions

servo.clearTurns()

Reset the number of turns.

servo.hold()

Stop and hold the servo to its current angle. Will be harder to turn the motor by hand. Disable this state by executing another rotation or calling servo.release();.

servo.release()

Releases the servo from its hold state.

servo.rotate(float angle)

Rotate from current position.

servo.easeRotate(float angle)

Rotate by given angle with a ease-in-out-quad move.

servo.rotateTo(float target)

Rotate to a specific position.

servo.easeRotateTo(float angle)

Rotate to a given angle with a ease-in-out-quad move.

servo.spin([float rpm])

Spin clockwise or anticlockwise at a the default RPM if the parameter unset.
Setting the parameter won't change the saved RPM of the servo. Instead use the method servo.setSpeed(); . Value must be between -140 and 140.

servo.stop()

Stop the rotation of the servo.

servo.wait()

Wait for the motor to finish its rotation. Will hold the execution of the main loop().

States

servo.attached()

true if servo is attached to pins. Returns bool.

servo.busy()

true if servo is still executing a rotation or holding an angle.
Returns bool.

Feedback

servo.getAngle()

Get the amount of rotation. Angle will go below 0 and above 360 degrees.
Returns a float.

servo.getOrientation()

Get the orientation between 0 to 360 degrees.
Returns a float.

servo.getTurns()

Get number of turns. This will be reset after a reboot of the board.
Returns int.


image Signal Spectacle, ECAL workshop with Pinaffo—Pluvinage, 2020

Author, maintainer: Sébastien Matos

ECAL 2020 Bachelor Media & Interaction design.

esp32servo360's People

Contributors

matoseb avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.