Problem in Serial communication between 2 arduinos ! [SOLVED]

hey guys,
I am having a problem when connecting the 2 arduinos serially, the serial communication is not being made, i debugged the problem to see if it's a problem from the push buttons or else but it's not , the push buttons are working fine, and i tried to send values from the serial monitor to second arduino and it worked fine
so what i suspected is that i have a TX pin (pin 10) defined for TX of the RF transmitter so might that be a problem for the TX pin 1 of arduino ? if not what might be the problem then ?

these are the codes of the arduino 1 which contains the transmitter and buttons :

//Transmitter
#include <VirtualWire.h>

char Array[10];
int potPin1 = A0;    // Throttle
int potPin2 = A1;    // Brakes
int potPin3 = A2;    //Streering 

//these values will be sent by the transmitter
int valThrottle = 0;  
int valBrakes = 0;
int valSteering = 0;

int transmitterPin = 10; //transmitter pin

int downShift = 2; //Left paddle shift pin 2
int upShift = 3; //Right paddle shift pin 3
int burnout = 5; //Burnout Button pin 5
int neutral = 6; //Neutral Green Button pin 6
int reverse = 7; //Reverse Button pin 7
int limiter = 8; //Pit Limiter Button pin 8
//int cam = 9; //Cam grey Button pin 9
//pin 4 is the white button

//downShift
boolean lastDownshift= LOW; 
boolean currentDownshift = LOW; 

//upShift
boolean lastUpshift = LOW; 
boolean currentUpshift = LOW; 

//burnout
boolean lastBurnout = LOW; 
boolean currentBurnout = LOW;
boolean burnoutState = HIGH;

//neutral
boolean lastNeutral = LOW; 
boolean currentNeutral = LOW; 
boolean neutralState = HIGH;

//reverse
boolean lastReverse = LOW; 
boolean currentReverse = LOW; 
boolean reverseState = HIGH;

//limiter
boolean lastLimiter = LOW; 
boolean currentLimiter = LOW; 
boolean limiterState = HIGH;

//cam
boolean lastCam = LOW; 
boolean currentCam = LOW; 
boolean camState = HIGH;

void setup()
{
  Serial.begin(9600);	  // Debugging only
  Serial.println("Sending"); // Debugging only

  // Initialise the IO and ISR
  //vw_set_ptt_inverted(true); // Required for DR3100
  vw_setup(2000);	 // Bits per sec
  vw_set_tx_pin(transmitterPin); //RF sending pin Arduino Mega
  
  for(int i = 2; i<10; i++){
    pinMode(i, INPUT);
  }
  
}

//debounce function
boolean debounce(boolean last, int button)
{
  boolean current = digitalRead(button);
  if(last != current)
  {
    delay(5);
    current = digitalRead(button);
  }
  return current;
}



