I wish to build a project with Raspberry PI as I2C master to control 9 DC (18v with 2 channel encoders)
Is it possible to do it ?
Page 33 of the Motor Shield V2 learning system PDF has a schematic but am not able to view it clearly (cick to embiggen- not working !)
Is there any other place to check the schematic (already asked in http://forums.adafruit.com/viewtopic.php?f=31&t=42138 )
What are the other pins the Motor shield depends on (other the 5v, GND , SDA, SCL)
Alternatively, use the motor shield with arduino connect them to PI
PI acts as the master and arduino as the slave (would this work or will it have master-slave conflict)
PS: not exactly in topic- what would be the best way to get encoder value of the motors in this setup
Motor Shield V2 - with Raspberry PI
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_bill
- Posts: 88086
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor Shield V2 - with Raspberry PI
It can't be embiggened once it has been PDFed. You have to go to the original: http://learn.adafruit.com/adafruit-moto ... /resources(cick to embiggen- not working !)
Digital pins 9 and 10 are used for servo control only.What are the other pins the Motor shield depends on (other the 5v, GND , SDA, SCL)
This could be done. You would have to design some sort of control protocol.PI acts as the master and arduino as the slave (would this work or will it have master-slave conflict)
What kind of encoders are they? Absolute encoders can often be read directly. Quadrature encoders usually require interrupt-driven drivers.PS: not exactly in topic- what would be the best way to get encoder value of the motors in this setup
-
- Posts: 2
- Joined: Thu Nov 14, 2013 6:34 am
Re: Motor Shield V2 - with Raspberry PI
Thats brilliant ! Thank you
Seems to have good tutorials for PCA9685, should hopefully be straight forward to implement
They are 9 motors with 2 channels quadrature encoders any ideas about using 2 interrupt pins - Select the motor encoder to read or other solution ?
Seems to have good tutorials for PCA9685, should hopefully be straight forward to implement
They are 9 motors with 2 channels quadrature encoders any ideas about using 2 interrupt pins - Select the motor encoder to read or other solution ?
- adafruit_support_bill
- Posts: 88086
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor Shield V2 - with Raspberry PI
That is a lot of motors to monitor in software. It would require 18 pins with interrupt capability. The Arduino Mega 2560 has 18 pins that support pin-change interrupts (10, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69). But at high rotation rates, it is very likely you will miss some.9 motors with 2 channels quadrature encoders
-
- Posts: 5
- Joined: Sat Feb 08, 2014 3:51 am
Re: Motor Shield V2 - with Raspberry PI
Hi,
is it possible to connect Adafruit motor shield v2 to Raspberry with I2C?
Can you provide an example program code for python as you have it for Adafruit 16 Channel Servo Driver with Raspberry Pi?
is it possible to connect Adafruit motor shield v2 to Raspberry with I2C?
Can you provide an example program code for python as you have it for Adafruit 16 Channel Servo Driver with Raspberry Pi?
- adafruit_support_bill
- Posts: 88086
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor Shield V2 - with Raspberry PI
It is possible to connect it to a Raspberry Pi. There is a jumper to change the logic levels to 3.3v: http://forums.adafruit.com/viewtopic.ph ... 89#p227877
At this time, we do not have any example code for the Pi. However, the control chip on the motor shield is the same as the one on the 16 channel servo driver, so the low-level communication is the same.
At this time, we do not have any example code for the Pi. However, the control chip on the motor shield is the same as the one on the 16 channel servo driver, so the low-level communication is the same.
-
- Posts: 5
- Joined: Sat Feb 08, 2014 3:51 am
Re: Motor Shield V2 - with Raspberry PI
Thank you for help of logic level setup. I didn't mention about it.
I need to manage two of DC motors, but tutorial is written for PWM.
I am beginner for programming of any i2c devices and other too.
Could you write me a simple example, how to identify port of DC, start, stop, reverse DC motor?
I need to manage two of DC motors, but tutorial is written for PWM.
I am beginner for programming of any i2c devices and other too.
Could you write me a simple example, how to identify port of DC, start, stop, reverse DC motor?
Last edited by Zheck on Sun Feb 09, 2014 1:40 pm, edited 1 time in total.
-
- Posts: 5
- Joined: Sat Feb 08, 2014 3:51 am
Re: Motor Shield V2 - with Raspberry PI
Hi,
I have write the Python code for DC motor manage. But something is wrong, it is not working.
I'm not so strong in python, but I am tried to port this program:
https://github.com/adafruit/Adafruit_Mo ... Shield.cpp
Could you look on it, please. What is wrong here?
And this is not working with more than one DCM
Adafruit_DC_Motor_Driver.py
DC_Example.py
I have write the Python code for DC motor manage. But something is wrong, it is not working.
I'm not so strong in python, but I am tried to port this program:
https://github.com/adafruit/Adafruit_Mo ... Shield.cpp
Could you look on it, please. What is wrong here?
And this is not working with more than one DCM
Adafruit_DC_Motor_Driver.py
Code: Select all
#!/usr/bin/python
import time
import math
from Adafruit_I2C import Adafruit_I2C
# ============================================================================
# Adafruit PCA9685 16-Channel PWM Servo Driver
# ============================================================================
class DCM :
i2c = None
# Registers/etc.
__SUBADR1 = 0x02
__SUBADR2 = 0x03
__SUBADR3 = 0x04
__MODE1 = 0x00
__PRESCALE = 0xFE
__LED0_ON_L = 0x06
__LED0_ON_H = 0x07
__LED0_OFF_L = 0x08
__LED0_OFF_H = 0x09
__ALLLED_ON_L = 0xFA
__ALLLED_ON_H = 0xFB
__ALLLED_OFF_L = 0xFC
__ALLLED_OFF_H = 0xFD
# __PWMX = 8
# __AIN2X = 9
# __AIN1X = 10
def __init__(self, address=0x60, debug=False):
self.i2c = Adafruit_I2C(address,1)
self.address = address
self.debug = debug
self.i2c.debug = debug
if (self.debug):
print "Reseting PCA9685"
self.i2c.write8(self.__MODE1, 0x00)
def setDCMport(self, port):
"Select DC Shield port"
if port == 'M2':
self.__PWMX = 13
self.__AIN2X = 12
self.__AIN1X = 11
self.motor = 'M2'
elif port == 'M3':
self.__PWMX = 2
self.__AIN2X = 3
self.__AIN1X = 4
self.motor = 'M3'
elif port == 'M4':
self.__PWMX = 7
self.__AIN2X = 6
self.__AIN1X = 5
self.motor = 'M4'
else:
self.__PWMX = 8
self.__AIN2X = 9
self.__AIN1X = 10
self.motor = 'M1'
if (self.debug):
print "DC Shield port %s selected with next parameters:" % port
print "PWM = %d " % self.__PWMX
print "AIN1 = %d " % self.__AIN1X
print "AIN2 = %d " % self.__AIN2X
def setDCMFreq(self, freq):
"Sets the PWM frequency"
prescaleval = 25000000.0 # 25MHz
prescaleval /= 4096.0 # 12-bit
prescaleval /= float(freq)
prescaleval -= 1.0
if (self.debug):
print "Setting PWM frequency to %d Hz" % freq
print "Estimated pre-scale: %d" % prescaleval
prescale = math.floor(prescaleval + 0.5)
if (self.debug):
print "Final pre-scale: %d" % prescale
oldmode = self.i2c.readU8(self.__MODE1);
newmode = (oldmode & 0x7F) | 0x10 # sleep
self.i2c.write8(self.__MODE1, newmode) # go to sleep
self.i2c.write8(self.__PRESCALE, int(math.floor(prescale)))
self.i2c.write8(self.__MODE1, oldmode)
time.sleep(0.005)
self.i2c.write8(self.__MODE1, oldmode | 0x80)
def setDCM(self, channel, on, off):
"Sets a single PWM channel"
self.i2c.write8(self.__LED0_ON_L+4*channel, on & 0xFF)
self.i2c.write8(self.__LED0_ON_H+4*channel, on >> 8)
self.i2c.write8(self.__LED0_OFF_L+4*channel, off & 0xFF)
self.i2c.write8(self.__LED0_OFF_H+4*channel, off >> 8)
if (self.debug):
self.readDCM(channel)
def readDCM(self, channel):
print "LED%d_ON_L = %d" % (channel,self.i2c.readS8(self.__LED0_ON_L+4*channel))
print "LED%d_ON_H = %d" % (channel,self.i2c.readS8(self.__LED0_ON_H+4*channel))
print "LED%d_OFF_L = %d" % (channel,self.i2c.readS8(self.__LED0_OFF_L+4*channel))
print "LED%d_OFF_H = %d" % (channel,self.i2c.readS8(self.__LED0_OFF_H+4*channel))
print "---------"
def setDCMSpeed(self, speed):
"Sets a DC motor speed"
if (self.debug):
print "Setting %s speed to %d" % (self.motor,speed)
if speed > 254:
speed = 255
speed = speed*16
if (self.debug):
print "Converted speed to %d" % speed
self.setDCM(self.__PWMX, 0, speed)
def run(self, direction):
"Run DC with directions: FORWARD, BACKWARD, RELEASE"
if (self.debug):
print "Command send: ", direction
if direction == 'FORWARD':
self.setDCM(self.__AIN2X, 0, 0)
self.setDCM(self.__AIN1X, 4096, 0)
elif direction == 'BACKWARD':
self.setDCM(self.__AIN1X, 0, 0)
self.setDCM(self.__AIN2X, 4096, 0)
elif direction == 'RELEASE':
self.setDCM(self.__AIN2X, 0, 0)
self.setDCM(self.__AIN1X, 0, 0)
Code: Select all
#!/usr/bin/python
from Adafruit_DC_Motor_Driver import DCM
import time
# ===========================================================================
# Example Code
# ===========================================================================
# Initialise the DC motor object using the default address and set frequency
# dcm = DCM(0x60, debug=True)
# dcm.setDCMFreq(1000)
dcm = DCM(0x60, debug=True)
dcm.setDCMFreq(1600)
# Set DC Motor Shield port for each device
DCmotorA = dcm
DCmotorA.setDCMport('M1')
# DCmotorB = dcm
# DCmotorB.setDCMport('M2')
# Set DC Motor speed
DCmotorA.setDCMSpeed(150)
# DCmotorB.setDCMSpeed(200)
DCmotorA.run('FORWARD')
time.sleep(1)
DCmotorA.run('RELEASE')
-
- Posts: 5
- Joined: Sat Feb 08, 2014 3:51 am
Re: Motor Shield V2 - with Raspberry PI
OK, it works. I have confused with power supply.
But it works only with one DC motor. Selection of two or more motros not possible in this code.
But it works only with one DC motor. Selection of two or more motros not possible in this code.
-
- Posts: 5
- Joined: Sat Feb 08, 2014 3:51 am
Re: Motor Shield V2 - with Raspberry PI
Hi,
Can anybody help me to modify code for manage more than one DC motor?
Thank you in advance!
Can anybody help me to modify code for manage more than one DC motor?
Thank you in advance!
-
- Posts: 3
- Joined: Wed Apr 02, 2014 6:11 am
Re: Motor Shield V2 - with Raspberry PI
Works great¡¡¡
have you improve this code?. otherwise I'ĺl try.
Thank you.
have you improve this code?. otherwise I'ĺl try.
Thank you.
- KlixxOne
- Posts: 1
- Joined: Thu Aug 14, 2014 5:48 pm
Re: Motor Shield V2 - with Raspberry PI
I'm interrested in this aswell because i wanted to build a robot using this motor driver. What I need is just something to controll the speed aswell as the direction of my motors. A normal H-Bridge would do it, but unfortunenately the RasPi does not have multiple PWM Pins.
Is there any other solution?
Got any further with your code porting?
Will there be a official release of the motor shield for raspberry pi?
Best Regards,
Felix
Is there any other solution?
Got any further with your code porting?
Will there be a official release of the motor shield for raspberry pi?
Best Regards,
Felix
- adafruit_support_bill
- Posts: 88086
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor Shield V2 - with Raspberry PI
We do not have any plans at this time to release a Pi library for the motor shield.
Please be positive and constructive with your questions and comments.