3

I am trying to control the enable pin on my L293D motor controller with pwm signal from the pigpio library. I have got to the point where when I execute this code:

import Tkinter as tk
import pigpio
from Tkinter import Tk, Frame, Menu, Label
from PIL import Image, ImageTk
import os
import time
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BOARD)
GPIO.setup(32, GPIO.OUT)
GPIO.setup(35, GPIO.OUT)
GPIO.setup(36, GPIO.OUT)
pigpio.set_mode(16, pigpio.OUTPUT)
pigpio.set_PWM_dutycycle(16, 256)

Whenever I try and run this code it give me this error:

AttributeError: 'module' object has no attribute 'set_mode'

I don't know if I am importing this wrong but any help would be greatly appreciated!

  • 1
    You only need to use a library such as pigpio if you need accurate PWM. For motors software PWM may well be good enough in which case just use RPi.GPIO. If you do need pigpio you need to run and connect to the daemon as described in Usage at abyz.co.uk/rpi/pigpio/python.html – joan Feb 10 '15 at 22:35
  • This fixed the issue Thanks you so much! If you post it as an answer I will select it for you. – Matthew Pitzer Feb 11 '15 at 1:11
4

You only need to use a library such as pigpio if you need accurate PWM. For motors software PWM may well be good enough in which case just use RPi.GPIO.

If you do need pigpio you need to run and connect to the daemon as described in Usage at abyz.me.uk/rpi/pigpio/python.html

Usage

The pigpio Python module uses the services of the C pigpio library. pigpio must be running on the Pi(s) whose gpios are to be manipulated (which may be any networked Pi).

The normal way to start pigpio is as a daemon (during system start).

sudo pigpiod

Your Python program must import pigpio and create one or more instances of the pigpio.pi class. This class gives access to a specified Pi's gpios.

pi1 = pigpio.pi()       # pi1 accesses the local Pi's gpios
pi2 = pigpio.pi('tom')  # pi2 accesses tom's gpios
pi3 = pigpio.pi('dick') # pi3 accesses dick's gpios

pi1.write(4, 0) # set local Pi's gpio 4 low
pi2.write(4, 1) # set tom's gpio 4 to high
pi3.read(4)     # get level of dick's gpio 4

In the pi1 example no machine was specified. In this case pigpio will attempt to connect to the machine running the script. This may be overridden by the environment variable PIGPIO_ADDR. E.g. export PIGPIO_ADDR=paul will cause the script to attempt connection with the machine called paul.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.