An archive of community.esquilo.io as of Saturday January 26, 2019.

Using servo.nut from github examples

cswiger

Ok, I'm stuck already - testing out the github examples, uploaded lib/motors/servo/servo.nut.
Testing it per the in-code usage hints with the below - at first the pin does not even setup output (get just noise on the scope) - then tested gpio output and can make a nice 1Khz square wave with

local pin = GPIO(6);
pin.output();
while(true) { pin.high(); delay(1); pin.low(); delay(1); }

Does this need any output setup? I'll try just a bare pwm test.

// is this how to include a library?
dofile("sd:/servo.nut");

pwm <- PWM(1);
servo <- Servo(pwm, 6);

while(true) {
servo.position(20);
delay(1000);
servo.position(83);
delay(1000);
}

cswiger

Sorry - got it, slight typo in the servo.nut usage - setup is with the channel (0) - not the pin (6) - so this is working

dofile("sd:/servo.nut");
pwm <- PWM(1);
servo <- Servo(pwm, 0);
while(true) {
servo.position(0);
delay(1000);
servo.position(90);
delay(1000);
}

cswiger

Opps - one of things to watch out for with dynamically typed languages (like in python) - use a '.' where there is supposed to be a float! I could not get the servo.position(x) to even move with anything other than servo.position(90) and anything less than 90 - because it was working in int. Once I started using servo.position(10.0) and (45.0) it works.

This loop sweeps the servo thru the range:

for(local i=0.; i<90.; i+=1.0) {
print("Setting pos: " + i + "\n");
servo.position(i);
delay(50);
}

patrick

Good catch. I've updated the usage comments with it.

gwziebe

For the newbies out there like me who still can't get this to work, try enabling PWM from the system menu. It is not enabled right out of the box. smile

patrick

Just an FYI: I updated the servo code so that all integers in the 0 - 90 range work now. It's committed to the github repo: https://github.com/esquiloio/lib