Hi, I am new to arduino and microcontrolling and I decided to buy the following parts to build a tank
-1x twin motor gear box - tamiya
-1x track and wheel set- tamiya
-1x universal plate set- tamiya
-1x Adruino Uno R3- Aruino
-1x set of jumper cables X60- spark fun
-1x TB6612FNG Dual 1 a motor controller- spark fun
-1x L3GD20 3-Axis Gyro- Adafruit
-1X LV- ManxSonar-EZ4 MB1040- Adafruit
-5x 9V battery clips- Radio Shack
-1x Mini Bread Board- Sparkfun
-1x Arduino Ethernet Shield R3- Amazon
(end parts list)
How do i properally control the tank over serial connection
I have the base code that was supplied by Spark fun so I decided if i could modify the base code to the point where i could simply just have the tank drive fwd for 5 seconds and turn around and come back.
all of the connections are perfect the tank operates but only goes forward.
it seems that the tank only is able to move forward and despite the fact that in the code i have instructed that after 5 second for the left motor to move forward and for the right one to move in reverse.
the point of the other censors is that this tank will be an automated system the range finder for the ability for it not to run into anything the gyro to if the tank is on an angle and it is moving at a angle too steep for the tank to remain in the upright position, it will right the wrong.
the Ethernet shield so that I can use the built in SD card slot as a data logger because the system will map out a 50ft x 50ft room and based on basic reading that the censors give it it will know its position in the room and be able to move freely
but in the mean time before the automation I would like to get the tank running on a serial connection from the computer or from an Ethernet cable that will tell it what direction to move in.
Also I have some Rechargeable batteries that I used to use on my RC Destroyer like this 7.2 volt AA mAh800 battery and i have various other 9.6 volt 2000 aMh batteries what configuration would i need for the proper powering of this tank i went through 3 9v's in 2 hours just off of testing last night so far i only have the motor controller hocked up the gyro is there but not connected and the Ethernet shield is not hooked up yet.
the code so far stands at such
[code]//motor A connected between A01 and A02
//motor B connected between B01 and B02
int STBY = 10; //standby
//Motor A
int PWMA = 3; //Speed control
int AIN1 = 9; //Direction
int AIN2 = 8; //Direction
//Motor B
int PWMB = 5; //Speed control
int BIN1 = 11; //Direction
int BIN2 = 12; //Direction
void setup(){
pinMode(STBY, OUTPUT);
pinMode(PWMA, OUTPUT);
pinMode(AIN1, OUTPUT);
pinMode(AIN2, OUTPUT);
pinMode(PWMB, OUTPUT);
pinMode(BIN1, OUTPUT);
pinMode(BIN2, OUTPUT);
}
void loop(){
move(1, 255, 0); //motor 1, full speed, left
move(2, 255, 0); //motor 2, full speed, left
delay(5000); //go for 1 second
stop(); //stop
delay(1000); //hold for 250ms until move again
move(1, 255, 1); //motor 1, half speed, right
move(2, 255, 0); //motor 2, half speed, right
delay(5000);
stop();
delay(1000);
}
void move(int motor, int speed, int direction){
//Move specific motor at speed and direction
//motor: 0 for B 1 for A
//speed: 0 is off, and 255 is full speed
//direction: 0 clockwise, 1 counter-clockwise
digitalWrite(STBY, HIGH); //disable standby
boolean inPin1 = LOW;
boolean inPin2 = HIGH;
if(direction == 1){
inPin1 = HIGH;
inPin2 = LOW;
}
if(direction == 0){
inPin1 = LOW;
inPin2 = HIGH;
}
if(motor == 1){
digitalWrite(AIN1, inPin1);
digitalWrite(AIN2, inPin2);
analogWrite(PWMA, speed);
}else{
digitalWrite(BIN1, inPin1);
digitalWrite(BIN2, inPin2);
analogWrite(PWMB, speed);
}
if(motor == 0){
digitalWrite(AIN1, inPin1);
digitalWrite(AIN2, inPin2);
analogWrite(PWMA, speed);
}else{
digitalWrite(BIN1, inPin1);
digitalWrite(BIN2, inPin2);
analogWrite(PWMB, speed);
}
}
void stop(){
//enable standby
digitalWrite(STBY, LOW);
}
that is for the motors ^^ for the gyroscope
#include <Wire.h>
#include <Adafruit_L3GD20.h>
#define USE_I2C
Adafruit_L3GD20 gyro;
void setup()
{
Serial.begin(9600);
if (!gyro.begin(gyro.L3DS20_RANGE_250DPS))
{
Serial.println("Oops ... unable to initialize the L3GD20. Check your wiring!");
while (1);
}
}
void loop()
{
gyro.read();
Serial.print("X: "); Serial.print((int)gyro.data.x); Serial.print(" ");
Serial.print("Y: "); Serial.print((int)gyro.data.y); Serial.print(" ");
Serial.print("Z: "); Serial.println((int)gyro.data.z); Serial.print(" ");
delay(100);
}
I realize that this is coded for serial I am yet to figure out how to translate it for just the Uno to read
Thank you Greatly For Your Time [/code]
How do i properally control the tank over serial connection