Hallo,
ich habe momentan keine Funke, und versuche trotzdem die Schaltung zu testen.
Ich habe die "Mini" version der Platine, mit den I2C->PWM convertern von Willi. Als ESC habe ich die Hobbyking SS Series 18-20A ESC (card programmable) http://www.hobbyking.com/hobbyking/s...idProduct=6548
Ich habe also den I2C->PWM converter an die Platine, und an den ESC angeschlossen, und den ESC an den Motor. Nun versuche ich mit I2C comandos den Motor anzusteuern, klappt aber nicht.
Die Ansteuerung mache ich mit einem kleinen Program, das ich über die Serielle schnittstelle mit den Komandos versorge z.B. ML=80 (soll den Wert 80 zum linken Motor senden. Unden habe ich den Code angführt.
Hat jemand Erfahrung mit den ESC, und/oder ein Beispielprogram wie ich die motor ansteuerung testen kann. Ich habe leider kein Oszi, und kann mir darum die signale nicht anschauen.
Danke Gerald
Code:
/*
* main.cpp
*
* Created on: Oct 5, 2010
* Author: geraldf
*/
#include <WProgram.h>
#include <Wire.h>
#include "SoftI2CMaster.h"
//--I2C--
const byte M_h = 0x52; //i2c address: motor at the back
const byte M_l = 0x54; //i2c address: motor at the left
const byte M_r = 0x56; //i2c address: motor at the right
const byte sdaPin = 4;
const byte sclPin = 5;
// LED Pins
int BackLED = 7;
int RightLED = 8;
int LeftLED = 9;
int ParseCommand(char *);
void I2CSend( int, int);
int BlinkLED(int );
extern "C" void __cxa_pure_virtual() {
}
int ledPin = 13; // LED connected to digital pin 13
int i = 0;
char str[255];
int inp;
char str1[] = "Test1";
// The setup() method runs once, when the sketch starts
void setup() {
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
pinMode (BackLED, OUTPUT);
pinMode (LeftLED, OUTPUT);
pinMode (RightLED, OUTPUT);
Serial.begin(9600);
Wire.begin();
Serial.println("Hello Master, I am online and waiting for your commands!");
}
// the loop() method runs over and over again,
// as long as the Arduino has power
void loop() {
if (Serial.available() > 0 && i < 255) {
// read the incoming byte:
inp = Serial.read();
//digitalWrite(ledPin, HIGH); // set the LED on
//delay(500L); // wait for a second
//digitalWrite(ledPin, LOW); // set the LED off
//delay(500L); // wait for a second
// say what you got:
//Serial.print("I received: ");
//Serial.println(inp);
if (inp != 10) {
str[i++] = inp;
} else {
str[i] = '\0';
i = 0;
Serial.print("I received: ");
Serial.println(str);
if (ParseCommand(str) > 0) {
Serial.println("Invalid Command!");
}
}
}
}
int main(void) {
/* Must call init for arduino to work properly */
init();
setup();
for (;;) {
loop();
} // end for
} // end main
int ParseCommand(char* s) {
char cmd[255];
strcpy(cmd, s);
cmd[3] = '\0'; // command only (ML=, MR= or MH=)
if (strcmp(cmd, "ML=") == 0 || strcmp(cmd, "MR=") == 0
|| strcmp(cmd, "MH=") == 0) {
Serial.print("command ");
Serial.print(cmd);
Serial.println(" found!");
//parsing value now
int value = 0;
char v[5];
strcpy(v, s + 3);
Serial.print("value = ");
value = atoi(v);
Serial.println(value);
switch (cmd[1])
{
case 'H':
BlinkLED(1);
I2CSend(M_h,value);
break;
case 'L':
BlinkLED(2);
I2CSend(M_l,value);
break;
case 'R':
BlinkLED(4);
I2CSend(M_r,value);
break;
}
return (0);
}
else if (strcmp(s,"stop")== 0)
{
Serial.println("All Motors will stop!");
I2CSend(M_h,0);
I2CSend(M_l,0);
I2CSend(M_r,0);
BlinkLED(7);
return 0;
}
else
{
return (1);
}
return (0);
}
void I2CSend( int adr, int cmd)
{
// Wire.beginTransmission (adr);
// Wire.send(cmd);
// Wire.endTransmission();
SoftI2CMaster I2C = SoftI2CMaster( sdaPin,sclPin );
i2c.beginTransmission(adr);
i2c.send(cmd);
i2c.endTransmission();
}
int BlinkLED(int LED)
{
switch(LED)
{
case 1:
digitalWrite(BackLED, HIGH); // set the LED on
delay(100L);
break;
case 2:
digitalWrite(LeftLED, HIGH); // set the LED on
delay(100L);
break;
case 4:
digitalWrite(RightLED, HIGH); // set the LED on
delay(100L);
break;
case 3:
digitalWrite(BackLED, HIGH); // set the LED on
digitalWrite(LeftLED, HIGH); // set the LED on
delay(100L);
break;
case 7:
digitalWrite(BackLED, HIGH); // set the LED on
digitalWrite(LeftLED, HIGH); // set the LED on
digitalWrite(RightLED, HIGH); // set the LED on
delay(100L);
break;
}
digitalWrite(BackLED, LOW); // set the LED on
digitalWrite(LeftLED, LOW); // set the LED on
digitalWrite(RightLED, LOW); // set the LED on
return 0;
}
Lesezeichen