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);
}