Micro Maestro 6 Channel & Python

I am trying to control 3 servos with the Micro Maestro with a Raspberry Pi and Python. The problem is when I try to move a servo to an angle of 180 degrees I get an error (red light on controller). It works fine for 0 & 90 but I get an error of 0x0001 (Serial signal error) when I try to move the servo to 180.

Any ideas?

Here is my code:

import serial

class ServoController:
    def __init__(self, controllerPort):
        self.serialCon = serial.Serial(controllerPort, baudrate=9600)

    def moveServo(self, channel, target):
        target = (self.map(target, 0, 180, 656, 2500) * 4) #Map the target angle to the corresponding PWM pulse.

        commandByte = chr(0x84)
        channelByte = chr(channel)
        lowTargetByte = chr(target & 0x7F)
        highTargetByte = chr((target >> 7) & 0x7F)

        command = commandByte + channelByte + lowTargetByte + highTargetByte
        self.serialCon.write(command)
        self.serialCon.flush()

        return target

    def map (self, x, in_min, in_max, out_min, out_max):
        return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min

Hello.

I do not see a reason why this would work for your 0° and 90° target position but not for the 180° position. Could you post your complete code that causes the error?

Also, how are you connecting the Raspberry Pi to your Maestro? Could you please post more information about your setup, including pictures and a saved settings file from the Maestro Control Center?

-Brandon

Here is the code that is calling the ServoController class:

#!/usr/bin/python

# Import modules for CGI handling
import cgi
import cgitb
import ServoController

# Create instance of FieldStorage
form = cgi.FieldStorage()

# Get data from fields
angle = int(form.getvalue('angle'))

control = ServoController.ServoController('/dev/ttyAMA0')
target = control.moveServo(2, angle)

print "Content-type:text/html\r\n\r\n"
print "<html>"
print "<head>"
print "<title>Rotate Arm CGI</title>"
print "</head>"
print "<body>"
print "<h2>Arm Rotated to: " + str(angle) + "</h2>"
print "<h2>Target set as: " + str(target) + "</h2>"
print "</body>"
print "</html>"

When I make the call to move the servo to a webpage, it moves, but I then get an error in the control center. I have attached my settings file and a drawing of the layout. I will also get an error occasional of 0x0011 which is Serial signal error and Serial protocol error.


maestro_settings.txt (1.53 KB)

I noticed you are using a 9V battery. 9V batteries are bad for powering servos, as they cannot deliver much current . Also, most servos are not rated for more than 6V; a 4- or 5-cell NiMH battery pack is recommended. From the diagram, it is unclear how you are powering your Raspberry Pi, and it looks like a ground wire is missing from the battery to the servo ground.

It looks like you have the Maestro TX pin connected to the Raspberry Pi. The Raspberry Pi uses 3.3V logic, and the serial output of the Maestro uses 5V to communicate . This could potentially cause problems or damage something. Could you try removing the connection to the Maestro TX pin and leaving the servo power disconnected, then checking to see if you still receive the errors when it sends the command?

If you still receive the errors, could you post a more complete diagram of your entire system and pictures of your setup?

-Brandon