Page 1 of 1

Can anybody help with this Error?

Posted: Thu Mar 30, 2017 10:38 pm
by luiskrlos84
This is my code:

Code: Select all

import time
 
import pigpio
 
servos = [4,7] #GPIO number
 
pigpio.start()
#pulsewidth can only set between 500-2500
try:
    while True:
 
        pigpio.set_servo_pulsewidth(servos[0], 500) #servo 1 to 0 degree
        print("Servo {} {} micro pulses".format(servos, 500))
        time.sleep(1)
        pigpio.set_servo_pulsewidth(servos[1], 1500) #servo 2 to 90 degree
        print("Servo {} {} micro pulses".format(servos, 1500))
        time.sleep(1)
        pigpio.set_servo_pulsewidth(servos[0], 1500)
        print("Servo {} {} micro pulses".format(servos, 1500))
        time.sleep(1)
        pigpio.set_servo_pulsewidth(servos[1], 500)
        print("Servo {} {} micro pulses".format(servos, 500))
        time.sleep(1)
 
   # switch all servos off
except KeyboardInterrupt:
    for s in servos:
 
        pigpio.set_servo_pulsewidth(s, 0);
 
pigpio.stop()
Im getting this error, please help me

Traceback (most recent call last):
File "servo-4.py", line 8, in <module>
pigpio.start()
AttributeError: 'module' object has no attribute 'start'

Re: Error

Posted: Thu Mar 30, 2017 10:41 pm
by DirkS
Did you name your script 'pigpio.py'?
If that's the case then you will have to rename it, as it confuses python. It will find your script instead of the installed pigpio module

Re: Error

Posted: Thu Mar 30, 2017 11:20 pm
by luiskrlos84
DirkS wrote:Did you name your script 'pigpio.py'?
If that's the case then you will have to rename it, as it confuses python. It will find your script instead of the installed pigpio module
No I named the script servo-4.py

Re: Error

Posted: Fri Mar 31, 2017 12:43 am
by Paeryn
luiskrlos84 wrote:This is my code:

import time

import pigpio

servos = [4,7] #GPIO number

pigpio.start()
#pulsewidth can only set between 500-2500
try:
while True:

pigpio.set_servo_pulsewidth(servos[0], 500) #servo 1 to 0 degree
print("Servo {} {} micro pulses".format(servos, 500))
time.sleep(1)
pigpio.set_servo_pulsewidth(servos[1], 1500) #servo 2 to 90 degree
print("Servo {} {} micro pulses".format(servos, 1500))
time.sleep(1)
pigpio.set_servo_pulsewidth(servos[0], 1500)
print("Servo {} {} micro pulses".format(servos, 1500))
time.sleep(1)
pigpio.set_servo_pulsewidth(servos[1], 500)
print("Servo {} {} micro pulses".format(servos, 500))
time.sleep(1)

# switch all servos off
except KeyboardInterrupt:
for s in servos:

pigpio.set_servo_pulsewidth(s, 0);

pigpio.stop()

Im getting this error, please help me

Traceback (most recent call last):
File "servo-4.py", line 8, in <module>
pigpio.start()
AttributeError: 'module' object has no attribute 'start'
That's not how you use pigpio (as far as I can see). To start a pigpio connection you use gpio = pigpio.pi(), then call the functions from gpio (you can use whatever name you want, I called the instance gpio).
Not tested, but something along the lines of :-

Code: Select all

import time
import pigpio
 
servos = [4,7] #GPIO number
 
gpio = pigpio.pi()
#pulsewidth can only set between 500-2500
try:
    while True:
 
        gpio.set_servo_pulsewidth(servos[0], 500) #servo 1 to 0 degree
        print("Servo {} {} micro pulses".format(servos, 500))
        time.sleep(1)
        gpio.set_servo_pulsewidth(servos[1], 1500) #servo 2 to 90 degree
        print("Servo {} {} micro pulses".format(servos, 1500))
        time.sleep(1)
        gpio.set_servo_pulsewidth(servos[0], 1500)
        print("Servo {} {} micro pulses".format(servos, 1500))
        time.sleep(1)
        gpio.set_servo_pulsewidth(servos[1], 500)
        print("Servo {} {} micro pulses".format(servos, 500))
        time.sleep(1)
 
   # switch all servos off
except KeyboardInterrupt:
    for s in servos:
 
        gpio.set_servo_pulsewidth(s, 0);
 
gpio.stop()

Re: Can anybody help with this Error?

Posted: Wed Apr 05, 2017 12:32 am
by luiskrlos84
thanks it already worked, I only changed the GPIO number and used [17,27]