Skip to content

Instantly share code, notes, and snippets.

@RRMoelker
Created July 14, 2016 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RRMoelker/01b2a03eeb0cb6b0f18400ccc9bc439c to your computer and use it in GitHub Desktop.
Save RRMoelker/01b2a03eeb0cb6b0f18400ccc9bc439c to your computer and use it in GitHub Desktop.
Hello servo using WiPy servo library https://github.com/RRMoelker/WiPy-servo
# coding=utf-8
#
# Rotate servo over full rotational range
#
import time
from machine import Pin
from servo import Servo
# Configuration
SERVO_WAIT = 100 # in ms
servo_pin = 9 # GP pin
# Servo specific constants
PULSE_MIN = 900 # in µs, actually bit higher than specs indicate
PULSE_MAX = 2100 # in µs
FREQUENCY = 50 # Hz
ROTATIONAL_RANGE_100 = 12000 # 120deg * 100
led = Pin('GP25', mode=Pin.OUT)
led(0) # turn off the heartbeat LED
servo = Servo(servo_pin,
FREQUENCY,
ROTATIONAL_RANGE_100,
PULSE_MIN,
PULSE_MAX)
for angle in range(0, 120):
servo.angle(angle * 100)
time.sleep_ms(SERVO_WAIT)
led(1) # turn on the heartbeat LED
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment