luiskrlos84
Posts: 9
Joined: Mon Mar 27, 2017 10:27 pm

Can anybody help with this Error?

Thu Mar 30, 2017 10:38 pm

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'

DirkS
Posts: 10363
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Error

Thu Mar 30, 2017 10:41 pm

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

luiskrlos84
Posts: 9
Joined: Mon Mar 27, 2017 10:27 pm

Re: Error

Thu Mar 30, 2017 11:20 pm

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

User avatar
Paeryn
Posts: 2966
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Error

Fri Mar 31, 2017 12:43 am

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()
She who travels light — forgot something.

luiskrlos84
Posts: 9
Joined: Mon Mar 27, 2017 10:27 pm

Re: Can anybody help with this Error?

Wed Apr 05, 2017 12:32 am

thanks it already worked, I only changed the GPIO number and used [17,27]

Return to “Beginners”