0

Raspberry PWM Servo hat python 3 library
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Raspberry PWM Servo hat python 3 library

by jesusjrobles on Sun Mar 13, 2016 11:28 am

I am a satisfied owner of your Servo HAT for the raspberry, but I have found that the python library for it seems to be downloadable only in a python 2 version.

As it is present, it is at least uncompatible due to usage of outdated "print" sentence for the debugging. I was thinking about trying to check and rewrite it, but strange you not offering a python 3 compatible version.

By now I am using it under python 2. but I am working in a projec in which I will need some extra functions offered by Python 3. And on the other side, due to the fact that Python 3 is supposed to be the "actual" version from some years now, I do not really understand the library stuck with a software that was supposed to pass to the "legacy" status 6 years ago. So I suspect the problem must my mistake not being able to find the right library.

Can so anybody help me?

jesusjrobles
 
Posts: 5
Joined: Sun Mar 13, 2016 11:19 am

Re: Raspberry PWM Servo hat python 3 library

by adafruit_support_mike on Tue Mar 15, 2016 3:10 am

We use Python2 because, at least for a long time, there was no Python3 module capable of handling I2C communication. The smbus module, used in Python2, used techniques that were deprecated in Python3.

We've heard a couple of people mention I2C support for Python3, but haven't seen enough demand to do a full-scale rewite on our Python libraries. If you know of a good I2C solution in Python3, by all means let us know about it.

adafruit_support_mike
 
Posts: 59421
Joined: Thu Feb 11, 2010 2:51 pm

Re: Raspberry PWM Servo hat python 3 library

by jesusjrobles on Tue Mar 15, 2016 4:07 am

Thanks a lot for your answer.

I am sure I am able to use Python 3 with some other devices supposed to be managed by I2C comm (remarkabily, the sense hat).

Never used the smbus library directly, but a simple five minutes google view show last messages asking about python 3 support in smbus are about 3-4 years old, and sooner than that you can even find questions about downgrading some existing i2c related libraries from python 3 to python 2.

A small sample: http://www.linuxcircle.com/2015/05/03/h ... -python-3/

¿What would you want me to check to confirm "a good I2C solution"?

jesusjrobles
 
Posts: 5
Joined: Sun Mar 13, 2016 11:19 am

Re: Raspberry PWM Servo hat python 3 library

by adafruit_support_mike on Tue Mar 15, 2016 10:42 pm

jesusjrobles wrote:¿What would you want me to check to confirm "a good I2C solution"?

Basically one that's used in enough RasPi Foundation and third-party code to warrant a project to rewrite our libraries, and which can coexist with the Python2 code we already have.

We have a hundred or so libraries that use Python I2C, plus associated tutorials that would have to be updated. Making the change would be a fairly large job. We also don't get many requests for Python3.. I think the last one I saw was about six months ago.

Beyond that, Open Source has a meaning. All our code is available on Github, and you're free to modify it with whatever Python3 I2C support you want.

adafruit_support_mike
 
Posts: 59421
Joined: Thu Feb 11, 2010 2:51 pm

Re: Raspberry PWM Servo hat python 3 library

by jesusjrobles on Wed Mar 16, 2016 3:44 am

adafruit_support_mike wrote:Beyond that, Open Source has a meaning. All our code is available on Github, and you're free to modify it with whatever Python3 I2C support you want.


That was my next option, sure. I simply found it strange to be the first one needing this.

A first sight over the code felt "not so complex" to adapt it. I will be returning the news if I am able to set it up working.

Thanks again for your attention :)

jesusjrobles
 
Posts: 5
Joined: Sun Mar 13, 2016 11:19 am

Re: Raspberry PWM Servo hat python 3 library

by jesusjrobles on Sun Mar 20, 2016 2:29 pm

I have checked... and found that it was as simple as it could be.

I already had installed the python 3 smbus module (that is placed in the standard repo, and thus I think it should be considered as official part of the system - it came from a simple "sudo apt-get install python3-smbus" command).

Checking it, it seems that all the functions and structures are similar to the original pyton 2 smbus module. Thus, it should no need to change anything on the smbus.SMBus() calls.

So I started by update the new changed sintax on the print calls adding parenthesys (in the debugging info printing), and the except sentences. About 20-30 line changes in Adafruit_I2C.py and Adafruit_PWM_Servo_Driver.py files.

And... voila!! everything working perfectly.

I have added the updated version of both files, if anybody wants them.
Attachments
pwm_servo_python3.zip
adafruit I2C and PWM Servo Driver .py files updated for python3 usage
(2.9 KiB) Downloaded 164 times

jesusjrobles
 
Posts: 5
Joined: Sun Mar 13, 2016 11:19 am

Re: Raspberry PWM Servo hat python 3 library

by adafruit_support_mike on Tue Mar 22, 2016 3:06 am

Glad to hear it worked for you, and thanks for posting the modifications!

adafruit_support_mike
 
Posts: 59421
Joined: Thu Feb 11, 2010 2:51 pm

Re: Raspberry PWM Servo hat python 3 library

by noob78 on Sat May 14, 2016 4:45 pm

Can anyone help me? I can't install the servo HAT library as shown in the tutorial on the adafruit website. The folder is empty apart from a document saying where has all the python code gone OWTTE. I have installed the following 'sudo pip install adafruit-pca9685' but I'm not sure if this is correct.

noob78
 
Posts: 5
Joined: Sat May 14, 2016 3:48 pm

Re: Raspberry PWM Servo hat python 3 library

by franklin97355 on Sat May 14, 2016 11:01 pm


franklin97355
 
Posts: 21309
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: Raspberry PWM Servo hat python 3 library

by noob78 on Sat May 21, 2016 2:24 am

Yes. I am following this tutorial. I have installed the library using pip with no example code. How can I find some example code to test if my servo works? Which directory does the code have to be in?

noob78
 
Posts: 5
Joined: Sat May 14, 2016 3:48 pm

Re: Raspberry PWM Servo hat python 3 library

by franklin97355 on Sat May 21, 2016 3:47 am


franklin97355
 
Posts: 21309
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: Raspberry PWM Servo hat python 3 library

by noob78 on Sat May 21, 2016 5:04 am

I have set up i2c and it works fine when I carry out i2cdetect -y 1. I have followed the tutorial to the letter. Hardware is fine. Library would only install using pip which means I am without example code. This is where I need help. I need code to run the servo.

noob78
 
Posts: 5
Joined: Sat May 14, 2016 3:48 pm

Re: Raspberry PWM Servo hat python 3 library

by franklin97355 on Sat May 21, 2016 1:22 pm

did you get and run this code?
Code: Select all | TOGGLE FULL SIZE
git clone https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code.git
cd Adafruit-Raspberry-Pi-Python-Code
cd Adafruit_PWM_Servo_Driver

franklin97355
 
Posts: 21309
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: Raspberry PWM Servo hat python 3 library

by noob78 on Sat May 21, 2016 1:37 pm

As far as I can see this link is out of date where adafruit has moved it's libraries to a different location. So no, I cannot get this code as the link is out of date. On github it says that the location of the code has now moved.

noob78
 
Posts: 5
Joined: Sat May 14, 2016 3:48 pm

Re: Raspberry PWM Servo hat python 3 library

by noob78 on Sat May 21, 2016 1:40 pm

See screenshot.
Attachments
adafruit github.png
adafruit github.png (193.82 KiB) Viewed 1023 times

noob78
 
Posts: 5
Joined: Sat May 14, 2016 3:48 pm

Please be positive and constructive with your questions and comments.