Author Topic: RobotKit motor driver  (Read 4128 times)

bsv116

  • Newbie
  • *
  • Posts: 2
RobotKit motor driver
« 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
« Last Edit: January 02, 2015, 03:06:29 pm by bsv116 »

JeffRand

  • Newbie
  • *
  • Posts: 44
Re: RobotKit motor driver
« Reply #1 on: December 28, 2014, 02:06:36 pm »
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.

tozz88

  • Newbie
  • *
  • Posts: 15
Re: RobotKit motor driver
« Reply #2 on: December 29, 2014, 02:02:10 am »
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.


bsv116

  • Newbie
  • *
  • Posts: 2
Re: RobotKit motor driver
« Reply #3 on: December 30, 2014, 01:54:40 pm »
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);
}


digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: RobotKit motor driver
« Reply #4 on: December 31, 2014, 10:32:32 pm »
Björn's code is correct - thanks and sorry for the mistake!