Skip to content

Improve sketches that use Serial comunication #5336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
// wait for Serial port initialization.
// Needed for boards that use native USB port such as
// ATMEGA32U4 based boards, Arduino/Genuino 101,
// Arduino Due and Arduino/Genuino Zero (Native Port)
while(!Serial) ;
}

// the loop routine runs over and over again forever:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ int pushButton = 2;
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
// wait for Serial port initialization.
// Needed for boards that use native USB port such as
// ATMEGA32U4 based boards, Arduino/Genuino 101,
// Arduino Due and Arduino/Genuino Zero (Native Port)
while(!Serial) ;
// make the pushbutton's pin an input:
pinMode(pushButton, INPUT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
// wait for Serial port initialization.
// Needed for boards that use native USB port such as
// ATMEGA32U4 based boards, Arduino/Genuino 101,
// Arduino Due and Arduino/Genuino Zero (Native Port)
while(!Serial) ;
}

// the loop routine runs over and over again forever:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
void setup() {
//start serial connection
Serial.begin(9600);
// wait for Serial port initialization.
// Needed for boards that use native USB port such as
// ATMEGA32U4 based boards, Arduino/Genuino 101,
// Arduino Due and Arduino/Genuino Zero (Native Port)
while(!Serial) ;
//configure pin2 as an input and enable the internal pull-up resistor
pinMode(2, INPUT_PULLUP);
pinMode(13, OUTPUT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ void setup() {
pinMode(ledPin, OUTPUT);
// initialize serial communication:
Serial.begin(9600);
// wait for Serial port initialization.
// Needed for boards that use native USB port such as
// ATMEGA32U4 based boards, Arduino/Genuino 101,
// Arduino Due and Arduino/Genuino Zero (Native Port)
while(!Serial) ;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ This example code is in the public domain.
void setup() {
// initialize serial communications (for debugging only):
Serial.begin(9600);
// wait for Serial port initialization.
// Needed for boards that use native USB port such as
// ATMEGA32U4 based boards, Arduino/Genuino 101,
// Arduino Due and Arduino/Genuino Zero (Native Port)
while(!Serial) ;
}

void loop() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ int outputValue = 0; // value output to the PWM (analog out)
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
// wait for Serial port initialization.
// Needed for boards that use native USB port such as
// ATMEGA32U4 based boards, Arduino/Genuino 101,
// Arduino Due and Arduino/Genuino Zero (Native Port)
while(!Serial) ;
}

void loop() {
Expand Down
5 changes: 5 additions & 0 deletions build/shared/examples/03.Analog/Smoothing/Smoothing.ino
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ int inputPin = A0;
void setup() {
// initialize serial communication with computer:
Serial.begin(9600);
// wait for Serial port initialization.
// Needed for boards that use native USB port such as
// ATMEGA32U4 based boards, Arduino/Genuino 101,
// Arduino Due and Arduino/Genuino Zero (Native Port)
while(!Serial) ;
// initialize all the readings to 0:
for (int thisReading = 0; thisReading < numReadings; thisReading++) {
readings[thisReading] = 0;
Expand Down
5 changes: 5 additions & 0 deletions build/shared/examples/04.Communication/Dimmer/Dimmer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ const int ledPin = 9; // the pin that the LED is attached to
void setup() {
// initialize the serial communication:
Serial.begin(9600);
// wait for Serial port initialization.
// Needed for boards that use native USB port such as
// ATMEGA32U4 based boards, Arduino/Genuino 101,
// Arduino Due and Arduino/Genuino Zero (Native Port)
while(!Serial) ;
// initialize the ledPin as an output:
pinMode(ledPin, OUTPUT);
}
Expand Down
5 changes: 5 additions & 0 deletions build/shared/examples/04.Communication/Graph/Graph.ino
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
void setup() {
// initialize the serial communication:
Serial.begin(9600);
// wait for Serial port initialization.
// Needed for boards that use native USB port such as
// ATMEGA32U4 based boards, Arduino/Genuino 101,
// Arduino Due and Arduino/Genuino Zero (Native Port)
while(!Serial) ;
}

void loop() {
Expand Down
5 changes: 5 additions & 0 deletions build/shared/examples/04.Communication/Midi/Midi.ino
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
void setup() {
// Set MIDI baud rate:
Serial.begin(31250);
// wait for Serial port initialization.
// Needed for boards that use native USB port such as
// ATMEGA32U4 based boards, Arduino/Genuino 101,
// Arduino Due and Arduino/Genuino Zero (Native Port)
while(!Serial) ;
}

void loop() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ void setup() {
// initialize both serial ports:
Serial.begin(9600);
Serial1.begin(9600);
// wait for Serial and Serial1 ports initialization.
// Needed for boards that use native USB port such as
// ATMEGA32U4 based boards, Arduino/Genuino 101,
// Arduino Due and Arduino/Genuino Zero (Native Port)
while(!Serial && !Serial1) ;
}

void loop() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ int incomingByte; // a variable to read incoming serial data into
void setup() {
// initialize serial communication:
Serial.begin(9600);
// wait for Serial port initialization.
// Needed for boards that use native USB port such as
// ATMEGA32U4 based boards, Arduino/Genuino 101,
// Arduino Due and Arduino/Genuino Zero (Native Port)
while(!Serial) ;
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@ const int greenPin = 5;
const int bluePin = 6;

void setup() {
// initialize serial:
// start serial comunication
Serial.begin(9600);
// wait for Serial port initialization.
// Needed for boards that use native USB port such as
// ATMEGA32U4 based boards, Arduino/Genuino 101,
// Arduino Due and Arduino/Genuino Zero (Native Port)
while(!Serial) ;
// make the pins outputs:
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ boolean stringComplete = false; // whether the string is complete
void setup() {
// initialize serial:
Serial.begin(9600);
// wait for Serial port initialization.
// Needed for boards that use native USB port such as
// ATMEGA32U4 based boards, Arduino/Genuino 101,
// Arduino Due and Arduino/Genuino Zero (Native Port)
while(!Serial) ;
// reserve 200 bytes for the inputString:
inputString.reserve(200);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
void setup() {
Serial.begin(9600);
Serial1.begin(9600);
// wait for Serial and Serial1 ports initialization.
// Needed for boards that use native USB port such as
// ATMEGA32U4 based boards, Arduino/Genuino 101,
// Arduino Due and Arduino/Genuino Zero (Native Port)
while(!Serial && !Serial1) ;
}

void loop() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ const int bluePin = A2; // sensor to control blue color

void setup() {
Serial.begin(9600);
// wait for Serial port initialization.
// Needed for boards that use native USB port such as
// ATMEGA32U4 based boards, Arduino/Genuino 101,
// Arduino Due and Arduino/Genuino Zero (Native Port)
while(!Serial) ;
}

void loop() {
Expand Down
5 changes: 5 additions & 0 deletions build/shared/examples/06.Sensors/ADXL3xx/ADXL3xx.ino
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ const int zpin = A1; // z-axis (only on 3-axis models)
void setup() {
// initialize the serial communications:
Serial.begin(9600);
// wait for Serial port to connect
// Needed for boards that use native USB port such as
// ATMEGA32U4 based boards, Arduino/Genuino 101,
// Arduino Due and Arduino/Genuino Zero (Native Port)
while(!Serial) ;

// Provide ground and power by using the analog inputs as normal
// digital pins. This makes it possible to directly connect the
Expand Down
5 changes: 5 additions & 0 deletions build/shared/examples/06.Sensors/Knock/Knock.ino
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ int ledState = LOW; // variable used to store the last LED status, to to
void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT
Serial.begin(9600); // use the serial port
// wait for Serial port initialization.
// Needed for boards that use native USB port such as
// ATMEGA32U4 based boards, Arduino/Genuino 101,
// Arduino Due and Arduino/Genuino Zero (Native Port)
while(!Serial) ;
}

void loop() {
Expand Down
7 changes: 6 additions & 1 deletion build/shared/examples/06.Sensors/Memsic2125/Memsic2125.ino
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@ const int xPin = 2; // X output of the accelerometer
const int yPin = 3; // Y output of the accelerometer

void setup() {
// initialize serial communications:
// initialize serial communication:
Serial.begin(9600);
// wait for Serial port to connect.
// Needed for boards that use native USB port such as
// ATMEGA32U4 based boards, Arduino/Genuino 101,
// Arduino Due and Arduino/Genuino Zero (Native Port)
while(!Serial) ;
// initialize the pins connected to the accelerometer
// as inputs:
pinMode(xPin, INPUT);
Expand Down
5 changes: 5 additions & 0 deletions build/shared/examples/06.Sensors/Ping/Ping.ino
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ const int pingPin = 7;
void setup() {
// initialize serial communication:
Serial.begin(9600);
// wait for Serial port to connect.
// Needed for boards that use native USB port such as
// ATMEGA32U4 based boards, Arduino/Genuino 101,
// Arduino Due and Arduino/Genuino Zero (Native Port)
while(!Serial) ;
}

void loop() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
void setup() {
// open the serial port:
Serial.begin(9600);
// wait for Serial port initialization.
// Needed for boards that use native USB port such as
// ATMEGA32U4 based boards, Arduino/Genuino 101,
// Arduino Due and Arduino/Genuino Zero (Native Port)
while(!Serial) ;
// initialize control over the keyboard:
Keyboard.begin();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ void setup() { // initialize the buttons' inputs:
pinMode(mouseButton, INPUT);

Serial.begin(9600);
// wait for Serial port initialization.
// Needed for boards that use native USB port such as
// ATMEGA32U4 based boards, Arduino/Genuino 101,
// Arduino Due and Arduino/Genuino Zero (Native Port)
while(!Serial) ;
// initialize mouse control:
Mouse.begin();
Keyboard.begin();
Expand Down