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:
#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