void loop(){
  //for the downShift
  currentDownshift = debounce(lastDownshift, downShift);
  if(lastDownshift == LOW && currentDownshift == HIGH)
  {
    Serial.write('-');
  }
  lastDownshift = currentDownshift;
  
  
  //for the upShift
  currentUpshift = debounce(lastUpshift, upShift);
  if(lastUpshift == LOW && currentUpshift == HIGH)
  {
    Serial.write('+');
  }
  lastUpshift = currentUpshift;
  
  
  //for the burnout
  currentBurnout = debounce(lastBurnout, burnout);
  if(lastBurnout == HIGH && currentBurnout == LOW)
  { 
    Serial.write('b');
    neutralState = !neutralState;
    Serial.println(neutralState);
    delay(1000);
  }  
  
  lastBurnout = currentBurnout;
  
  
  //for the neutral
  currentNeutral = debounce(lastNeutral, neutral);
  if(lastNeutral == HIGH && currentNeutral == LOW)
  {
    Serial.write('n');
    neutralState = !neutralState;
    Serial.println(neutralState);
    delay(1000);
    
  }
  lastNeutral = currentNeutral;
  
  
  //for the reverse
  currentReverse = debounce(lastReverse, reverse);
  if(lastReverse == HIGH && currentReverse == LOW)
  {
    Serial.write('r');
    reverseState = !reverseState;
    Serial.println(reverseState);
    delay(1000);
  }
  lastReverse = currentReverse;
  
  
  //for the limiter
  currentLimiter = debounce(lastLimiter, limiter);
  if(lastLimiter == HIGH && currentLimiter == LOW)
  {
    Serial.write('l');
    limiterState = !limiterState;
    Serial.println(limiterState);
    delay(1000);
    
  }
  lastLimiter = currentLimiter;
  
  
  //for the cam
  /*currentCam = debounce(lastCam, cam);
  if(lastCam == HIGH && currentCam == LOW)
  {
     Serial.write('c');
     camState = !camState;
    Serial.println(camState);
    delay(1000);
  }
  lastCam = currentCam;*/
  
  //transmitter codes
  valThrottle = analogRead(potPin1);  // read the value from the sensor
  if(neutralState == LOW){
    
    valThrottle = map(valThrottle, 0, 55, 0, 0); 
    valThrottle = constrain(valThrottle, 0, 0);
    
  }else if(limiterState == LOW){
    
    valThrottle = map(valThrottle, 0, 55, 0, 150); 
    valThrottle = constrain(valThrottle, 0, 150);
    
  }else if(burnoutState == LOW){
    
    valThrottle = map(valThrottle, 0, 10, 0, 255); 
    valThrottle = constrain(valThrottle, 0, 255);
    
  }else{
    valThrottle = map(valThrottle, 0, 55, 0, 255); 
    valThrottle = constrain(valThrottle, 0, 255);
  }
  
  
  valBrakes = analogRead(potPin2);  // read the value from the sensor
  if(reverseState == LOW){
    
    valBrakes = map(valBrakes, 1023, 954, 0, 255); 
    valBrakes = constrain(valBrakes, 0, 255);
    
  }else if(reverseState == HIGH){
    
    valBrakes = map(valBrakes, 1023, 954, 0, 10); 
    valBrakes = constrain(valBrakes, 0, 10);
    
  }
  
  valSteering = analogRead(potPin3); // 0 to 1023
  valSteering = map(valSteering, 0, 1023, 255, 0);
  Serial.println(valSteering);
  
  sprintf(Array, "%d,%d,%d.", valBrakes,valThrottle,valSteering);
  vw_send((uint8_t*)Array, strlen(Array));
  vw_wait_tx(); 
  Serial.println(Array);
    
}

these are the codes of the second arduino that contains the displays and leds:

//For the 2 digits displays////////////////////////////////////////////////////////////////////
byte datapin = 2;
byte clockpin = 3;
byte latchpin = 4;

byte datapin2 = 7;
byte clockpin2 = 8;
byte latchpin2 = 9;

byte First = 5;
byte Second = 6;
byte Third = 10;
byte Fourth = 11;

int times;
byte segments[14] = {0b11111111,  //Blank - 0
                     0b00101011, //n - 1
                     0b10000110, //E - 2
                     0b00000111, //t - 3
                     0b10101111, //r - 4
                     0b11001111, //l - 5
                     0b10000011, //b - 6
                     0b11000000, //O - 7
                     0b11100011, //u - 8
                     0b11010101, //v - 9
                     0b11000111, //L - 10
                     0b11001111, //i - 11
                     0b11101010,  //M - 12
                     0b10001001
                     
                   };
                     

byte FirstDigit;
byte SecondDigit;
byte ThirdDigit;
byte FourthDigit;

byte FirstD;
byte SecondD;
byte ThirdD;
byte FourthD;

//these pins for the gear number display///////////////////////////////////////////////////////
byte latchPin0 = 15; //latch pin
byte clockPin0 = 16; //clock pin
byte dataPin0 = 14; //data pin

