Quantcast
Channel: Arduino Forum - Latest topics
Viewing all articles
Browse latest Browse all 15971

LAFVIN 2WD Smart Robot Car Kit V2.2

$
0
0

In this topic I will be posting links, drawings and sketches to help you isolate problems particular to the Lafvin 2WD V2.2 kit which uses the TB6612FNG motor controller and the JDY-16 Bluetooth module - the other devices are common digital and analog sensors. I hope to cover all devices for a one-post help spot, so this helps get your robot working.

The OEM product download page where you need to find the 2WD V2.2 link:

This zip file contains the user manual and all the code.

You may find the manual neither logically arranged nor logical inside one subject, where code is inserted as images and the wrong parts are used... for example Lesson 2 was a sketch to all six (or more) devices interact, then Lesson 3 was a motors going in every direction... I like to learn to walk before I learn to run.

Starting with their incomplete system drawing. I added useful information with a few notes. D8 and D11 are unused, so I speculated on their possible use. D18 and D19 can be used for any I2C device or bus.

The LAFVIN 2WD V2.2 motor driver board is the TB6612FNG. Here is how these motors will be controlled:

//***************************************************************
// TB6612FNG PIN STATES                         MOTOR DIRECTIONS
//***************************************************************
//  LDIO  LPWM  RDIO  RPWM  RESULT              LEFT      RIGHT
//  HIGH  rate  LOW   rate  forward             forward   forward
//  LOW   rate  HIGH  rate  reverse             reverse   reverse
//  LOW   rate  LOW   rate  rotate left         reverse   forward
//  HIGH  rate  HIGH  rate  rotate right        forward   reverse
//  LOW   LOW   LOW   rate  skid forward left   stop      forward
//  HIGH  rate  LOW   LOW   skid forward right  forward   stop
//  LOW   LOW   LOW   rate  skid reverse left   reverse   stop
//  HIGH  rate  LOW   LOW   skid reverse right  stop      reverse
//  LOW   LOW   LOW   LOW   stop                stop      stop
//***************************************************************

The LAFVIN sketch tree did not have a good starting point (ventured into another programming language), so I added simple sketches to "Lessons" to help in learning along the way. Under each lesson I will post the most basic sketches to get to know and use the device. Their folders are arranged in "Lessons" with subfolders. Every sketch must be in a folder of the same name.

"Lesson 0" - Getting to know the Serial Monitor.

// LAFVIN 2WD Smart Robot Car Kit V2.2 https://lafvintech.com/pages/tutorials
// hello.ino
// The minimal required functions are: setup() and loop().  
// Note loop() is empty, allowing the code in setup() to run only once - a useful troubleshooting tool.

void setup() {
  Serial.begin(115200);
  Serial.print("Hello, World!");
}

void loop() {
}

Another way to print to the Serial Monitor, this time from a stored variable (an array of characters):

// LAFVIN 2WD Smart Robot Car Kit V2.2 https://lafvintech.com/pages/tutorials
// hello_world.ino
// Creates and prints an array of characters.
// Printing to the Serial Monitor helps find working and non-working code

char charArray[] = { ", World!" };

void setup() {
  Serial.begin(115200);
  Serial.print("Hello");    // print() is without carriage return
  Serial.println(charArray);  // println() is with a carriage return
}

void loop() {
}

"Lesson 1" - this folder is not included in the original file tree, but a logical step to add "blink" type sketches.

The LAFVIN 2WD V2.2 uses an Arduino Uno with an addressable LED on Pin 13 (D13) and a Multi-function Shield with a (not published) LED connected to Pin 3 (D3).

// LAFVIN 2WD Smart Robot Car Kit V2.2 https://lafvintech.com/pages/tutorials
// blink.ino
// D3 and D13 alternating on and off
// Remove BlueTooth Module before uploading

byte LED_IRREMOTE = 3;
// byte LED_BUILTIN = 13; // pre-defined

void setup() {
  pinMode(LED_IRREMOTE, OUTPUT);
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_IRREMOTE, LOW);  // D3 LOW = ON ***
  digitalWrite(LED_BUILTIN, LOW);   // D13 LOW = OFF
  delay(250);
  digitalWrite(LED_IRREMOTE, HIGH);  // D3 HIGH = OFF ***
  digitalWrite(LED_BUILTIN, HIGH);   // D13 LOW = ON
  delay(250);
}

This sketch only uses D3 to show how to use PWM to fade an LED

