Show Posts
Pages: [1] 2 3
1  Using Arduino / Programming Questions / Re: TB6612FNG STBY problem on: February 01, 2011, 07:59:56 pm
It works great now with 2 separates batteries. One 180mAh 7,4V for Arduino and 280mAh 3,6V for motors.
Thx for your help Bill and Brad.
MadProf
2  Using Arduino / Programming Questions / Re: TB6612FNG STBY problem on: January 31, 2011, 05:38:20 pm
It's not a Lipo Battery but a nimh. The original was a 150mAh 3,6V.
I didn't use separates batteries cause I wanted a very small tank. 9V battery is nearly the same size...
Image
I will try with separates batteries.

MadProf
3  Using Arduino / Programming Questions / Re: TB6612FNG STBY problem on: January 31, 2011, 01:09:03 pm
I use only one battery (7,2V 180mAh) to power arduino board and motors.
4  Using Arduino / Programming Questions / Re: TB6612FNG STBY problem on: January 30, 2011, 05:44:51 pm
You were right Brad, with motors unplugged, it works great, RF link doesn't interrupt.
I've tested with motors plugged, when the RF doesn't receive anymore, if I unplugged motors the program resume.
Don't know if this problem can be solve, and how...

MadProf
5  Using Arduino / Programming Questions / Re: TB6612FNG STBY problem on: January 29, 2011, 07:12:03 pm
Hello Brad,
I use a cheap IR tank, +-15€ on ebay. It as 2 very little motors :
IR Tank
I will try to unplugged the motors as you suggest, I will post my feedback tomorrow.
Thx,
MadProf
6  Using Arduino / Programming Questions / TB6612FNG STBY problem on: January 26, 2011, 10:20:15 am
Hello, I've already started this topic in an inapropriate place (software/interfacing), so I retype it here.
I use a TB6612FNG driver motor and a cheap RF device to communicate.
I want to control my little tank.
I've tried to change the motor library, the RF link library (I first use virtualWire, It work great, then I use serialSoftware, it work great too).
If the STBY pin is high I can't receive any data, same issue with both library.
I've tried to link directly the stby pin on logic vcc, but still the same...

here is the code:

Code:
#include <VirtualWire.h>

//declaration des pins du controleur de moteurs

#define out_A_PWM 3
#define out_A_IN2 2
#define out_A_IN1 4
#define out_STBY 5
#define out_B_PWM 6
#define out_B_IN2 7
#define out_B_IN1 8

int ordrePrecedent = 0;
int ordre = 0;

void setup()
{
  //pins configuration
  pinMode(out_STBY,OUTPUT);
  pinMode(out_A_PWM,OUTPUT);
  pinMode(out_A_IN1,OUTPUT);
  pinMode(out_A_IN2,OUTPUT);
  pinMode(out_B_PWM,OUTPUT);
  pinMode(out_B_IN1,OUTPUT);
  pinMode(out_B_IN2,OUTPUT);
 
  vw_setup(2400); // Bits per sec
  vw_set_rx_pin(9);
  vw_rx_start(); // Start the receiver PLL running
  analogWrite (out_A_PWM, 80);//set motors speed
  analogWrite (out_B_PWM, 80);
  Serial.begin(9600);
  Serial.println("setup");
}

void loop()
{
   
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;
   
    // PB: while digitalWrite(out_STBY,HIGH), no reception possible.
    // out_STBY must be set to LOW in order to get new message, so I can't have a continuous move...
    if (vw_get_message(buf, &buflen)) // Non-blocking
    {
      int i;
      // Message with a good checksum received, dump HEX
      Serial.print("Got: ");
      for (i = 0; i < buflen; i++)
      {
        Serial.println(buf[i]);
        ordre = buf[i];
      }
     
      if(ordre!=ordrePrecedent){
        switch (ordre) {
          case 'A':
            avancer();
            break;
           
          case 'B':
            reculer();
            break;
           
          case 'C':
            tournerDroite();
            break;
           
          case 'D':
            tournerGauche();
            break;
           
          case 'E':
            //mode = 1;
            break;
           
          case 'F':
            //mode = 0;
            break;
           
          case 'S':
            stopper();
            break;
          }
          ordrePrecedent=ordre;
      }
  }
}