byte gearDisplay = 0;

int gearBox = 0;

byte segments1Digit[7] = {0b00000011, //0 - position 1
                          0b10011111, //1 - position 2
                          0b00100101, //2 - position 3
                          0b00001101, //3 - position 4
                          0b10011001, //4 - position 5
                          0b01001001, //5 - position 6
                          0b01000001, //6 - position 7
                         };
                   
boolean burnoutOn = HIGH;
boolean neutralOn = HIGH;
boolean reverseOn = HIGH;
boolean limiterOn = HIGH;
boolean camOn = HIGH;

void setup()
{
  Serial.begin(9600);
  
  for(int x = 2; x < 20; x++){
    pinMode(x, OUTPUT);
  }
  
  digitalWrite(Second,HIGH);
  digitalWrite(First,HIGH);
  digitalWrite(datapin,LOW);
  digitalWrite(latchpin,LOW);
  digitalWrite(clockpin,LOW);
  
  digitalWrite(Fourth,HIGH);
  digitalWrite(Third,HIGH);
  digitalWrite(datapin2,LOW);
  digitalWrite(latchpin2,LOW);
  digitalWrite(clockpin2,LOW);
}

void loop()
{  
  //Puting Limits for the gear box up and down
  if(gearBox > 6){
     gearBox = 6;
  }else if(gearBox < 0){
     gearBox = 0;
  }  
  
  //Read from Serial port
  if(Serial.available() > 0){
    int value = Serial.read();
    if(value == '+'){
     
      gearBox++;
    
    }
    if(value == '-'){
      
      gearBox--;
    
    }
    if(value == 'b'){
      
      burnoutOn = !burnoutOn;
      Serial.write('w'); //this to turn the red LED on from arduino 3
      
    }
    if(value == 'n'){
      
      neutralOn = !neutralOn;
      Serial.write('e'); //this to turn the green LED on from arduino 3
      
    }
    if(value == 'r'){
      
      reverseOn = !reverseOn;
      Serial.write('y'); //this to turn the yellow LED on from arduino 3
      
    }
    if(value == 'l'){
      
      limiterOn = !limiterOn;
      Serial.write('u'); //this to turn the blue LED on from arduino 3
      
    }
    if(value == 'c'){
      
      camOn = !camOn;
      
    }
  
    
    if(!burnoutOn && !neutralOn && !reverseOn && !limiterOn && !camOn){
      
      FirstD = 144; //this will give me 0, this is second digit
      SecondD = 156; //this will give me 1, this is actully the first digit
      ThirdD = 0; //this is the fourth digit
      FourthD = 0;
      
    }
    ///burnout display word
    if(burnoutOn){
      neutralOn = false;
      reverseOn = false;
      limiterOn = false;
      camOn = false;
      
      FirstD = 84; //this will give me 0, this is second digit
      SecondD = 72; //this will give me 1, this is actully the first digit
      ThirdD = 36; //this is the fourth digit
      FourthD = 96; // this is third digit
      
      
      
    }
    ///neutral display word
    if(neutralOn){
      burnoutOn = false;
      reverseOn = false;
      limiterOn = false;
      camOn = false;
      
      FirstD = 24; //this will give me 0, this is second digit
      SecondD = 12; //this will give me 1, this is actully the first digit
      ThirdD = 48; //this is the fourth digit
      FourthD = 36; // this is third digit
      
      
      
    }
    ///reverse display word
    if(reverseOn){
      burnoutOn = false;
      neutralOn = false;
      limiterOn = false;
      camOn = false;
      
      FirstD = 24; //this will give me 0, this is second digit
      SecondD = 48; //this will give me 1, this is actully the first digit
      ThirdD = 0; //this is the fourth digit
      FourthD = 108; // this is third digit
      
      
      
    }
    
    ///limiter display word
    if(limiterOn){
      burnoutOn = false;
      neutralOn = false;
      reverseOn = false;
      camOn = false;
      
      FirstD = 132; //this will give me 0, this is second digit
      SecondD = 120; //this will give me 1, this is actully the first digit
      ThirdD = 36; //this is the fourth digit
      FourthD = 144; // this is third digit
      
      
    }
    
    
    ///cam display word
    /*if(camOn){
      
     
    }*/
    
  }  
    
    
  gearDisplay = gearBox;
  updateShiftRegister();
  digitparse();
  lookItUp();
  


}

