No response from servo

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
Dramatic Explosion
Posts: 5
Joined: Fri Jul 07, 2017 7:30 pm

No response from servo

Post by Dramatic Explosion » Wed Aug 09, 2017 4:17 am

I have successfully used a script copied to "main" on the pyboard to flash the LED's, etc.
I have also used "PuTTY" to turn the LED's on and off.

No luck getting my servo to move at all, though. The servo control wire is plugged into X1.

When I run this simple script copied to "main" to test my VILROS micro servo model SG90, the servo doesn't move:

SCRIPT:
# servo control
from pyb import Servo

s1 = Servo(1) # an angle servo


# move to 45 degrees; wait 1 second
s1.angle(45)
pyb.delay(1000)

# move to -60 degrees over 1.5 seconds
s1.angle(-60, 1500)

And I get this response (I'm using IDLE):

Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36) [MSC v.1900 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>>
============================ RESTART: F:\main.py ============================
Traceback (most recent call last):
File "F:\main.py", line 2, in <module>
from pyb import Servo
ModuleNotFoundError: No module named 'pyb'
>>>

Also, when I throw angles at it using PuTTY, there is absolutely no movement.

Do I need to install this servo library https://github.com/micropython/micropyt ... al/servo.c ???

If that's my problem, where do I install it? Could not find "micropython/stmhal" anywhere.

Obviously, I'm very new to this. There is probably a simple answer. I just couldn't find it. :oops:

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: No response from servo

Post by pythoncoder » Wed Aug 09, 2017 5:57 am

I'm not clear on how you're using IDLE. It looks to me as if you're running the code on the PC rather than on the Pyboard, given that the line

Code: Select all

import pyb
is failing. This should never fail on a Pyboard. And there is no need to install anything to run a servo.

I'd test as follows. Connect to the Pyboard using a terminal. At the REPL (the >>> prompt) type in your lines one by one:

Code: Select all

 >>> from pyb import Servo
 >>> s1 = Servo(1)
 >>> s1.angle(45)
 
One of the many joys of Python is that you can test code line-by-line.

Incidentally development is easier if you don't alter main.py. Create a module, say "test.py". Then your program doesn't run whenever you reset the Pyboard. There are several benefits to working this way - you might have several versions on your Pyboard and it means you always get a REPL prompt after a reset. Just enter

Code: Select all

import test
to run your script. If you build a stand-alone project which does need to run at power up, you modify main.py to include just the single import statement.
Peter Hinch
Index to my micropython libraries.

Dramatic Explosion
Posts: 5
Joined: Fri Jul 07, 2017 7:30 pm

Re: No response from servo

Post by Dramatic Explosion » Wed Aug 09, 2017 9:53 pm

Got some weird results today.

Before today, I was using IDLE to write a script, and I was naming the script "main" and copying it to flash drive F which is my pyboard. Pretty sure I was doing that right, since the LED scripts worked fine.

Second, I was using PuTTY on COM4 to get a REPL prompt, and again, the LED's worked every time. No problems there.

Here's what I found today: The X1 pin on pyboard responds to commands sent to servo 3. The X2 pin on pyboard responds to servo 4 commands, and so on. X3 is servo 1. X4 is servo 2. I discovered this by moving the signal wire around.

I don't know why. It is what it is. Maybe I need to update firmware on pyboard?

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: No response from servo

Post by dhylands » Wed Aug 09, 2017 10:04 pm

The PYBLITE uses a different processor from the PYBV10/PYBV11 and there were a couple of pins that were changed in order to keep a UART on pins X1 & X2.

There was some discussion about this here:
viewtopic.php?f=6&t=2806&p=16662

If you compare the pinout for the PYBLITE:
https://store.micropython.org/static/st ... 0-AC-D.jpg
and the PYBV11:
https://store.micropython.org/static/st ... v1_1-E.jpg

you can see some differences in the timer channels assigned to the pins X1, X2, X3, and X4. Currently, the servo code maps servo 1 to CH1, servo 2 to CH2, etc.

Dramatic Explosion
Posts: 5
Joined: Fri Jul 07, 2017 7:30 pm

Re: No response from servo

Post by Dramatic Explosion » Thu Aug 10, 2017 2:30 am

Thanks for the answer. :) Yes, I have the PYBLITE. I meant to order the PYBV11. I goofed up from the beginning. :cry:

Post Reply