void avancer()
{
  digitalWrite(out_STBY,HIGH);
  digitalWrite(out_A_IN2, LOW);
  digitalWrite(out_A_IN1, HIGH);
  digitalWrite(out_B_IN2, LOW);
  digitalWrite(out_B_IN1, HIGH);
}

void reculer()
{
  digitalWrite(out_STBY,HIGH);
  digitalWrite(out_A_IN2, HIGH);
  digitalWrite(out_A_IN1, LOW);
  digitalWrite(out_B_IN2, HIGH);
  digitalWrite(out_B_IN1, LOW);
}

void stopper()
{
  digitalWrite(out_STBY,LOW);
}

void tournerGauche()
{
  digitalWrite(out_STBY,HIGH);
  digitalWrite(out_A_IN2, HIGH);
  digitalWrite(out_A_IN1, LOW);
  digitalWrite(out_B_IN2, LOW);
  digitalWrite(out_B_IN1, HIGH);
}

void tournerDroite()
{
  digitalWrite(out_STBY,HIGH);
  digitalWrite(out_A_IN2, LOW);
  digitalWrite(out_A_IN1, HIGH);
  digitalWrite(out_B_IN2, HIGH);
  digitalWrite(out_B_IN1, LOW);
}

I really don't know what to do, I've tried lot of things.
The only time it worked was when I replace "if (vw_get_message(buf, &buflen))" with "if(serial.read())" to receive order directly from my PC with the USB cable, but never with RF link...
There must have an issue cause I've seen some projects using this motor driver with the same RF device. Why motor standby set to HIGH stop RF link ?

Thx in advance and sry for my bad english,

MadProf

7  Forum 2005-2010 (read only) / Interfacing / Re: VirtualWire speed problem ? on: January 23, 2011, 08:02:36 pm
Hello,
I'm just retrying other things to solve my pb but I stille have the same issue.
I've tried to simplify the code in order to determine where the pb is.

Code:
#include <VirtualWire.h>

//declaration des pins du controleur de moteurs

#define out_A_PWM 3
#define out_A_IN2 2
#define out_A_IN1 4
#define out_STBY 5
#define out_B_PWM 6
#define out_B_IN2 7
#define out_B_IN1 8

int ordrePrecedent = 0;
int ordre = 0;

void setup()
{
  //pins configuration
  pinMode(out_STBY,OUTPUT);
  pinMode(out_A_PWM,OUTPUT);
  pinMode(out_A_IN1,OUTPUT);
  pinMode(out_A_IN2,OUTPUT);
  pinMode(out_B_PWM,OUTPUT);
  pinMode(out_B_IN1,OUTPUT);
  pinMode(out_B_IN2,OUTPUT);
  
  vw_setup(2400); // Bits per sec
  vw_set_rx_pin(9);
  vw_rx_start(); // Start the receiver PLL running
  analogWrite (out_A_PWM, 80);//set motors speed
  analogWrite (out_B_PWM, 80);
  Serial.begin(9600);
  Serial.println("setup");
}

void loop()
{
    
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;
    
    // PB: while digitalWrite(out_STBY,HIGH), no reception possible.
    // out_STBY must be set to LOW in order to get new message, so I can't have a continuous move...
    if (vw_get_message(buf, &buflen)) // Non-blocking
    {
      int i;
      // Message with a good checksum received, dump HEX
      Serial.print("Got: ");
      for (i = 0; i < buflen; i++)
      {
        Serial.println(buf[i]);
        ordre = buf[i];
      }
      
      if(ordre!=ordrePrecedent){
        switch (ordre) {
          case 'A':
            avancer();
            break;
            
          case 'B':
            reculer();
            break;
            
          case 'C':
            tournerDroite();
            break;
            
          case 'D':
            tournerGauche();
            break;
            
          case 'E':
            //mode = 1;
            break;
            
          case 'F':
            //mode = 0;
            break;
            
          case 'S':
            stopper();
            break;
          }
          ordrePrecedent=ordre;
      }
  }
}