void updateShiftRegister()
{
  
  shiftOut(dataPin0, clockPin0, LSBFIRST, segments1Digit[gearDisplay]);
  digitalWrite(latchPin0, LOW);  
  digitalWrite(latchPin0, HIGH);
  
}

void latchit ()
{
  digitalWrite(latchpin,HIGH);
  digitalWrite(latchpin,LOW);
  digitalWrite(latchpin2,HIGH);
  digitalWrite(latchpin2,LOW);
}

void digitparse ()
{
  //from left to right
  FirstDigit = FirstD / 12;
  SecondDigit = SecondD / 12;
  ThirdDigit = ThirdD / 12;  
  FourthDigit = FourthD / 12;   
}


void lookItUp ()
{
  shiftOut(datapin,clockpin,MSBFIRST,segments[FirstDigit]);
  shiftOut(datapin,clockpin,MSBFIRST,segments[SecondDigit]);
  shiftOut(datapin2,clockpin2,MSBFIRST,segments[ThirdDigit]);
  shiftOut(datapin2,clockpin2,MSBFIRST,segments[FourthDigit]);
  latchit();
  dispOn();    
}

void dispOn ()
{
  for(times=0; times < 5; times++) // display interval
  {
    digitalWrite(Second,LOW);
    delay(5);
    digitalWrite(Second,HIGH);
    digitalWrite(First,LOW);
    delay(5);
    digitalWrite(First,HIGH);
    
    digitalWrite(Third,LOW);
    delay(5);
    digitalWrite(Third,HIGH);
    digitalWrite(Fourth,LOW);
    delay(5);
    digitalWrite(Fourth,HIGH);
  }
}

The transmitter should have nothing to do with it. Have you connected the two Arduinos together correctly?

   Arduino 1 -------------Arduino 2
     Tx --------------------- Rx
     Rx --------------------- Tx

On the other hand, if you are trying to send data over the RF link, you'll need to use VirtualWire on the receiver as well.

And where, in all this, is Arduino 3? It seems you are sending stuff over Serial to it from Arduino 2. If so, how many Arduinos share Serial Tx pins, and how many share Serial Rx pins? 3 is the wrong answer for either question.

exactly this is how i connect them, i tried it before and was working totally fine,

Arduino 1 (TX) --------------  Arduino 2 (RX) 
Arduino 2 (TX) --------------Arduino 3 (RX)

firashelou:
exactly this is how i connect them, i tried it before and was working totally fine,

Arduino 1 (TX) --------------  Arduino 2 (RX) 

Arduino 2 (TX) --------------Arduino 3 (RX)

Maybe you ought to expand on that, because it seems that you have the same serial connection going to multiple places.

Can you explain exactly what Arduinos you have got and what connections there are between them in terms of pin numbers?

Also note that the string you're sending over the virtual wire interface may be longer than the array you're storing it in since each value may be up to three decimal digits plus a comma, giving twelve characters of content plus the null terminator. I recommend you resize the array and use snprint() rather than sprintf() to avoid array overflow in future.

PeterH:

firashelou:
exactly this is how i connect them, i tried it before and was working totally fine,

Arduino 1 (TX) --------------  Arduino 2 (RX) 

Arduino 2 (TX) --------------Arduino 3 (RX)

Maybe you ought to expand on that, because it seems that you have the same serial connection going to multiple places.

Can you explain exactly what Arduinos you have got and what connections there are between them in terms of pin numbers?

