Digistump Forums
The Digispark => Digispark Pro Support => Topic started by: bsv116 on December 25, 2014, 02:57:52 am
-
The motor driver for my RobotKit does not work with the BasicRobot code. It turned out that the motor driver need separate PWM lines for forward and reverse and that GND is full speed and Vcc is stop. So the modified BasicRobot code works when as follows:
------------------------------------------------------------
See the proper code example in a later post further down
-
Thank you! I really thought I had done something wrong assembling the robot. It would only go forward and not reverse with the sample sketch. Your code works perfectly.
-
Hmm. I'd love to hear a DigiStump representative respond. Based on this post http://digistump.com/board/index.php/topic,1624.0.html only pins 0 and 1 are true pwm ports. The others respond like a digital port. Your code may really be emulating the same analogWrite/digitalWrite as the official code example with pins 2 and 5 effectively performing digitalWrites.
If this is correct then the real fix in your code is to get the polarity of the signals right. This wouldn't surprise me since the motor controller isn't the DigiSpark motor controller board but is a 3rd party board while the example is lifted from the DigiSpark motor controller shield example.
-
Thank you for the input. I have now found some specs for the motor driver. It can be managed with just 2 PWM lines so it is fine with the actual limitations of the DigiSpark Pro. Below is an even better version of the BasicRobot.
/Björn
---------------------------------------------
void setup() {
// put your setup code here, to run once:
botInit();
}
void loop() {
// put your main code here, to run repeatedly:
botForward(255); //speed can be any value from 0 (stopped) to 255 (full)
delay(5000);
botReverse(255);
delay(5000);
botRight(255);
delay(5000);
botHardRight(255);
delay(5000);
botLeft(255);
delay(5000);
botHardLeft(255);
delay(5000);
botStop();
delay(5000);
}
void botForward(int botSpeed){
digitalWrite(2, HIGH);
digitalWrite(5, HIGH);
analogWrite(0, 255 - botSpeed);
analogWrite(1, 255 - botSpeed);
}
void botReverse(int botSpeed){
digitalWrite(2, LOW);
digitalWrite(5, LOW);
analogWrite(0, botSpeed);
analogWrite(1, botSpeed);
}
void botRight(int botSpeed){
digitalWrite(2, LOW);
digitalWrite(5, HIGH);
analogWrite(0, 0);
analogWrite(1, 255 - botSpeed);
}
void botHardRight(int botSpeed){
digitalWrite(2, LOW);
digitalWrite(5, HIGH);
analogWrite(0, botSpeed);
analogWrite(1, 255 - botSpeed);
}
void botLeft(int botSpeed){
digitalWrite(2, HIGH);
digitalWrite(5, LOW);
analogWrite(0, 255 - botSpeed);
analogWrite(1, 0);
}
void botHardLeft(int botSpeed){
digitalWrite(2, HIGH);
digitalWrite(5, LOW);
analogWrite(0, 255 - botSpeed);
analogWrite(1, botSpeed);
}
void botStop(){
digitalWrite(2,LOW);
digitalWrite(5,LOW);
analogWrite(0,0);
analogWrite(1,0);
}
void botInit(){
pinMode(0,OUTPUT);
pinMode(1,OUTPUT);
pinMode(2,OUTPUT);
pinMode(5,OUTPUT);
}
-
Björn's code is correct - thanks and sorry for the mistake!