void avancer()
{
  digitalWrite(out_STBY,HIGH);
  digitalWrite(out_A_IN2, LOW);
  digitalWrite(out_A_IN1, HIGH);
  digitalWrite(out_B_IN2, LOW);
  digitalWrite(out_B_IN1, HIGH);
}

void reculer()
{
  digitalWrite(out_STBY,HIGH);
  digitalWrite(out_A_IN2, HIGH);
  digitalWrite(out_A_IN1, LOW);
  digitalWrite(out_B_IN2, HIGH);
  digitalWrite(out_B_IN1, LOW);
}

void stopper()
{
  digitalWrite(out_STBY,LOW);
}

void tournerGauche()
{
  digitalWrite(out_STBY,HIGH);
  digitalWrite(out_A_IN2, HIGH);
  digitalWrite(out_A_IN1, LOW);
  digitalWrite(out_B_IN2, LOW);
  digitalWrite(out_B_IN1, HIGH);
}

void tournerDroite()
{
  digitalWrite(out_STBY,HIGH);
  digitalWrite(out_A_IN2, LOW);
  digitalWrite(out_A_IN1, HIGH);
  digitalWrite(out_B_IN2, HIGH);
  digitalWrite(out_B_IN1, LOW);
}


I know what the pb is but don't know how to fix it. While digitalWrite(out_STBY,HIGH), no reception possible.
out_STBY must be set to LOW in order to get new message, so I can't have a continuous move. Does someone use this motor driver with vitualWire ?
Why out_STBY=HIGH is a prb to receive datas ?

MadProf
8  Forum 2005-2010 (read only) / Interfacing / Re: VirtualWire speed problem ? on: September 07, 2010, 06:50:24 pm
I've tested with several println to know where the pb occurs.
The first order receive is read correctly and after that the program never enter the "if (vw_get_message(buf, &buflen))" condition. The main loop is still running.
9  Forum 2005-2010 (read only) / Interfacing / Re: VirtualWire speed problem ? on: September 07, 2010, 06:06:06 pm
Yes I've tried without shuting off the motor, but in this case the motors never stopped... and I can't receive anymore, as if the function motor_speed2 was blocking.
10  Forum 2005-2010 (read only) / Interfacing / Re: VirtualWire speed problem ? on: September 07, 2010, 05:20:50 pm
Thanx for your responses,

The 2 values 20 and 25 are motors's speed. My little tank is a cheap one so I must trim to go straight  :-[

I've tested first without the delay, but the motors never run...

I use a code by JoakimCh from this forum to control my motor driver TB6612FNG :
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1263858213

And the full code:

Code:
#include <VirtualWire.h>

//declaration des pins du controleur de moteurs
#define out_A_PWM 3
#define out_A_IN2 2
#define out_A_IN1 4
#define out_STBY 5
#define out_B_PWM 6
#define out_B_IN2 7
#define out_B_IN1 8
#define motor_A 0
#define motor_B 1
#define motor_AB 2

//IR Detection
int irPin = 11;   // capteur IR connecté sur pin 11
int val = 0;

int mode = 0; //0 = radio 1 = auto

void setup()
{  
  pinMode(irPin, INPUT);
  
  //configuration des pins du controleur de moteurs
  pinMode(out_STBY,OUTPUT);
  pinMode(out_A_PWM,OUTPUT);
  pinMode(out_A_IN1,OUTPUT);
  pinMode(out_A_IN2,OUTPUT);
  pinMode(out_B_PWM,OUTPUT);
  pinMode(out_B_IN1,OUTPUT);
  pinMode(out_B_IN2,OUTPUT);
  
  vw_setup(2000); // Bits per sec
  vw_set_rx_pin(9);
  vw_rx_start(); // Start the receiver PLL running
}


int lireCapteurDistance(){
  //detection IR digital (10cm)
  val = digitalRead(irPin);
  return val;
}