Also note that the string you're sending over the virtual wire interface may be longer than the array you're storing it in since each value may be up to three decimal digits plus a comma, giving twelve characters of content plus the null terminator. I recommend you resize the array and use snprint() rather than sprintf() to avoid array overflow in future.

well about serial connection between arduinos :
arduino 1 (pin 1) --------------- arduino 2 (pin 0)
arduino 2 (pin 1) --------------- arduino 3 (pin 0)

i am not sending the value in serial between arduino in any array, if that what you mean if not can you please explain what you really mean ? because i am using the array for the virtual wire to send data via RF transmitter

firashelou:
i am not sending the value in serial between arduino in any array, if that what you mean if not can you please explain what you really mean ? because i am using the array for the virtual wire to send data via RF transmitter

  1. Array has 10 characters. Your sprintf can have up to 12 characters, and it still requires a NULL terminator.

So, if you're not sending the value in Array, what is this in your code for Arduino 1, right there at the bottom where it says Serial.println?

  sprintf(Array, "%d,%d,%d.", valBrakes,valThrottle,valSteering);
  vw_send((uint8_t*)Array, strlen(Array));
  vw_wait_tx(); 
  Serial.println(Array);

this is just for the transmitter code,
i am working now on the serial communication between 2 arduinos which is via pin 0 and 1 of both arduinos

i made a small script to check if the pins are broken but it seems they are just fine so i know now that it's a problem from the script, and by the way i change the array to 12

here are the testing script :

arduino 1:

void setup(){
  Serial.begin(9600);
}

void loop(){
  Serial.write('1');
}

arduino 2 :

void setup(){
  Serial.begin(9600);
  pinMode(13, OUTPUT);
}

void loop(){
  if(Serial.available() > 0){
    int value = Serial.read();
    if(value == '1'){
      digitalWrite(13, HIGH);
      delay(2000);
      digitalWrite(13, LOW);
      delay(2000);
    }
  }
}

firashelou:
this is just for the transmitter code,

Then what is the Serial.println doing in there? It looks a lot like you are sending a variable called Array.

i am working now on the serial communication between 2 arduinos which is via pin 0 and 1 of both arduinos

i made a small script to check if the pins are broken but it seems they are just fine so i know now that it's a problem from the script, and by the way i change the array to 12

You need to be more specific in telling us what the problem is. Your simple program works, sending over Serial from Arduino 1 to Arduino 2. How do you know it isn't working in the full program? Tell us what you expect to see, and what you do see.

Where in your code do you check the values sent when you send Array over Serial?

If your code is no longer the same as what you've posted, let us know, and show us the revised code.

the codes are exactly the same as posted
what i am doing is : clicking a push button called Reverse and connected to arduino 1 it's to let the reverse option be on, which will make the motor go in reverse position, so when i click this button, the arduino 1 should send a character which is 'r' to arduino 2 via TX pin 1, and then the arduino 2 will get that variable and turn on a LED to indicate that reverse has been enabled

so this operation the sending via TX pin 1 is not being received from arduino 2, nevertheless arduino 1 is sending the variable and showing it on the monitor . The part which is not being send is the Serial.write()
for the record, the Transmitter is sending data fine to the receiver module

so i am sure now that the problem is from the code and not hardware after making the small test i posted in the last reply

does Virtual Wire and Serial. interfere ? because it seems that when i introduce the virtual wire commands to send wireless data, the Serial connection between the 2 arduinos is broken !!

do you think i must use the software serial ?
and if yes, can i use it with pins 0 and 1 ?

the Solution :

i had to use SoftwareSerial.h to redefine the TX and RX pin 0 and 1 on the arduino 1 and leave the arduino 2 as it is , or it will not work with Virtual Wire

here is the last version of codes for the arduino 1 TX :

//Transmitter
#include <VirtualWire.h>
#include <SoftwareSerial.h>

SoftwareSerial mySerial(0, 1); //RX, TX

