do i have to end a serial communication ? is there any function ?

hello guys,
when i turn my circuit on, a LED is on which is not supposed to be. The system consist of a serial communication between 3 arduinos using pins 0 and 1, so i need to know why this is happening ? does the arduino send data on start even if it doesnt have to ? is there any function that i should use to end sending data ? seems that it is sending data on start even if i never clicked the button :S

schematic (attachment file)

code for arduino 1 (push button is connected to this arduino) :

//Arduino number 1

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 lastButton1 = LOW; 
boolean currentButton1 = LOW; 

//upShift
boolean lastButton2 = LOW; 
boolean currentButton2 = LOW; 

//burnout
boolean lastButton4 = LOW; 
boolean currentButton4 = LOW;

void setup(){
  Serial.begin(9600);
  for(int i = 2; i<9; 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
  currentButton1 = debounce(lastButton1, downShift);
  if(lastButton1 == LOW && currentButton1 == HIGH)
  {
    Serial.write('-');
  }
  lastButton1 = currentButton1;
  
  
  //for the upShift
  currentButton2 = debounce(lastButton2, upShift);
  if(lastButton2 == LOW && currentButton2 == HIGH)
  {
    Serial.write('+');
  }
  lastButton2 = currentButton2;
  
  
  //for the burnout
  currentButton4 = debounce(lastButton4, burnout);
  if(lastButton4 == LOW && currentButton4 == HIGH)
  { 
    Serial.write('b');
  }  
  
  lastButton4 = currentButton4;

code for second arduino (this one has displays connected but now it is just sending data for 3rd arduino) :

//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
                         };
                   
int burnoutOn = 0;
int burnoutCounter = 0;

int neutralOn = 0;
int neutralCounter = 0;

int reverseOn = 0;
int reverseCounter = 0;

int limiterOn = 0;
int limiterCounter = 0;

int camOn = 0;
int camCounter = 0;

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 = 1;
      Serial.write('w'); //this to turn the red LED on from arduino 3
      
    }
    

   if(burnoutOn == 1 || neutralOn == 1 || reverseOn == 1 || limiterOn == 1){
    if(burnoutOn == 1){
        
        
        burnoutCounter ++;
        
        if(burnoutCounter == 2){
          burnoutOn =0;
          burnoutCounter = 0;
        }
        
        
      }
      }else{
        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;
      }
    
  }//end of Serial.available
  
    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);
  }
}

code for 3rd arduino (this one has the LED connected to it, it is supposed to be on when i click the push button):

byte redLED = 2;
byte greenLED = 3;
byte yellowLED = 4;
byte blueLED = 5;

int redLEDon = 0;
int redLEDcounter = 0;

int greenLEDon = 0;
int greenLEDcounter = 0;

int yellowLEDon = 0;
int yellowLEDcounter = 0;

int blueLEDon = 0;
int blueLEDcounter = 0;

void setup(){
  Serial.begin(9600);
  
  for(int i = 2; i<6; i++){
    pinMode(i, OUTPUT);
    digitalWrite(i, LOW);
  }
  
}

void loop(){
  
  if(Serial.available() > 0){
    greenLEDon = 0;
    redLEDon = 0;
    yellowLEDon = 0;
    blueLEDon = 0;
    
    int value = Serial.read();
    if(value == 'w'){
      //w for the red LED
      redLEDon = 1;

    }
    
    
    
    if(redLEDon == 1 || greenLEDon == 1 || yellowLEDon == 1 || blueLEDon == 1){
      if(redLEDon == 1){
        
        
        redLEDcounter++;
        if(redLEDcounter > 2){
          redLEDcounter = 2;
        }
        if(redLEDcounter == 2){
          redLEDon = 0;
          redLEDcounter = 0;
          digitalWrite(redLED, LOW);
        }else{
          digitalWrite(redLED, HIGH);
        }
        
      }else{
        digitalWrite(redLED, LOW);
      }
      
      
  }else{
      digitalWrite(redLED, LOW);
      digitalWrite(greenLED, LOW);
      digitalWrite(yellowLED, LOW);
      digitalWrite(blueLED, LOW);
  }
  
  }//end of Serial.available
  
  
}