void loop()
{
  int ordre;

  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;
    
  if (vw_get_message(buf, &buflen)) // Non-blocking
  {
    int i;
    // Message with a good checksum received, dump HEX
    for (i = 0; i < buflen; i++)
    {
      ordre = buf[i];
    }

    if(mode == 1){
      if (ordre == 'F'){
        mode = 0;
      }else{
        mode_auto();
      }
    }else{  
      switch (ordre) {
          case 'A':
            avancer();
            motor_standby(true);
            break;
            
          case 'B':
            reculer();
            motor_standby(true);
            break;
            
          case 'C':
            tournerDroite();
            motor_standby(true);
            break;
            
          case 'D':
            tournerGauche();
            motor_standby(true);
            break;
            
          case 'E':
            mode = 1;
            break;
            
          case 'F':
            mode = 0;
            break;
            
          case 'S':
            stopper();
            break;
          }
        }
  }

}

void mode_auto(){
 //Serial.println(lireCapteurDistance());
 //TODO
}


void avancer()
{
  motor_standby(false);
  motor_speed2(motor_A,20);
  motor_speed2(motor_B,25);
}

void reculer()
{
  motor_standby(false);
  motor_speed2(motor_A,-20);
  motor_speed2(motor_B,-25);
}

void stopper()
{
  motor_brake(motor_A);
  motor_brake(motor_B);
}

void tournerGauche()
{
  motor_standby(false);
  motor_speed2(motor_A,20);
  motor_speed2(motor_B,-25);
}

void tournerDroite()
{
  motor_standby(false);
  motor_speed2(motor_A,-20);
  motor_speed2(motor_B,25);
}



void motor_speed2(boolean motor, char speed) { //speed from -100 to 100
  byte PWMvalue=0;
  PWMvalue = map(abs(speed),0,100,50,255); //anything below 50 is very weak
  if (speed > 0)
    motor_speed(motor,0,PWMvalue);
  else if (speed < 0)
    motor_speed(motor,1,PWMvalue);
  else {
    motor_coast(motor);
  }
}
void motor_speed(boolean motor, boolean direction, byte speed) { //speed from 0 to 255
  if (motor == motor_A) {
    if (direction == 0) {
      digitalWrite(out_A_IN1,HIGH);
      digitalWrite(out_A_IN2,LOW);
    } else {
      digitalWrite(out_A_IN1,LOW);
      digitalWrite(out_A_IN2,HIGH);
    }
    analogWrite(out_A_PWM,speed);
  } else {
    if (direction == 0) {
      digitalWrite(out_B_IN1,HIGH);
      digitalWrite(out_B_IN2,LOW);
    } else {
      digitalWrite(out_B_IN1,LOW);
      digitalWrite(out_B_IN2,HIGH);
    }
    analogWrite(out_B_PWM,speed);
  }
}

void motor_standby(boolean state) { //low power mode
  if (state == true)
    digitalWrite(out_STBY,LOW);
  else
    digitalWrite(out_STBY,HIGH);
}

void motor_brake(boolean motor) {
  if (motor == motor_A) {
    digitalWrite(out_A_IN1,HIGH);
    digitalWrite(out_A_IN2,HIGH);
  } else {
    digitalWrite(out_B_IN1,HIGH);
    digitalWrite(out_B_IN2,HIGH);
  }
}

void motor_coast(boolean motor) {
  if (motor == motor_A) {
    digitalWrite(out_A_IN1,LOW);
    digitalWrite(out_A_IN2,LOW);
    digitalWrite(out_A_PWM,HIGH);
  } else {
    digitalWrite(out_B_IN1,LOW);
    digitalWrite(out_B_IN2,LOW);
    digitalWrite(out_B_PWM,HIGH);
  }
}


MadProf
11  Forum 2005-2010 (read only) / Interfacing / VirtualWire speed problem ? on: September 07, 2010, 07:45:22 am
Hello,

I'm using virtualWire to control my micro rover.

It works well, but I can't have a continuous move:

I transmit data continuously, but my rover is stopping after each order.
I've tried to change wireless communication with serial transmitting and it work really well, so the problem might be on this line :
Code:
if (vw_get_message(buf, &buflen))
It seem to take time to execute, nearly blocking...
Anyone know how is it possible to make my rover moving like RC car ?

I use motorSpeed2 library.