char Array[12];
int potPin1 = A0;    // Throttle
int potPin2 = A1;    // Brakes
int potPin3 = A2;    //Streering 

//these values will be sent by the transmitter
int valThrottle = 0;  
int valBrakes = 0;
int valSteering = 0;

int transmitterPin = 10; //transmitter pin

int downShift = 2; //Left paddle shift pin 2
int upShift = 3; //Right paddle shift pin 3
int burnout = 5; //Burnout Button pin 5
int neutral = 6; //Neutral Green Button pin 6
int reverse = 7; //Reverse Button pin 7
int limiter = 8; //Pit Limiter Button pin 8
//int cam = 9; //Cam grey Button pin 9
//pin 4 is the white button

//downShift
boolean lastDownshift= LOW; 
boolean currentDownshift = LOW; 

//upShift
boolean lastUpshift = LOW; 
boolean currentUpshift = LOW; 

//burnout
boolean lastBurnout = LOW; 
boolean currentBurnout = LOW;
boolean burnoutState = HIGH;

//neutral
boolean lastNeutral = LOW; 
boolean currentNeutral = LOW; 
boolean neutralState = HIGH;

//reverse
boolean lastReverse = LOW; 
boolean currentReverse = LOW; 
boolean reverseState = HIGH;

//limiter
boolean lastLimiter = LOW; 
boolean currentLimiter = LOW; 
boolean limiterState = HIGH;

//cam
boolean lastCam = LOW; 
boolean currentCam = LOW; 
boolean camState = HIGH;

int gearBox = 0;

void setup()
{
  //Serial.begin(9600);
  mySerial.begin(9600);	  // Debugging only
  //Serial.println("Sending"); // Debugging only

  // Initialise the IO and ISR
  //vw_set_ptt_inverted(true); // Required for DR3100
  vw_setup(2000);	 // Bits per sec
  vw_set_tx_pin(transmitterPin); //RF sending pin Arduino Mega
  
  for(int i = 2; i<10; i++){
    pinMode(i, INPUT);
  }
  
  pinMode(0, INPUT);
  pinMode(1, OUTPUT);
  
}

//debounce function
boolean debounce(boolean last, int button)
{
  boolean current = digitalRead(button);
  if(last != current)
  {
    delay(5);
    current = digitalRead(button);
  }
  return current;
}



