ok , you are right , some additional data
the engine shield is:http://arduino.cc/en/Main/ArduinoMotorShieldR3
some pics :
the project looks like that:
https://drive.google.com/file/d/0BwE-Ba3ePCwOYWNLVVlwRDhLTGs/edit?usp=sharing
a robot platforn build from makeblock parts , with arduino mega, engine shield and Bluetooth model.
the engines gets its power from 8 batteries of 1.3V each and the arduino gets its power from single 9V battery
the batteries pack:
https://drive.google.com/file/d/0BwE-Ba3ePCwOeW5iRGotQmZIMkU/edit?usp=sharing
the motor shield input/output
https://drive.google.com/file/d/0BwE-Ba3ePCwOMHVRRzlyMmVvTVU/edit?usp=sharing
the black and red wires(input voltage from bateries) gave 10.4V ,while the white wires of each engine(the output from the shield) gave only 3.6V at max from each channel
MY CODE IS HERE: its just some communication initialization of Bluetooth model HC05 and commands to the engines to increase velocity for X seconds(X is a value from user by Bluetooth serial port).
#include <Wire.h>
//Types
struct CallibratedValue
{
int motor_speed_A ;
int motor_speed_B ;
}
CallibratedValue;
int default_motor_speed = 0;
//------------------------PINS----------------------------
//Pins
int pwm_pin_A = 3;
int dir_pin_A = 12;
int brake_pin_A = 9;
int pwm_pin_B = 11;
int dir_pin_B = 13;
int brake_pin_B = 8;
int ledpin = 51;
//-------------------------------------------------------------SETUP------------------------------------------
void setup()
{
//Motor Pins
pinMode(dir_pin_A,OUTPUT);
pinMode(brake_pin_A,OUTPUT);
pinMode(dir_pin_B,OUTPUT);
pinMode(brake_pin_B,OUTPUT);
//Communication Pins
pinMode(ledpin,OUTPUT);
//Buttons
digitalWrite(dir_pin_A,HIGH);
digitalWrite(brake_pin_A,LOW);
digitalWrite(dir_pin_B,LOW);
digitalWrite(brake_pin_B,LOW);
digitalWrite(ledpin,LOW);
Serial1.begin(115200);
Serial1.println("STARTING SETUP PHASE");
Wire.begin();
CallibratedValue.motor_speed_A = default_motor_speed;
CallibratedValue.motor_speed_B = default_motor_speed;
Serial1.println();
Serial1.print("Storage:motor_speed_A: ");
Serial1.println(CallibratedValue.motor_speed_A);
Serial1.print("Storage:motor_speed_B: ");
Serial1.println(CallibratedValue.motor_speed_B);
}
int BluetoothData; // the data given from Computer
//---------------------------------------------------------------------MAIN------------------------------------------
void loop()
{
//Bluietooth
BluetoothData = -1;
if (Serial1.available())
{
BluetoothData = Serial1.parseInt() ;
}
if (BluetoothData ==1)
{
Serial1.println("Insert Wanted Time Of Drive[sec]:");
while (!Serial1.available())
{
}
digitalWrite(ledpin,1); //led is on when driving
BluetoothData = Serial1.parseInt() ;
DriveForward(BluetoothData);
digitalWrite(ledpin,0);
}
}
void DriveForward(int NumOfSeconds)
{
unsigned long current_time,start_time,t,t_for_pereodic_printing,start_time_for_periodic_printing;
String s;
int dt;
int counter;
Serial1.println("Driving Forward...");
Serial1.print("Motor_speed_A ");
Serial1.print(CallibratedValue.motor_speed_A);
Serial1.print(", Motor_speed_B: ");
Serial1.println(CallibratedValue.motor_speed_B);
Serial1.println("Report:counter,dt,motor_speed_A,motor_speed_B");
start_time = millis();
t = millis()-start_time;
//for printing
t_for_pereodic_printing = 0;
start_time_for_periodic_printing = millis();
//end printing
dt = 0;
counter = 1;
while (t<NumOfSeconds*1000) //driving NumOfSeconds forward
{
current_time = millis();
s = "";
s += counter;
s += " " ;
s += micros();
s += " " ;
s += CallibratedValue.motor_speed_A;
s += " " ;
s += CallibratedValue.motor_speed_B;
s += " " ;
counter++;
dt = millis()-current_time;
t = millis()-start_time;
Serial1.println(s);
t_for_pereodic_printing = millis()-start_time_for_periodic_printing;
if (t_for_pereodic_printing>1000) //every 1 second , increasing motor power
{
CallibratedValue.motor_speed_A = CallibratedValue.motor_speed_A + 15; //incresing motor power
CallibratedValue.motor_speed_B = CallibratedValue.motor_speed_B + 15;
analogWrite(pwm_pin_A,(int)CallibratedValue.motor_speed_A); //writing to motor pwm
analogWrite(pwm_pin_B,(int)CallibratedValue.motor_speed_B);
start_time_for_periodic_printing = millis();
}
}
CallibratedValue.motor_speed_A = 0; //engines off
CallibratedValue.motor_speed_B = 0;
analogWrite(pwm_pin_A,CallibratedValue.motor_speed_A);
analogWrite(pwm_pin_B,CallibratedValue.motor_speed_B);
}