My loop :
Code:
int ordre;

    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;
    if (vw_get_message(buf, &buflen)) // Non-blocking
    {
      int i;
      for (i = 0; i < buflen; i++)
      {
        Serial.println(buf[i]);
        ordre = buf[i];
      }
    
    if(mode == 1){
      if (ordre == 'F'){
        mode = 0;
      }else{
        mode_auto();
      }
    }else{  
      switch (ordre) {
          case 'A':
            avancer();
            motor_standby(true);
            break;
            
          case 'B':
            reculer();
            motor_standby(true);
            break;
            
          case 'C':
            tournerDroite();
            motor_standby(true);
            break;
            
          case 'D':
            tournerGauche();
            motor_standby(true);
            break;
            
          case 'E':
            mode = 1;
            break;
            
          case 'F':
            mode = 0;
            break;
            
          case 'S':
            stopper();
            break;
          }
        }
      }

and an example of function :

Code:
void avancer()
{
  motor_speed2(motor_A,20);
  motor_speed2(motor_B,25);
  delay(1000);
}

Thx in advance and sorry for my bad english.

MadProf

12  Forum 2005-2010 (read only) / Français / Re: Moteur qui tourne pas... on: September 02, 2010, 07:25:31 am
Hello,
Novice comme toi j'utilise celui là avec succès :
http://www.pololu.com/catalog/product/713

Peut tu préciser les caractéristiques de tes moteurs ? car un 6V de voiture RC fait penser à un modele de type "Speed":
Speed 400 6V, qui peut consommer jusqu'a 4A.
Speed 300 6V -> 5A
Speed 280 6V -> 1.58A

MadProf
13  Forum 2005-2010 (read only) / Français / Re: Batterie Arduino Nano on: September 01, 2010, 03:27:54 am
Petite avancée:
Pour test j'ai remplacé la communication wireless par une communication série via le câble usb. En envoyant mes ordres comme la télécommande ca fonctionne bien. Le problème viens donc de la réception des message (bloquante ?).
Si quelqu'un a déjà rencontré çà... J'utilise virtualWire

++

MadProf
14  Forum 2005-2010 (read only) / Français / Re: Batterie Arduino Nano on: August 30, 2010, 07:23:00 pm
Bonsoir,

Voilà le contenu de loop():

Code:
int ordre;

    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;
    if (vw_get_message(buf, &buflen)) // Non-blocking
    {
      int i;
      for (i = 0; i < buflen; i++)
      {
        Serial.println(buf[i]);
        ordre = buf[i];
      }
    
    if(mode == 1){
      if (ordre == 'F'){
        mode = 0;
      }else{
        mode_auto();
      }
    }else{  
      switch (ordre) {
          case 'A':
            avancer();
            break;
            
          case 'B':
            reculer();
            break;
            
          case 'C':
            tournerDroite();
            break;
            
          case 'D':
            tournerGauche();
            break;
            
          case 'E':
            mode = 1;
            break;
            
          case 'F':
            mode = 0;
            break;
            
          case 'S':
            stopper();
            break;
          }
        }
      }


 Et un exemple de fonction.
Avec le delay la réception est continue. Si je l'enlève, je reçois un premier ordre puis vw_get_message ne renvoi plus rien, du coup les moteurs ne reçoivent jamais l'ordre de s'arrêter

Code:
void avancer()
{
  motor_standby(false);
  motor_speed2(motor_A,20);
  motor_speed2(motor_B,25);
  delay(1000);
}

15  Forum 2005-2010 (read only) / Français / Re: Batterie Arduino Nano on: August 30, 2010, 06:57:08 am
Je vais voir ca ce soir, et modifier pour que les infos soient envoyées en permanence...
En tout cas merci pour les conseils, je savais pas trop dans quelle direction partir. Je vais donc adopter ta méthode.
Mais un y'a quand même un truc qui m'embête :
Comment est-ce que mon véhicule peut avancer si je ne met aucun délai ? dans ce cas il reçoit les infos en permanence, ex : avancer, avancer, reculer, droit gauche, mais sans délai il va avancer pdt quelques microsecondes, puis re-avancer quelques micro secondes, puis reculer...
Faudra que je mette mon code ce soir ce sera plus simple.

MadProf

PS: J'ai beau chercher je trouve pas de source qui corresponde, pourtant ca doit bien exister !
Pages: [1] 2 3