3

I am attempting to control a stepper motor with Sparkfun's Big Easy Driver, and I see the line "Serial.println();" they put in the example code. Why is there no argument and what function does this serve?

//Declare pin functions on Arduino
#define stp 2
#define dir 3
#define MS1 4
#define MS2 5
#define MS3 6
#define EN 7
//Declare variables for functions
char user_input;
int x;
int y;
int state;
void setup() {
 pinMode(stp, OUTPUT);
 pinMode(dir, OUTPUT);
 pinMode(MS1, OUTPUT);
 pinMode(MS2, OUTPUT);
 pinMode(MS3, OUTPUT);
 pinMode(EN, OUTPUT);
 resetBEDPins(); //Set step, direction, microstep and enable pins to default states
 Serial.begin(9600); //Open Serial connection for debugging
 Serial.println("Begin motor control");
 Serial.println();
 //Print function list for user selection
 Serial.println("Enter number for control option:");
 Serial.println("1. Turn at default microstep mode.");
 Serial.println("2. Reverse direction at default microstep mode.");
 Serial.println("3. Turn at 1/16th microstep mode.");
 Serial.println("4. Step forward and reverse directions.");
 Serial.println();
}
asked Apr 10, 2019 at 17:29
5
  • 2
    prints everything in the argument, followed by a newline .... in other words, prints just a newline Commented Apr 10, 2019 at 17:32
  • 1
    when you post code in a question, select all of the code and press ctrl-k or click the {} button .... all of the code will be indented by 4 spaces, which causes it to be displayed as code ...... upvote for being concerned with code formatting Commented Apr 10, 2019 at 17:35
  • That's simple. Thanks! So if you had printed text (surrounded by quotation marks) before, the same effect would be achieved by putting in a "\n", correct? Commented Apr 10, 2019 at 18:27
  • yes, serial.print("\n"); gives same result as serial.println(); Commented Apr 10, 2019 at 23:43
  • @jsotola: No, Serial.println() outputs a '\r' before the '\n', which Serial.print("\n") doesn't. Commented Apr 11, 2019 at 7:21

2 Answers 2

2

It simply prints a newline to the serial monitor. Just for spacing.

answered Apr 10, 2019 at 17:30
2

To complement jose can u c's answer: the Arduino Serial object uses CRLF as the end-of-line marker. That's an ASCII CR (carriage return, or '\r' in C) followed by ASCII LF (line feed, '\n' in C). Thus,

Serial.println();

is equivalent to

Serial.print("\r\n");
answered Apr 10, 2019 at 19:03
1
  • This is a cool expansion on some fundamental formatting stuff. Thank you for the info Commented Apr 10, 2019 at 20:23

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.