void loop(){
  //Putting Limits for the gear box up and down
  if(gearBox > 6){
     gearBox = 6;
  }else if(gearBox < 0){
     gearBox = 0;
  }  
  
  //for the downShift
  currentDownshift = debounce(lastDownshift, downShift);
  if(lastDownshift == LOW && currentDownshift == HIGH)
  {
    mySerial.write('-');
    gearBox--;
  }
  lastDownshift = currentDownshift;
  
  
  //for the upShift
  currentUpshift = debounce(lastUpshift, upShift);
  if(lastUpshift == LOW && currentUpshift == HIGH)
  {
    mySerial.write('+');
    gearBox++;
  }
  lastUpshift = currentUpshift;
  
  
  //for the burnout
  currentBurnout = debounce(lastBurnout, burnout);
  if(lastBurnout == HIGH && currentBurnout == LOW)
  { 
    Serial.write('b');
    neutralState = !neutralState;
    Serial.println(neutralState);
    delay(1000);
  }  
  
  lastBurnout = currentBurnout;
  
  
  //for the neutral
  currentNeutral = debounce(lastNeutral, neutral);
  if(lastNeutral == HIGH && currentNeutral == LOW)
  {
    Serial.write('n');
    neutralState = !neutralState;
    Serial.println(neutralState);
    delay(1000);
    
  }
  lastNeutral = currentNeutral;
  
  
  //for the reverse
  currentReverse = debounce(lastReverse, reverse);
  if(lastReverse == HIGH && currentReverse == LOW)
  {
    Serial.write('r');
    reverseState = !reverseState;
    Serial.println(reverseState);
    delay(1000);
  }
  lastReverse = currentReverse;
  
  
  //for the limiter
  currentLimiter = debounce(lastLimiter, limiter);
  if(lastLimiter == HIGH && currentLimiter == LOW)
  {
    Serial.write('l');
    limiterState = !limiterState;
    Serial.println(limiterState);
    delay(1000);
    
  }
  lastLimiter = currentLimiter;
  
  
  //for the cam
  /*currentCam = debounce(lastCam, cam);
  if(lastCam == HIGH && currentCam == LOW)
  {
     Serial.write('c');
     camState = !camState;
    Serial.println(camState);
    delay(1000);
  }
  lastCam = currentCam;*/
  
  //transmitter codes
  valThrottle = analogRead(potPin1);  // read the value from the sensor
  if(neutralState == LOW){
    
    valThrottle = map(valThrottle, 0, 55, 0, 0); 
    valThrottle = constrain(valThrottle, 0, 0);
    
  }else if(limiterState == LOW){
    
    valThrottle = map(valThrottle, 0, 55, 0, 150); 
    valThrottle = constrain(valThrottle, 0, 150);
    
  }else if(burnoutState == LOW){
    
    valThrottle = map(valThrottle, 0, 5, 0, 255); 
    valThrottle = constrain(valThrottle, 0, 255);
    
  }else{
    //defining the speeds according to gear box
    
      
      valThrottle = map(valThrottle, 0, 55, 0, 255); 
      valThrottle = constrain(valThrottle, 0, 255);
      /*
      //defining the speeds according to gear box
    if(gearBox == 1){
      
      valThrottle = map(valThrottle, 0, 55, 0, 60); 
      valThrottle = constrain(valThrottle, 0, 60);
      
    }
    if(gearBox == 2){
      
      valThrottle = map(valThrottle, 0, 55, 61, 100); 
      valThrottle = constrain(valThrottle, 61, 100);
      
    }
    if(gearBox == 3){
    
      valThrottle = map(valThrottle, 0, 55, 101, 150); 
      valThrottle = constrain(valThrottle, 101, 150);
      
    }
    if(gearBox == 4){
    
      valThrottle = map(valThrottle, 0, 55, 151, 190); 
      valThrottle = constrain(valThrottle, 151, 190);  
      
    }
    if(gearBox == 5){
    
      valThrottle = map(valThrottle, 0, 55, 191, 220); 
      valThrottle = constrain(valThrottle, 191, 220);  
      
    }
    if(gearBox == 6){
    
      valThrottle = map(valThrottle, 0, 55, 221, 255); 
      valThrottle = constrain(valThrottle, 221, 255);  
      
    }
      */
    
  }
  
  
  valBrakes = analogRead(potPin2);  // read the value from the sensor
  if(reverseState == LOW){
    
    valBrakes = map(valBrakes, 1023, 954, 0, 255); 
    valBrakes = constrain(valBrakes, 0, 255);
    
  }else if(reverseState == HIGH){
    
    valBrakes = map(valBrakes, 1023, 954, 0, 10); 
    valBrakes = constrain(valBrakes, 0, 10);
    
  }
  
  valSteering = analogRead(potPin3); // 0 to 1023
  valSteering = map(valSteering, 0, 1023, 255, 0);
  Serial.println(valSteering);
  
  sprintf(Array, "%d,%d,%d.", valBrakes,valThrottle,valSteering);
  vw_send((uint8_t*)Array, strlen(Array));
  vw_wait_tx(); 
  Serial.println(Array);
    
}

so the

quite a complex problem but tyy using software serial

profmuluka:
quite a complex problem but tyy using software serial

what does tyy mean ?

firashelou:
does Virtual Wire and Serial. interfere ? because it seems that when i introduce the virtual wire commands to send wireless data, the Serial connection between the 2 arduinos is broken !!

It's possible, I suppose, but I have a project that is running just fine with SPI, Serial, and VirtualWire. It's a Cloud Sensor, and communicates over a 433 MHz trasnitter to receiver on another Arduino running the same way.