How are the buttons wired? Specifically do you have external pull-down resistors?

MarkT: How are the buttons wired? Specifically do you have external pull-down resistors?

yes all the hardware right stuff are done, as long as i was programming, i found out that it is probably a program error but i can't find it or order in statement or some function that is necessary to end the serial communication after executing or before :(

i have a pull down resistor which is connected to one of the pins of the button and this same pin is connected to arduino, the other pin of the button is connected to the +5V going out from a voltage regulator

i have a pull down resistor which is connected to one of the pins of the button and this same pin is connected to arduino, the other pin of the button is connected to the +5V going out from a voltage regulator

It's (past) time for you to post a picture or schematic. This verbal description just doesn't sound right.

ok i will do a simple one, the thing is because i am working on a schematic for the whole circuit by the way which software can i use if i want to draw it on pc and not by hand ?

small schematic added

lar3ry:

firashelou: ok i will do a simple one, the thing is because i am working on a schematic for the whole circuit by the way which software can i use if i want to draw it on pc and not by hand ?

You could download Fritzing. You can get it at http://fritzing.org/, or, for this simple case, you could just use text. Here's how you wire a pulldown:

5V | | |----- Arduino pin 4 | \ \ | | GND

i have the fritzing i need something else if it's possible something just for schematic and not for components

firashelou: i have the fritzing i need something else if it's possible something just for schematic and not for components

Sorry about that. I saw you had added the schematic, and I meant to not post my (unfinished) ASCII schematic. Hit the Post button, then removed it.

A lot of folks like the freeware version of the schematic editor called Eagle. It only allows one sheet, but for small projects, it often enough.

Wikipedia has a bunch listed. Try Googling "schematic editor" freeware

ok i will try eagle and express pcb i found one before and download it, it said for student and for free but it didn't work i forgot its name

hello guys, is there anyway to clear the arduino serial memory or the memory where it keeps arduino's last execution command before it's off ?

What??????????????

Mark

i mean, when i turn on the arduinos, 3 arduinos in serial, it’s like the command is executing and sending a char without even clicking anything !! so isn’t this related to some memory that is keeping data or something ?

The last program you loaded stays in the Arduino until you load a new program.

Mark

it's like the command is executing and sending a char without even clicking anything

No, it isn't. When are you going to stop posting new threads and tell us how the damned switches are wired?

Please do not cross-post. This wastes time and resources as people attempt to answer your question on multiple threads.

Threads merged.

  • Moderator

PaulS:

it's like the command is executing and sending a char without even clicking anything

No, it isn't. When are you going to stop posting new threads and tell us how the damned switches are wired?

i've put a picture on how the switch is wired

holmes4:
The last program you loaded stays in the Arduino until you load a new program.

Mark

sure but what i meant is, when i turn on the whole system (3 arduinos, 1 pushbutton connected to arduino 1 and a led connected to arduino 3 same as the schematic) the LED is supposed to be off untill i click the push button, but in fact it’s on which is not supposed to be :S
so what might be the problem in the codes ?

sure but what i meant is, when i turn on the whole system (3 arduinos, 1 pushbutton connected to arduino 1 and a led connected to arduino 3 same as the schematic) the LED is supposed to be off untill i click the push button, but in fact it's on which is not supposed to be :S so what might be the problem in the codes ?

I don't see a problem in the code. Are you sure you have the LED wired in correctly?

yea i am 200% sure, when i change the letter in the codes it goes off
but thing is from arduino, it’s like sending the letter even if i am not clicking, so when i click the LED go off and if i click again the LED go on and so on, but the problem i don’t want the LED to be on, when i start the system

How can you be 200% sure?