Circuit diagram

Construct the following temporary circuit to test out the motors. The enable pins are to be connected to 5V of the Intel Edison and Gnd to Gnd.

It's recommended to use motor driver modules instead of a standalone IC. This allows us to accomplish things in a much simpler way.

CP1 and CP2 are the control pins for the first motor, while CP3 and CP4 are the control pins for the second motor:

Circuit diagram for motor testing
When dealing with robotics, it is advised to keep sample code with which you can test that your motor driver is working or not. The code discussed here will explain how one can do so.

This part is especially important because it is necessary as the motor testing unit and also for calibration. This code also depends on your motor connection and it may require trial and error:

#define M11 2 
#define M12 3
#define M21 4
#define M22 5
void setup()
{
pinMode(M11,OUTPUT);
pinMode(M12,OUTPUT);
pinMode(M21,OUTPUT);
pinMode(M22,OUTPUT);
}
void loop()
{
forward();
delay(10000);
backward();
delay(10000);
left();
delay(10000);
right();
delay(10000);
stop();
delay(10000);
}
void forward()
{
digitalWrite(M11,HIGH);
digitalWrite(M12,LOW);
digitalWrite(M21,HIGH);
digitalWrite(M22,LOW);
}
void backward()
{
digitalWrite(M11,LOW);
digitalWrite(M12,HIGH);
digitalWrite(M21,LOW);
digitalWrite(M22,HIGH);
}
void right()
{
digitalWrite(M11,HIGH);
digitalWrite(M12,LOW);
digitalWrite(M21,LOW);
digitalWrite(M22,HIGH);
}
void left()
{
digitalWrite(M11,LOW);
digitalWrite(M12,HIGH);
digitalWrite(M21,HIGH);
digitalWrite(M22,LOW);
}
void stop()
{
digitalWrite(M11,LOW);
digitalWrite(M12,LOW);
digitalWrite(M21,LOW);
digitalWrite(M22,LOW);
}

The preceding code is very simple to understand. Here, we have broken it into several methods for forward, backward, left, right, and stop. These methods will be responsible for sending control signals to the motor driver using digitalWrite. Point to be noted is that this code may not work. It all depends on how your motor is connected. So, when you burn this code to your Intel Edison, make a note of which direction your motor is rotating for the initial 10 seconds. If both motors rotate in the same direction, well then you are lucky enough of not tampering with the connections. If, however, you observe rotation in opposite directions, then reverse the connection of one of the motors from its motor driver. This will allows the motor to rotate in the other direction, so both the motors will rotate in the same direction.

Another important point to be noted is that considering the methods left and right, we notice that motors rotate in different directions. That's how the steering system of a robot is implemented. It will be discussed in a later section of this chapter.

While dealing with motor drivers, please go through the specifications first. Then go for connections and coding.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.60.63