re-enable serial communication

How to re-enable the serial communication once it was stopped with Serial.end() ?

The reference page just says to call Serial.begin() but i tried it in the loop and i only get strange characters on the serial monitor.

Thanks a lot!

You should set the speed in Serial.begin() - something like Serial.begin(9600) - if it is still broken then please post your code (with code tags, button #).

Yes i did, Serial.begin(9600).

Sorry, don't know exactly what you mean for posting with code tags, button #, i started programming one week ago and i'm still not practical with conventions.

Board is UNO R3 there is a potentiometer connected on analog input A0, when the pot is all the way down the built-in led powers up and serial communication stops. When pot is being turned up serial comm should start again...

//potenziometro collegato su ingresso analogico A0

int potValue = 0; int ledPin = 13; void setup() { Serial.begin(9600); pinMode(13, OUTPUT); }

void loop() {

potValue = analogRead(0); Serial.println(potValue); if (potValue == 0) { Serial.end(); digitalWrite(13, HIGH); } if (potValue > 0) { digitalWrite(13, LOW); Serial.begin(9600); } if (potValue > 850) { digitalWrite(13, HIGH); delay(30); digitalWrite(13, LOW); delay(30); } delay(100); }

When you post your code, above the text entry box are a number of buttons. One of them has a '#' on it. Select the text of your code and press the '#' button. It will put [code]...[/code] tags around your code. The result will look

like this.

I don't really understand the point of stopping Serial in that sketch.

Why do you want to stop the serial connection? I would just leave it out completely (only leaving it in setup()) and try to manage the calls of Serial.println(). Why? Because Serial.println() is a blocking call when the send buffer is full. Additionally it is not checking if the connection is initialized. This results in filling the buffer and then blocking, but there is no routine to empty the buffer if you stopped the serial communication. That's why the communication is not restarting.

If you send the analog value on each read the send buffer will fill up faster than it can be send at 9600 baud. Your loop will wait at Serial.println() until the send buffer accepts more data. Maybe you should only send every second (see millis()). A higher baud rate would allow faster sending - still the loop will be too fast.

@dxw00d: how do you escape the tags?

I wrap the opening '[' in a font-size tag. You need to do it for both code tags. Other people (Nick, in his sticky, for example) use the glow tag.

OK, thank you!

I'm just learning and there's no utility behind it if not teaching myself programming.

@dxw00d: thank you - this was too easy :roll_eyes:

@lee_chuck: The Arduino software and the libraries are a powerful utility if you know how to program in C/C++. There are examples in the file menu to get started.