Take the 2-minute tour ×
Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It's 100% free, no registration required.

how to send input values from host computer to arduino,such that speficing the number of rotations for a stepper motor etc

share|improve this question

put on hold as too broad by Ignacio Vazquez-Abrams, Gerben, BrettAM, LoganBlades, Annonomus Penguin yesterday

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs. If this question can be reworded to fit the rules in the help center, please edit the question.

    
Via serial. Most CNCs and 3D printers send GCode over serial. –  Gerben Apr 15 at 19:18

1 Answer 1

up vote 0 down vote accepted

The easiest method is to use the serial communication. Use the sample code at http://arduino.cc/en/Tutorial/SwitchCase2, upload that to an Arduino, start the serial monitor (Ctrl+Shift+M), make sure the baud rate is the same as set in the code (9600 in this case), then write the commands and send them to the Arduino.

Edit Since the serial characters are usually read one by one you need a character that will signal the end of the string. This is usually a newline \n, but can be any character you choose (and can be sent to Arduino).

Sample code (processString would be your function to do something with the string):

char buf[64];
byte cnt = 0;
void loop() 
{
    while (Serial.available()>0) {
        byte c = Serial.read();
        // Check for terminator character or the size of buffer
        if (c == '\n' || cnt >= 63) {
            // Add the terminating 0
            buf[cnt] = 0;
            // Process the full string
            processString(buf);
            // Prepare to read the next string
            cnt = 0;
        } else {
            // Not terminator - add to string
            buf[cnt++] = c;
        }
    }
}
share|improve this answer
    
okay.If i want to sent a string the same read() is used? Is there any modifications needed for sending strings? –  midhun johnson 2 days ago
    
check my updated answer above –  rslite 2 days ago
    
thank you for the help –  midhun johnson 2 days ago

Not the answer you're looking for? Browse other questions tagged or ask your own question.