ico
October 27, 2023, 11:21pm
1
I am writing a script to control two servos from an Arduino Portenta H7 with the vision shield, and got started from the Cheat Sheet here .
I calibrated the servos using a servo tester and center is pretty close to 1500. Each has ~120 degrees of movement. I can control them predictably using Arduino code, but
x_signal_pin = Pin("PC6", Pin.OUT_PP, Pin.PULL_NONE)
y_signal_pin = Pin("PC7", Pin.OUT_PP, Pin.PULL_NONE)
timer = Timer(3, freq=50)
x_channel = timer.channel(1, Timer.PWM, pin=x_signal_pin, pulse_width=1500)
y_channel = timer.channel(2, Timer.PWM, pin=y_signal_pin, pulse_width=1500)
x_channel.pulse_width(10)
time.sleep(2)
x_channel.pulse_width(1500)
Doesn’t move the way I expect which is,
Center
Move to one side
sleep
Move to center
Am I assuming or doing something wrong?
ico
October 27, 2023, 11:57pm
3
from machine import PWM
ImportError for the name PWM. Do I need to install this module?
Mmm, it should be built-in. Okay, let’s use the PYB module then.
x_channel.pulse_width(10)
time.sleep(2)
x_channel.pulse_width(1500)
Doesn’t seem right. A pulse width of 10 is usually ignored by a servo. Try:
x_channel.pulse_width(1500)
time.sleep(2)
x_channel.pulse_width(1000)
time.sleep(2)
x_channel.pulse_width(2000)
time.sleep(2)
x_channel.pulse_width(1500)
ico
October 28, 2023, 2:01am
5
Is it possible that it’s unavailable because of the hardware?
You’re right about the pulse width range, these servos seem to operate in 500-2500usec.
They are moving but they don’t seem to be moving into the correct positions based on what I’ve seen with Arduino code and the servo tester. Almost like they are skewed 90 degrees off, at times.
Were you using pulse lengths with the Arduino or a library ? Typically you need to calibrate the ranges.
ico
October 28, 2023, 2:50am
7
Looks like I was using the library that takes angles, so I’ll ignore the Arduino implementation for now.
Here is what 1500us (not 500 ) looks like when I attach the servos to a consistency tester (black arrow for reference):
And after running the micropython code:
// hit media upload limit, I’ll upload in a second post
code:
import pyb
from pyb import Pin, Timer
import sensor
import time
x_signal_pin = Pin("PC6", Pin.OUT_PP, Pin.PULL_NONE)
y_signal_pin = Pin("PC7", Pin.OUT_PP, Pin.PULL_NONE)
timer = Timer(3, freq=50)
x_channel = timer.channel(1, Timer.PWM, pin=x_signal_pin, pulse_width=1500)
y_channel = timer.channel(2, Timer.PWM, pin=y_signal_pin, pulse_width=1500)
time.sleep(2)
# test bottom servo movement
x_channel.pulse_width(1500)
time.sleep(2)
x_channel.pulse_width(1000)
time.sleep(2)
x_channel.pulse_width(2000)
time.sleep(2)
x_channel.pulse_width(1500)
Are you saying I can fix this with calibration?
Thanks for your time, btw.