Motor Shield on pcDuino

In this tutorial, we are going to show how to use motor shield to control motor on pcDuino. The interface covered on pcDuino is PWM interface.

The motor shield can be connected to pcDuino by protoshield with 6-pin and 8-pin jumper wires.

motorshield_1

 

We use a big DC power supply to supply power to the motor as shown above. This is for demo purpose only. In real application, batteries should be used. The motor is connected to the green terminal.

Now we work on the software side, launch  LXTerminal and enter into the working directory:

motorshield_2

 

Edit the source code:

motorshield_3

Compile and execute the code:

motorshield_4

The motor will rotate as we expected.

The source file is provided as below:

#include 

#define pinI1     8  //define IN1 interface
#define pinI2     11 //define IN2 interface 
#define speedpinA 3  //enable motor A
#define pinI3     12 //define IN3 interface 
#define pinI4     13 //define IN4 interface 
#define speedpinB 4 //enable motor B
#define spead     200 //define the spead of motor

void forward()
{
     analogWrite(speedpinA,spead);//input a simulation value to set the speed
     analogWrite(speedpinB,spead);
     digitalWrite(pinI4,HIGH);//turn DC Motor B move clockwise
     digitalWrite(pinI3,LOW);
     digitalWrite(pinI2,LOW);//turn DC Motor A move anticlockwise
     digitalWrite(pinI1,HIGH);
}
void backward()
{
     analogWrite(speedpinA,spead);//input a simulation value to set the speed
     analogWrite(speedpinB,spead);
     digitalWrite(pinI4,LOW);//turn DC Motor B move anticlockwise
     digitalWrite(pinI3,HIGH);
     digitalWrite(pinI2,HIGH);//turn DC Motor A move clockwise
     digitalWrite(pinI1,LOW);
}
void left()
{
     analogWrite(speedpinA,spead);//input a simulation value to set the speed
     analogWrite(speedpinB,spead);
     digitalWrite(pinI4,HIGH);//turn DC Motor B move clockwise
     digitalWrite(pinI3,LOW);
     digitalWrite(pinI2,HIGH);//turn DC Motor A move clockwise
     digitalWrite(pinI1,LOW);
}
void right()
{
     analogWrite(speedpinA,spead);//input a simulation value to set the speed
     analogWrite(speedpinB,spead);
     digitalWrite(pinI4,LOW);//turn DC Motor B move anticlockwise
     digitalWrite(pinI3,HIGH);
     digitalWrite(pinI2,LOW);//turn DC Motor A move clockwise
     digitalWrite(pinI1,HIGH);
}
void stop()
{
     digitalWrite(speedpinA,LOW);// Unenble the pin, to stop the motor. this          should be done to avid damaging the motor. 
     digitalWrite(speedpinB,LOW);
     delay(2000);
}

void setup()
{
  pinMode(pinI1,OUTPUT);
  pinMode(pinI2,OUTPUT);
  pinMode(speedpinA,OUTPUT);
  pinMode(pinI3,OUTPUT);
  pinMode(pinI4,OUTPUT);
  pinMode(speedpinB,OUTPUT);
}

void loop()
{
  left();
  delay(2000);
  stop();
  right();
  delay(2000);
  stop();
  forward();
  delay(2000);
  stop();
  backward();
  delay(2000); 
  stop(); 
}

 

 

 

 

 

Posted in Arduino-ish Progamming, Tutorials
Loading Facebook Comments ...
2 comments on “Motor Shield on pcDuino
  1. Charles says:

    These tutorials are nice but maybe you should do one on how to compile arduino code and libraries.

Leave a Reply