Examples / Servo control

Servo control

A full servo control panel: immediate and timed moves, soft limits, and homing, with a live gauge and call log.

IntermediateMotionTool
Servo control — the example running

Servo control

A p5.js control panel for one servo — a Pardalote tool that works out of the box (the connection and servo pin are set on the page and remembered by the browser, no code editing). A live gauge draws the arm and every command updates it in real time. Use it to exercise the modern servo API, or to drive the servo directly by dragging the arm.

What This Example Does

Hardware Requirements

Wiring

Servo wire Arduino
Power (red) 5 V
Ground (brown/black) GND
Signal (orange/yellow) Pin 11 (set on the page — the Wiring row)

For more than one or two servos, power them from an external 5 V supply rather than the Arduino's 5 V pin.

Arduino libraries

Install via Arduino IDE → Tools → Manage Libraries:

Install Pardalote itself by copying pardalote-arduino/library/Pardalote/ into your Arduino libraries folder (see the top-level README).

Quick Start

1. Upload the firmware

  1. In Arduino IDE: File → Examples → Pardalote → servo-control. The sketch is two lines:

    Arduino
    #include <Pardalote.h>
    #include <PardaloteServo.h>
    
    void setup() { Pardalote.begin(); }
    void loop()  { Pardalote.run();   }
    
  2. Select your board and upload

  3. Open the Serial Monitor at 115200 baud — on first boot Pardalote asks for your WiFi credentials:

    === Pardalote ===
    No WiFi networks stored.
    === WiFi Configuration ===
    [a]dd  [d]elete  [c]lear all  [s]how  [x] exit
    > a
    SSID: YourWiFiName
    Password: ********
    Saved: YourWiFiName
    > x
    

    Credentials are saved to EEPROM and survive re-uploads. Press w in the Serial Monitor at any point while the board is trying to connect to update them.

    Prefer compile-time credentials? Create a secrets.h file in the sketch folder with:

    Arduino
    #define SECRET_SSID "YourWiFiName"
    #define SECRET_PASS "YourWiFiPassword"
    

    If both are configured, secrets.h is tried first.

  4. Find your Arduino's IP address:

    • UNO R4 WiFi: scrolls across the LED matrix
    • ESP32: printed in the Serial Monitor

2. Open the example

This is a tool — it works out of the box, no code editing:

  1. Open index.html in a browser.
  2. Type the board's IP into the Board IP row and press Connect.
  3. Set the servo pin in the Wiring row under the gauge (default 11) — changing it reconnects and re-attaches.

The browser remembers the IP and pin, so next visit it reconnects with one click. Each control row exercises one part of the servo API — immediate writes, timed moves with an awaited whenDone(), soft limits (watch the clamp appear in the log and on the gauge), and set-home / go-home — with a live gauge and call log underneath.

How It Works

JS
arduino = new Arduino();
arduino.add('myServo', new Servo());   // register the extension
setupConnection(arduino, { store: 'pardalote-servo-control' });   // Board row + connection (connect.js)

// attach + centre once the board is ready (the servo pin is the Wiring row's field)
arduino.on('ready', () => {
    arduino.myServo.attach(11);   // servo pin
    arduino.myServo.center();     // 90°
});

A timed move with awaited arrival:

JS
const move = arduino.myServo.writeTimed(target, duration);  // interpolated on-board
const ok   = await move.whenDone();   // true = arrived, false = safety timeout

The gauge tracks arduino.myServo.angle — the value the library actually applied, already clamped to any soft limits — so a clamped command is visible on screen (and noted in the log). A PWM servo has no position feedback: angle is the commanded value, which for a hobby servo is its state.

Script loading order

Include the pardalote.js bundle (core + every extension) before your sketch:

<script src="../../lib/pardalote.js"></script>
<script src="sketch.js"></script>

Troubleshooting

"Servo doesn't move"

"Servo jitters"

"Servo moves to wrong position on startup"

File Structure

servo-control/
├── index.html      # Canvas page (loads p5.js and the pardalote.js bundle)
├── sketch.js       # Servo control and visualisation
├── connect.js      # Board connection UI (WiFi / USB, remembered per browser)
└── README.md       # This file

dist/
└── pardalote.js    # Pardalote bundle (core + all extensions)

Next Steps