D
D
de1m2015-04-18 22:59:50
Arduino
de1m, 2015-04-18 22:59:50

Arduino reset when connected via serial port, what to do?

There is a very simple code

#define LED 5

int input = 0;       // variable to keep the data from the serial port

void setup() {
  pinMode(LED,OUTPUT);    // declare the LED's pin as output
  Serial.begin(9600);        // connect to the serial port
  digitalWrite(LED,HIGH);
}

void loop () {
  input = Serial.read();      // read the serial port

  // if the input is '1' turn the LED ON, if '0' turn it OFF
  if (input == '1' ) {
    digitalWrite(LED,LOW);
    Serial.println("LED13 is ON");
  } 
  if (input == '0'){
      digitalWrite(LED, HIGH);
      Serial.println("LED13 is OFF");
  }
}

I have an rgb led with a common plus, so the values ​​are reversed.
The problem is that when I send a command (1) to turn on the led, it turns on and works, but as long as there is a connection on the serial port. As soon as I turn it off, the light is no longer on.
Here they write that when connecting, the arduins are reset and you can theoretically turn off the DTR line, then it seems like the reset will not work, but it will be necessary to do the reset manually before the firmware.
How can I make the light stay on even after the serial connection is terminated? Is there some other way?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander, 2015-04-19
@de1m

There is a special jumper - on the DTR-> Reset line - you need to remove it. No other friend.

D
de1m, 2015-04-19
@de1m

While I began to write the value in eeprom, which is then read at startup. But I suspect that this is not a very correct way, but for the test, let it stay for a while.

N
Nysha, 2015-04-23
@Nysha

you can Serial.read(); put in an interrupt from uart about receiving a character.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question