Arthur Sobel
Published © GPL3+

Tamiya Dual Motor Driver

PCB board for driving Tamiya Dual Motor Tractor Kit.

IntermediateWork in progress4 hours847
Tamiya Dual Motor Driver

Things used in this project

Hardware components

Tamiya 70100 Track and Wheel Set
×1
Tamiya 70098 universal plate set
×1
Tamiya 70097 twin-motor gearbox kit
×1
WEMOS D1 Mini ESP8266
×1
WEMOS D1 Mini Battery Shield
×1
Pololu DRV8835 Carrier
×1
VL6180 Module
×1
GL5506
×2
18650 Battery holder
×1
Capacitor 100 nF
Capacitor 100 nF
×2
Resistor 4.75k ohm
Resistor 4.75k ohm
×2
Resistor 220 ohm
Resistor 220 ohm
×1
.1 inch pin header strip
×1
Tamiya Driver board
×1

Story

Read more

Custom parts and enclosures

Loaded board mounted

Front View of loaded board

Schematics

Tamiya_drive.SHCDOC

Code

function_motor.ino

Arduino
This code uses the VL6180X as a light sensor so that the tractor will follow the light beam from a flash light. You must first install the ESP8266 and VL6180 libraries
/* This example demonstrates how to use interleaved mode to
take continuous range and ambient light measurements. The
datasheet recommends using interleaved mode instead of
running "range and ALS continuous modes simultaneously (i.e.
asynchronously)".

In order to attain a faster update rate (10 Hz), the max
convergence time for ranging and integration time for
ambient light measurement are reduced from the normally
recommended defaults. See section 2.4.4 ("Continuous mode
limits") and Table 6 ("Interleaved mode limits (10 Hz
operation)") in the VL6180X datasheet for more details.

Raw ambient light readings can be converted to units of lux
using the equation in datasheet section 2.13.4 ("ALS count
to lux conversion").

Example: A VL6180X gives an ambient light reading of 613
with the default gain of 1 and an integration period of
50 ms as configured in this sketch (reduced from 100 ms as
set by configureDefault()). With the factory calibrated
resolution of 0.32 lux/count, the light level is therefore
(0.32 * 613 * 100) / (1 * 50) or 392 lux.

The range readings are in units of mm. */

#include <Wire.h>
#include <VL6180X.h>
#include <ESP8266WiFi.h>
//#include <DRV8835MotorShield.h>

VL6180X sensor;
const int sclPin = D3;
const int sdaPin = D4;
const unsigned char M1DIR = D10;
const unsigned char M2DIR = D6;
const unsigned char M1PWM = D7;
const unsigned char M2PWM = D5;
int ambientvalue;
int distancevalue;
int speed;

int sensorValue;
//  DRV8835MotorShield motors;



void forward(int velocity){
  if (velocity> 1023 ) velocity= 1023;
  digitalWrite(M1DIR, HIGH);
  digitalWrite(M2DIR, HIGH);
  analogWrite(M1PWM, velocity);
  analogWrite(M2PWM, velocity);
  }
  
void backward(int velocity){
  if (velocity> 1023 ) velocity= 1023;
  digitalWrite(M1DIR, LOW);
  digitalWrite(M2DIR, LOW);
  analogWrite(M1PWM, velocity);
  analogWrite(M2PWM, velocity);
  }

void turnright(int velocity){
  if (velocity> 1023 ) velocity= 1023;
  digitalWrite(M1DIR, HIGH);
  digitalWrite(M2DIR, HIGH);
  analogWrite(M1PWM, velocity);
  analogWrite(M2PWM, 0);
  }
  
void turnleft(int velocity){
    if (velocity> 1023 ) velocity= 1023;
    digitalWrite(M1DIR, HIGH);
    digitalWrite(M2DIR, HIGH);
    analogWrite(M1PWM, 0);
    analogWrite(M2PWM, velocity);
    } 
  
void stopmotor(){

  digitalWrite(M1DIR, HIGH);
  digitalWrite(M2DIR, HIGH);
  analogWrite(M1PWM, 0);
  analogWrite(M2PWM, 0);
  } 

void setup()
{
  stopmotor();
  delay(5000);
  stopmotor();
  Serial.begin(9600);


  Wire.begin(sdaPin, sclPin);
    delay(100);
  sensor.init();
  sensor.configureDefault();

  // Reduce range max convergence time and ALS integration
  // time to 30 ms and 50 ms, respectively, to allow 10 Hz
  // operation (as suggested by Table 6 ("Interleaved mode
  // limits (10 Hz operation)") in the datasheet).
  sensor.writeReg(VL6180X::SYSRANGE__MAX_CONVERGENCE_TIME, 30);
  sensor.writeReg16Bit(VL6180X::SYSALS__INTEGRATION_PERIOD, 50);

  sensor.setTimeout(500);

   // stop continuous mode if already active
  sensor.stopContinuous();
  // in case stopContinuous() triggered a single-shot
  // measurement, wait for it to complete
  delay(300);
  // start interleaved continuous mode with period of 100 ms
  sensor.startInterleavedContinuous(100);
  
  stopmotor();

}

void loop(){
  Serial.print("Ambient: ");
  ambientvalue = sensor.readAmbientContinuous();
  sensorValue  = analogRead(A0); 

  Serial.print(ambientvalue);
  if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }

  Serial.print("\tRange: ");
  
  distancevalue = sensor.readRangeContinuousMillimeters();
  Serial.print(distancevalue);
  if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
   Serial.print("\tAnalog: ");
  Serial.print(sensorValue); 

   if (ambientvalue> 200) {

	    if (ambientvalue < 0 ) {speed=0;
	        }
      else {speed = ambientvalue - 100;
          }
  
	    if  (sensorValue > 800) {
		  turnleft(speed);
    		}

	    if  (sensorValue < 500) {
     		turnright(speed);
		    }

	    if  ((sensorValue >= 501) && (sensorValue <= 799))  {
		  forward(speed);		
		  }
  
     }
  if (ambientvalue< 100) {
        stopmotor();
        }
  Serial.print("\tspeed: ");
  Serial.print(speed);

  Serial.println();
}

Credits

Arthur Sobel

Arthur Sobel

4 projects • 4 followers
General electronics

Comments