Hallo Community
ich habe mit einen Grove I2C Motor Driver V 1.3 zugelegt, da ich mit dem Rasp Pi Motoren ansteuern möchte (logisch). Nun gibt es jedoch Probleme bei der Verbindung oder Programmierung (ich weiss noch net was, deshalb hab ich den Thread erstmal hier gemacht).
Seite vom Hersteller (mit Software ganz unten): http://www.seeedstudio.com/wiki/Grove_-_I2C_Motor_Driver_V1.3
Die Software vom Hersteller:
/*
Grove- i2C motor driver demo v1.0
by: http://www.seeedstudio.com
// Author:LG
//
//
// This demo code is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//
*/
#include <Wire.h>
#define MotorSpeedSet 0x82
#define PWMFrequenceSet 0x84
#define DirectionSet 0xaa
#define MotorSetA 0xa1
#define MotorSetB 0xa5
#define Nothing 0x01
#define EnableStepper 0x1a
#define UnenableStepper 0x1b
#define Stepernu 0x1c
#define I2CMotorDriverAdd 0x0f // Set the address of the I2CMotorDriver
// set the steps you want, if 255, the stepper will rotate continuely;
void SteperStepset(unsigned char stepnu)
{
Wire.beginTransmission(I2CMotorDriverAdd); // transmit to device I2CMotorDriverAdd
Wire.write(Stepernu); // Send the stepernu command
Wire.write(stepnu); // send the steps
Wire.write(Nothing); // send nothing
Wire.endTransmission(); // stop transmitting
}
///////////////////////////////////////////////////////////////////////////////
// Enanble the i2c motor driver to drive a 4-wire stepper. the i2c motor driver will
//driver a 4-wire with 8 polarity .
//Direction: stepper direction ; 1/0
//motor speed: defines the time interval the i2C motor driver change it output to drive the stepper
//the actul interval time is : motorspeed * 4ms. that is , when motor speed is 10, the interval time
//would be 40 ms
//////////////////////////////////////////////////////////////////////////////////
void StepperMotorEnable(unsigned char Direction, unsigned char motorspeed)
{
Wire.beginTransmission(I2CMotorDriverAdd); // transmit to device I2CMotorDriverAdd
Wire.write(EnableStepper); // set pwm header
Wire.write(Direction); // send pwma
Wire.write(motorspeed); // send pwmb
Wire.endTransmission(); // stop transmitting
}
//function to uneanble i2C motor drive to drive the stepper.
void StepperMotorUnenable()
{
Wire.beginTransmission(I2CMotorDriverAdd); // transmit to device I2CMotorDriverAdd
Wire.write(UnenableStepper); // set unenable commmand
Wire.write(Nothing);
Wire.write(Nothing);
Wire.endTransmission(); // stop transmitting
}
//////////////////////////////////////////////////////////////////////
//Function to set the 2 DC motor speed
//motorSpeedA : the DC motor A speed; should be 0~100;
//motorSpeedB: the DC motor B speed; should be 0~100;
void MotorSpeedSetAB(unsigned char MotorSpeedA , unsigned char MotorSpeedB) {
MotorSpeedA=map(MotorSpeedA,0,100,0,255);
MotorSpeedB=map(MotorSpeedB,0,100,0,255);
Wire.beginTransmission(I2CMotorDriverAdd); // transmit to device I2CMotorDriverAdd
Wire.write(MotorSpeedSet); // set pwm header
Wire.write(MotorSpeedA); // send pwma
Wire.write(MotorSpeedB); // send pwmb
Wire.endTransmission(); // stop transmitting
}
//set the prescale frequency of PWM, 0x03 default;
void MotorPWMFrequenceSet(unsigned char Frequence) {
Wire.beginTransmission(I2CMotorDriverAdd); // transmit to device I2CMotorDriverAdd
Wire.write(PWMFrequenceSet); // set frequence header
Wire.write(Frequence); // send frequence
Wire.write(Nothing); // need to send this byte as the third byte(no meaning)
Wire.endTransmission(); // stop transmitting
}
//set the direction of DC motor.
void MotorDirectionSet(unsigned char Direction) { // Adjust the direction of the motors 0b0000 I4 I3 I2 I1
Wire.beginTransmission(I2CMotorDriverAdd); // transmit to device I2CMotorDriverAdd
Wire.write(DirectionSet); // Direction control header
Wire.write(Direction); // send direction control information
Wire.write(Nothing); // need to send this byte as the third byte(no meaning)
Wire.endTransmission(); // stop transmitting
}
void MotorDriectionAndSpeedSet(unsigned char Direction,unsigned char MotorSpeedA,unsigned char MotorSpeedB) { //you can adjust the driection and speed together
MotorDirectionSet(Direction);
MotorSpeedSetAB(MotorSpeedA,MotorSpeedB);
}
void setup() {
Wire.begin(); // join i2c bus (address optional for master)
delayMicroseconds(10000);
Serial.begin(9600);
Serial.println("setup begin");
}
void loop() {
// the following code sent commands to motor driver to drive DC motor
while(1) {
Serial.println("sent DC speed 100");
MotorSpeedSetAB(100,100);//defines the speed of motor 1 and motor 2;
delay(10); //this delay needed
MotorDirectionSet(0b1010); //"0b1010" defines the output polarity, "10" means the M+ is "positive" while the M- is "negtive"
// make sure M+ and M- is different polatity when driving DC motors.
delay(5000);
MotorDirectionSet(0b0101); //0b0101 Rotating in the opposite direction
delay(5000);
}
}
Alles anzeigen
Hier meine angepasste Software (wozu siehe ganz unten):
//Include arduPi library
#include "arduPi.h"
/*
Grove- i2C motor driver demo v1.0
by: http://www.seeedstudio.com
// Author:LG
//
//
// This demo code is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//
*/
#define MotorSpeedSet 0x82
#define PWMFrequenceSet 0x84
#define DirectionSet 0xaa
#define MotorSetA 0xa1
#define MotorSetB 0xa5
#define Nothing 0x01
#define EnableStepper 0x1a
#define UnenableStepper 0x1b
#define Stepernu 0x1c
#define I2CMotorDriverAdd 0x0f // Set the address of the I2CMotorDriver
// set the steps you want, if 255, the stepper will rotate continuely;
void SteperStepset(unsigned char stepnu)
{
Wire.beginTransmission(I2CMotorDriverAdd); // transmit to device I2CMotorDriverAdd
Wire.write(Stepernu); // Send the stepernu command
Wire.write(stepnu); // send the steps
Wire.write(Nothing); // send nothing
Wire.endTransmission(); // stop transmitting
}
//////////////////////////////////////////////////////////////////////
//Function to set the 2 DC motor speed
//motorSpeedA : the DC motor A speed; should be 0~100;
//motorSpeedB: the DC motor B speed; should be 0~100;
void MotorSpeedSetAB(unsigned char MotorSpeedA , unsigned char MotorSpeedB) {
MotorSpeedA=255; //map(MotorSpeedA,0,100,0,255)
MotorSpeedB=255; //map(MotorSpeedB,0,100,0,255)
Wire.beginTransmission(I2CMotorDriverAdd); // transmit to device I2CMotorDriverAdd
Wire.write(MotorSpeedSet); // set pwm header
Wire.write(MotorSpeedA); // send pwma
Wire.write(MotorSpeedB); // send pwmb
Wire.endTransmission(); // stop transmitting
}
//set the prescale frequency of PWM, 0x03 default;
void MotorPWMFrequenceSet(unsigned char Frequence) {
Wire.beginTransmission(I2CMotorDriverAdd); // transmit to device I2CMotorDriverAdd
Wire.write(PWMFrequenceSet); // set frequence header
Wire.write(Frequence); // send frequence
Wire.write(Nothing); // need to send this byte as the third byte(no meaning)
Wire.endTransmission(); // stop transmitting
}
void MotorDriectionAndSpeedSet(unsigned char Direction,unsigned char MotorSpeedA,unsigned char MotorSpeedB) { //you can ad$
MotorDirectionSet(Direction);
MotorSpeedSetAB(MotorSpeedA,MotorSpeedB);
}
void setup() {
Wire.begin(); // join i2c bus (address optional for master)
delayMicroseconds(10000);
Serial.begin(9600);
Serial.println("setup begin");
}
void loop() {
// the following code sent commands to motor driver to drive DC motor
while(1) {
Serial.println("sent DC speed 100");
MotorSpeedSetAB(255,255);//defines the speed of motor 1 and motor 2;
delay(10); //this delay needed
MotorDirectionSet(0b1010); //"0b1010" defines the output polarity, "10" means the M+ is "positive" while the M- is "negti$
// make sure M+ and M- is different polatity when driving DC motors.
delay(5000);
MotorDirectionSet(0b0101); //0b0101 Rotating in the opposite direction
delay(5000);
}
}
int main (){
setup();
while(1){
loop();
}
return (0);
}
Alles anzeigen
Hier habe ich statt der wire.h die arduPi.h library geladen, eine von der arduPi library nicht unterstützte Funktion (map()) rausgenommen und den Teil für den Steppermotor rausgenommen, da ich ihn net brauch. Das Ganze hab ich dann mit der arduPi.cpp kompiliert (g++ -lrt -lpthread DCControl.cpp arduPi.cpp -o DCControl).
Vorbereitung des Rasp Pi für I2C:
Meine Anleitung: http://www.gsurf.de/vorbereiten-des-raspberry-pi-auf-i2c/ bis zur Installation der i2c-tools
- habe das Modul (i2c-bcm2708) aus der Blacklist entfernt
- habe die Module (i2c-bcm2708 und i2c_dev) geladen und eingetragen damit sie beim Systemstart geladen werden
- habe Board so verbunden:
GND -> P1-6 (ist ja GND)
VCC -> P1-1 (ist ja 3,3V; oder muss hier P1-3 (5V) hin? Ich hatte Angst um die I2C-Pins)
SDA -> P1-3 (ist ja der SDA Pin)
SCL -> P1-5 (ist ja auch der SCL Pin)
Probleme:
- ich sehen das Board nur bei i2cdetect -y 1, wenn ich es vorher resettet habe (reset-button)
|-> Es könnte sein das dieser Fehler gar nicht schlimm ist aber:
- die Software vom Hersteller ist für Arduino und ich weiss net wie ich die auf dem rasp pi zum laufen kriege
- habe die Software mit der Library von diesem Projekt zum laufen gebracht (ohen die Hardware für die es gedacht ist): http://www.cooking-hacks.com/documentation/…nnection-bridge
Wenn ich das kompilierte Ergebnis starte, schmiert jedoch I2C am Rasp pi ganz ab und ich muss ihn Neustarten
Wie kriege ich die Software vom Arduino für den Rasp Pi kompiliert?
Bei Fragen zu meinem unübersichtlichen Bericht bitte fragen
MfG
paulrt5