Servo Issue


I’ve been using the following example code with the aim of moving a servo through an arc using the tick-tock function:
/// April controlling a servo with PWM

// Configure hardware

// the servo used in this example have ~170 degrees of range. Each servo has three pins: power, ground, and pulse in
// The width of the pulse determines the position of the servo
// The servo expects a pulse every 20 to 30 ms
// 0.8 ms pulse -> fully counterclockwise
// 2.6 ms pulse -> fully clockwise
// set up PWM on both pins at a period of 20 ms, and initialize the duty cycle
hardware.pin1.configure(PWM_OUT, 0.02, 0.045);

server.log(“Hardware Configured”);

class servo extends InputPort

name = "servo position"
type = "number"

function set(value) {
    hardware.pin1.write(0.04 + (value * 0.09));
    server.log(format("%s set to %.2f", name, value));


// imp.configure registers us with the Imp Service
// The first parameter Sets the text shown on the top line of the node in the planner - i.e., what this node is
// The second parameter is a list of input ports in square brackets
// The third parameter is a list of output ports in square brackets
imp.configure(“April Dual Servo Controller”, [servo()], []);

The servo does not respond to this. I connected the same servo to an Arduino to test and it is working fine.
I also thought it may be a power issue so I used the red and black (positive and negative) from the Arduino and only added the white (control) wire to the electric imp, pine 1.
After this didnt work I thought it was because the earths were not common so I bridged them in case this was needed. It didnt help. The servo is still not working with the imp.

Does anyone have any suggestions?


EDIT: I switched to Pin2 and it worked. Lesson of this evening, before you spend hours trying the same thing over and over, check your soldering connections :slight_smile: