Hi.
I have just got the Adafruit DC & Stepper Motor HAT to use in some robotics.
The book i'm using says that the python library to import into my program is Adafruit_MotorHAT which i find here https://github.com/adafruit/Adafruit-Mo ... ibrary.git, it adds that this library only works with Python 2.7. In a post here viewtopic.php?f=50&t=95654&p=480060&hil ... on#p480060 a user suggested that he had hacked it to Python 3 however very helpfully they don't give any indication of how!
However, the web pages for the HAT on your site suggest that the library that should be used is adafruit_motorkit, which is for Python 3.
I note that the class methods in the two libraries are very different.
I would prefer to work with python 3 if possible.
So two questions if i may.
1. Has Adafruit_MotorHAT been updated to python 3? Or would that break something else?
2. Which is the best python library to use with the HAT currently?
3. I've searched to see if i can see what the changes that need to be made to the Adafruit_MotorHAT libraries are but have failed dismally to find them. Does anyone have a pointer to the information?
Ta.
Nick P
Adafruit DC & Stepper Motor HAT - Python
Moderators: adafruit_support_bill, adafruit
Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
- adafruit_support_mike
- Posts: 67485
- Joined: Thu Feb 11, 2010 2:51 pm
Re: Adafruit DC & Stepper Motor HAT - Python
We're currently moving most of our driver code to CircuitPython, which works on microcontrollers and full-scale computers like the RasPi. The RasPi version uses Python3.
This tutorial page has instructions for installing the pieces you need:
https://learn.adafruit.com/adafruit-dc- ... g-software
This tutorial page has instructions for installing the pieces you need:
https://learn.adafruit.com/adafruit-dc- ... g-software
- Nick_P
- Posts: 3
- Joined: Sat Jan 19, 2019 1:09 pm
Re: Adafruit DC & Stepper Motor HAT - Python
Thanks Mike.
It looks like using the adafruit_Motorkit class is a little more straight forward than Adafruit_MotorHAT so i may well port the examples in the book over to that.
It looks from the documentation that the class adafruit_Motorkit is defined as class afdafruit_motorkit.Motorkit(address=96). The 96 has me stumped a little. I understand that to call different HATS that are stacked with the jumpers set appropriately i would
the default i2c address for kit1 being 0x60, and the second kit2, if the jumpers have been set correctly, will have an address of 0x61, but i'm not clear how that maps to the class definition for the default being (address=96). Where does the 9 come from? But i can't see that's going to stop me using this class!
A last question (i promise).
The all call address of 0x70. If i was to stack, say three hats, all with the addresses set differently by the jumpers, and then i did
Would all the motor1's on all the stacked boards all run forward at full speed at the same time? Not sure why i would want to do it more of a general interest question really.
Nick P.
It looks like using the adafruit_Motorkit class is a little more straight forward than Adafruit_MotorHAT so i may well port the examples in the book over to that.
It looks from the documentation that the class adafruit_Motorkit is defined as class afdafruit_motorkit.Motorkit(address=96). The 96 has me stumped a little. I understand that to call different HATS that are stacked with the jumpers set appropriately i would
Code: Select all
kit1=MotorKit()
kit2=Motorkit(address=0x61)
#rest of code follows
A last question (i promise).
The all call address of 0x70. If i was to stack, say three hats, all with the addresses set differently by the jumpers, and then i did
Code: Select all
kit_all=MotorKit(address=0x70)
kit_all.motor1.throttle=1.0
Nick P.
- adafruit_support_mike
- Posts: 67485
- Joined: Thu Feb 11, 2010 2:51 pm
Re: Adafruit DC & Stepper Motor HAT - Python
The Python library just writes the value in decimal. 0x60 == 96 base 10.Nick_P wrote:The 96 has me stumped a little.
In theory, yes.. all the boards should accept the same input at once.Nick_P wrote: The all call address of 0x70. If i was to stack, say three hats, all with the addresses set differently by the jumpers, and then i did
Would all the motor1's on all the stacked boards all run forward at full speed at the same time? Not sure why i would want to do it more of a general interest question really.Code: Select all
kit_all=MotorKit(address=0x70) kit_all.motor1.throttle=1.0
In practice, we haven't done much with the PCA9685's all-call or group addresses. On the bright side, it won't hurt anything to try it out!
Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/