// LAFVIN 2WD Smart Robot Car Kit V2.2 https://lafvintech.com/pages/tutorials
// fade.ino
// Remove BlueTooth Module before uploading

byte LED_IRREMOTE = 3;  // D3 is a PWM pin used for the IR remote
byte step = 5;          // size of PWM change
byte wait = 20;         // time between PWM changes

void setup() {
  pinMode(LED_IRREMOTE, OUTPUT);  // configure DIO pin D3 for output
}

void loop() {
  for (int i = 0; i < 246; i += step) {  // fade D3 dimmer (D3 starts HIGH/ON/255)
    analogWrite(LED_IRREMOTE, i);        // write the PWM value to D3
    delay(wait);                         // pause for viewing effect
  }
  for (int i = 10; i < 256; i += step) {  // fade D3 brighter
    analogWrite(LED_IRREMOTE, 255 - i);
    delay(wait);
  }
}

"Lesson 2" - If there was a folder, it would be covering the graphic programming language included in the User Manual. It is a mess.

"Lesson 3" - Motors

Motors cause many kit-build problems due to insufficient power, inefficient motor drivers and confusion in wiring (motor and direction). LAFVIN 2WD V2.2 uses the TB6612FNG which seems to efficiently use power. The kit's battery holder is for two 18650, but does not have a BMS, so keep measuring the 18650s or install a 1P2S BMS. If you did not get 18650s or do not want to install a BMS, use 6 x AA batteries (6x1.5vdc=9vdc) to form the kit power supply.

The next eight sketches will each test one motor in one direction. The first four sketches will test wheel and direction. The second four sketches will test wheel and rate (PWM/speed).

All the sketches will be within setup() to allow for observation of one movement happening one time. This avoids scrambling for a way to turn the motors off - usually pulling the power supply and some wiring. This also helps verify the correct motor and polarity without the unneeded load of a second motor while using a too-weak power supply.

Left motor rotating "forward"

// LAFVIN 2WD Smart Robot Car Kit V2.2 https://lafvintech.com/pages/tutorials
// leftForward.ino - left wheel rotating "forward"

byte leftDIO = 2;
byte leftPWM = 5;

int rate = 50;       // PWM duty cycle (rate) 0 - 255
int duration = 500;  // duration of movement

void setup() {
  Serial.begin(115200);          // for debugging
  pinMode(LED_BUILTIN, OUTPUT);  // for "end of test" signal
  pinMode(leftDIO, OUTPUT);     // DIO for DIRECTION
  pinMode(leftPWM, OUTPUT);     // PWM for RATE

  for (int i = 0; i < 5; i++) {  // test the motor five times
    forward();
    stop();
  }

  for (int i = 0; i < 100; i++) {  // signal end of test
    digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
    delay(100);
  }
}

void loop() {
}

void forward() {
  digitalWrite(leftDIO, HIGH);  // direction
  analogWrite(leftPWM, rate);  // rate
  delay(duration);              // duration
  Serial.println("= BLUE LED =");
}

void stop() {
  digitalWrite(leftDIO, LOW);
  analogWrite(leftPWM, LOW);
  delay(duration * 2);
}

Left motor rotating "reverse"

// LAFVIN 2WD Smart Robot Car Kit V2.2 https://lafvintech.com/pages/tutorials
// leftReverse.ino - left motor rotating "reverse"

byte leftDIO = 2;
byte leftPWM = 5;

int rate = 50;       // PWM duty cycle (rate) 0 - 255
int duration = 500;  // duration of movement

void setup() {
  Serial.begin(115200);          // for debugging
  pinMode(LED_BUILTIN, OUTPUT);  // for "end of test" signal
  pinMode(leftDIO, OUTPUT);      // DIO for DIRECTION
  pinMode(leftPWM, OUTPUT);      // PWM for rate

  for (int i = 0; i < 5; i++) {  // test the motor
    reverse();
    stop();
  }

  for (int i = 0; i < 100; i++) {  // signal end of test
    digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
    delay(100);
  }
}

void loop() {
}

void reverse() {
  digitalWrite(leftDIO, LOW);  // direction
  analogWrite(leftPWM, rate);  // rate
  delay(duration);             // duration
  Serial.println("= GREEN LED =");
}

void stop() {
  digitalWrite(leftDIO, LOW);
  analogWrite(leftPWM, LOW);
  delay(duration * 2);
}

(more to come just taking a pause)

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 15971

Latest Images

Trending Articles



Latest Images