Brookesa05
Posts: 22
Joined: Mon Apr 15, 2013 7:53 pm

Adafruit PWM not Working

Tue Nov 26, 2013 11:13 pm

hey guys, basically i've been an idiot. Long story short i had to re-install my os onto my pi and lost everything other than my code. I have been trying to re-install all stuff needed to get my I2C stuff to work but cant. I have an adafruit 16 channel 12-bit servo controller. it is connected over i2c and i have followed the're instructions but when i run my code all i get is "ImportError: No Module named Adafruit_PWM_Servo_Driver" i have checked everything that i can think of but still nothing.

Code: Select all

from Adafruit_PWM_Servo_Driver import PWM
Any ideas?

User avatar
joan
Posts: 14372
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Adafruit PWM not Working

Wed Nov 27, 2013 9:59 am

The code seems to be written for an Arduino. Did you find a version for the Pi?

Brookesa05
Posts: 22
Joined: Mon Apr 15, 2013 7:53 pm

Re: Adafruit PWM not Working

Wed Nov 27, 2013 12:44 pm

Thanks for the reply, I'm sure that it is code for the pi as it is the same code as i used before on my old pi/SD-card. I downloaded some example code form Adafruit using this.

Code: Select all

$ git clone https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code.git
$ cd Adafruit-Raspberry-Pi-Python-Code
$ cd Adafruit_PWM_Servo_Driver 
I got told to do with on their tutorial for the raspberry pi and Adafruit 16-channel 12-bit servo controller http://learn.adafruit.com/adafruit-16-c ... it-library.
In their example code that i downloaded it it has

Code: Select all

from Adafuit_PWM_Servo_Driver import PWM
at the top of the python file. But when i run it as shown in the tutorial all i get is the No module named: Adafuit_PWM_Servo_Driver.

User avatar
joan
Posts: 14372
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Adafruit PWM not Working

Wed Nov 27, 2013 1:17 pm

It looks likes you'll have to run the script from the Adafruit_PWM_Servo_Driver directory.

Alternatively copy the .py files to the directory your script is in.

I don't know the proper way to set the Python "path".

Brookesa05
Posts: 22
Joined: Mon Apr 15, 2013 7:53 pm

Re: Adafruit PWM not Working

Thu Nov 28, 2013 9:38 am

Thankyou, you was right i just had to move some files around, cheers

Brookesa05
Posts: 22
Joined: Mon Apr 15, 2013 7:53 pm

Re: Adafruit PWM not Working

Fri Nov 29, 2013 9:59 pm

Thankyou, moving it to the right directory fixed my problem.

rickseiden
Posts: 411
Joined: Thu Aug 02, 2012 12:21 pm
Location: Buffalo, NY, USA

Re: Adafruit PWM not Working

Sat Nov 30, 2013 4:07 pm

Brookesa05 wrote:Thankyou, moving it to the right directory fixed my problem.
In case anyone else runs into this in the future, could you post the correct directory that fixed your problem, please?

Thanks,
Rick
There are 10 types of people in this world. Those that understand binary, and those that don't.

User avatar
Douglas6
Posts: 4778
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Adafruit PWM not Working

Sat Nov 30, 2013 5:15 pm

Python will search for modules in the script working directory, and in the directories specified in the environment variable $PYTHONPATH, or if that's not specified, in an installation specific path. The path used is exposed in the Python sys.path property. On my Raspian install:

Code: Select all

>>> print sys.path
['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-ol
d', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages',
'/usr/lib/pymodules/python2.7']
I like to put my common modules in /usr/lib/pymodules/python2.7/

zafiz10
Posts: 1
Joined: Sun Jun 07, 2015 3:25 pm

Re: Adafruit PWM not Working

Sun Jun 07, 2015 3:32 pm

Hi, I'm new to Raspberry Pi and Adafruit and I'm having the same issue. What files do you copy over so that you can run pwm from root instead of manually going into the Adafruit Servo PWM directory?

Return to “Interfacing (DSI, CSI, I2C, etc.)”