do you think i must use the software serial ?
and if yes, can i use it with pins 0 and 1 ?

You've marked this thread SOLVED. Was it solved when you went to Software Serial?

ok your project is different

for my project what is solved is this :

i have 3 arduinos, 2 are connected by pin 0 and 1 serially
the 3rd arduino is connected to the receiver

arduino number 1 has the transmitter, push buttons and potentiometers connected to it and arduino number 2 has LEDs and displays,

when i click a push button on arduino 1, it should send a character to arduino number 2 to make the LEDs interact with the change or the displays and when i turn any of the potentiometers, arduino number 1 should send this data to arduino number 3 using the transmitter

the problem solved is that i can now use the transmitter and the Serial ports pin 0 and 1 in the same time after i used the SoftwareSerial, but before i couldn't use them in the same time

So I understand we're looking at serial comms, not virtual wire comms.

Virtual Wire uses Timer1 but that isn't needed for Serial hardware comms as far as I know.

When testing the serial comms, have you connected the grounds too? How are the two Arduinos powered?

The virtual wire code you posted looks pretty flaky - you STILL haven't made the array holding the message big enough for its contents (remember you need to include a byte for the null terminator so you need a minimum of 13 bytes) and you ought to use snprintf() not sprintf() to avoid that problem biting you again in future.

While you're investigating this comms issue I suggest you put your main sketch to one side and just add minimal code to do the virtual wire sending to the serial test sketch that you posted. Then it will be easy to see what effect virtual wire calls have on serial I/O.

PeterH:
So I understand we're looking at serial comms, not virtual wire comms.

Virtual Wire uses Timer1 but that isn't needed for Serial hardware comms as far as I know.

When testing the serial comms, have you connected the grounds too? How are the two Arduinos powered?

The virtual wire code you posted looks pretty flaky - you STILL haven't made the array holding the message big enough for its contents (remember you need to include a byte for the null terminator so you need a minimum of 13 bytes) and you ought to use snprintf() not sprintf() to avoid that problem biting you again in future.

While you're investigating this comms issue I suggest you put your main sketch to one side and just add minimal code to do the virtual wire sending to the serial test sketch that you posted. Then it will be easy to see what effect virtual wire calls have on serial I/O.

actully i have to work on really understanding the virtual wire
but as i said before the array has nothing to do with the problem here because i am just using the array for virtual wire for the transmitter

the problem was that virtual wire and serial coms didn't work together unless i used SoftwareSerial

As I said, I used Serial and VirtualWire at the same time, both on transmitter and receiver, with no interaction or problems. You say my project is different, but it is the same as far as using Serial and VitualWire.

You also say your sketch is still the same as what you posted, and further, that you send Array only over VirtualWire. The sketch says otherwise, unless you really have changed it. Further, whether you send it via Serial, VirtualWire, or whatever, you STILL need to size the array properly, or you stand a chance of having strange problems when you overwrite memory that belongs to some other variable.

Oh well, you say it's solved, and I really hope it is, but I think there are likely other problems that interference between VirtualWire and Serial.

lar3ry:
As I said, I used Serial and VirtualWire at the same time, both on transmitter and receiver, with no interaction or problems. You say my project is different, but it is the same as far as using Serial and VitualWire.

You also say your sketch is still the same as what you posted, and further, that you send Array only over VirtualWire. The sketch says otherwise, unless you really have changed it. Further, whether you send it via Serial, VirtualWire, or whatever, you STILL need to size the array properly, or you stand a chance of having strange problems when you overwrite memory that belongs to some other variable.

Oh well, you say it's solved, and I really hope it is, but I think there are likely other problems that interference between VirtualWire and Serial.

do you have a connection between 2 arduinos via TX and RX pin 0 and 1 in your project because you didn't mentioned that ?
means you must have 3 arduinos

and about the array its size is 12, then how much do i have to make it ?