0

I have some python example script from ADAFRUIT which controls a servo and it works!

I would like to execute it to change the ServoMin and ServoMax values by calling two values from command line. The problem I am having is that it seems not to like it when I import sys and set ServoMin = (sys.argv). Im not sure why its not accepting int or str. Any ideas?

Here is the code body:

#!/usr/bin/python

from Adafruit_PWM_Servo_Driver import PWM
import time
import sys

# ===========================================================================
# Example Code
# ===========================================================================

# Initialise the PWM device using the default address
# bmp = PWM(0x40, debug=True)
pwm = PWM(0x50, debug=True)

servoMin = 150  # Min pulse length out of 4096
servoMax = 600  # Max pulse length out of 4096

def setServoPulse(channel, pulse):
  pulseLength = 1000000                   # 1,000,000 us per second
  pulseLength /= 60                       # 60 Hz
  print "%d us per period" % pulseLength
  pulseLength /= 4096                     # 12 bits of resolution
  print "%d us per bit" % pulseLength
  pulse *= 1000
  pulse /= pulseLength
  pwm.setPWM(channel, 0, pulse)

pwm.setPWMFreq(60)                        # Set frequency to 60 Hz
while (True):
  # Change speed of continuous servo on channel O
  pwm.setPWM(0, 0, servoMin)
  time.sleep(1)
  pwm.setPWM(0, 0, servoMax)
  time.sleep(1)
2
  • sys.argv is a list. Did you mean sys.argv[1]? Commented Apr 19, 2013 at 23:50
  • sys.argv returns a list, try this: servoMin,servoMin=map(int,sys.argv[1:3]) Commented Apr 19, 2013 at 23:51

1 Answer 1

2

sys.argv is an list of arguments, you need to access the arguments, then convert them to Ints.

This should do it:

servoMin = int(sys.argv[1])
servoMax = int(sys.argv[2])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.