how to control arduino through the serial monitor - marginally clever robotsw to control arduino...

Upload: tounsi-twensa

Post on 05-Jul-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/16/2019 How to Control Arduino Through the Serial Monitor - Marginally Clever Robotsw to Control Arduino Through the Se…

    1/9

    Home / Tutorials / How to Control Arduino through the Serial Monitor

    Posted on October 18, 2011

    How to Control Arduinothrough the Serial Monitor

    Written by

    Dan

    Posted inTutorials

    Tagged

    arduino, monitor, serial, serial monitor

    Comments

    13 Comments

    When I’m developing Arduino code, I often have variables that need to be tweaked

    Menu

    https://www.marginallyclever.com/author/admin/https://www.marginallyclever.com/https://www.marginallyclever.com/https://www.marginallyclever.com/https://www.marginallyclever.com/https://www.marginallyclever.com/https://www.marginallyclever.com/2011/10/controlling-your-arduino-through-the-serial-monitor/#commentshttps://www.marginallyclever.com/tag/serial-monitor/https://www.marginallyclever.com/tag/serial/https://www.marginallyclever.com/tag/monitor/https://www.marginallyclever.com/tag/arduino/https://www.marginallyclever.com/category/tutorials/https://www.marginallyclever.com/author/admin/https://www.marginallyclever.com/2011/10/controlling-your-arduino-through-the-serial-monitor/https://www.marginallyclever.com/category/tutorials/https://www.marginallyclever.com/

  • 8/16/2019 How to Control Arduino Through the Serial Monitor - Marginally Clever Robotsw to Control Arduino Through the Se…

    2/9

    during testing & calibration.

    Rather than recompile and upload the code (a time consuming process) I wrote a

    few lines to let me open the Serial Monitor and send commands directly.

    I hope you 䆗nd this useful – I use it in all my robots!

    #define DELAY (5)

    #define BAUD (57600)

    #define MAX_BUF (64)

    char buffer[MAX_BUF];

    int sofar;

    char test_on=0; // only used in processCommand as an ex

    float pos_x;

    float pos_y;

    float pos_z;

    void jog(float x, float y, float z) {

    // do some tests here to validate x, y, and z.

    pos_x=x;

    pos_y=y;

    pos_z=z;

    }

    void processCommand() {

    if(!strncmp(buffer,"help",4)) {

      Serial.println("commands: where; test (1/0); jog [x(

      } else if(!strncmp(buffer,"where",5)) {

    // no parameters

    Serial.print(pos_x);

    Search Products…

    0

    https://www.marginallyclever.com/cart/http://www.marginallyclever.com/2011/10/controlling-your-arduino-through-the-serial-monitor/https://www.marginallyclever.com/my-account/

  • 8/16/2019 How to Control Arduino Through the Serial Monitor - Marginally Clever Robotsw to Control Arduino Through the Se…

    3/9

      Serial.print(", ");

    Serial.print(pos_y);

    Serial.print(", ");

    Serial.println(pos_z);

    } else if(!strncmp(buffer,"test",4)) {

    // one whole number parameter

      char *state=strchr(buffer,' ')+1;

    Serial.println(state);

    if(state[0]=='0') {

    Serial.println("End test");

      test_on=0;

    } else {

    Serial.println("Start test");

    test_on=1;

    }

    } else if(!strncmp(buffer,"jog",3)) {

    // several optional float parameters.

    // then calls a method to do something with those pa

      float xx=pos_x;float yy=pos_y;

    float zz=pos_z;

    char *ptr=buffer;

    while(ptr && ptr

  • 8/16/2019 How to Control Arduino Through the Serial Monitor - Marginally Clever Robotsw to Control Arduino Through the Se…

    4/9

    }

    void setup() {

    Serial.begin(BAUD);

    Serial.println("Init...");

    Serial.println("Stretching...");

    sofar=0;

    Serial.println("** AWAKE **");

    }

    void loop() {

    // listen for serial commands

    while(Serial.available() > 0) {

      buffer[sofar++]=Serial.read();

    if(buffer[sofar-1]==';') break; // in case there ar

    }

    // if we hit a semi-colon, assume end of instruction.

    if(sofar>0 && buffer[sofar-1]==';') {

    // what if message fails/garbled?

    // echo confirmation

    buffer[sofar]=0;

    Serial.println(buffer);

    // do something with the command

    processCommand();

    // reset the buffer

    sofar=0;

    // echo completion

  • 8/16/2019 How to Control Arduino Through the Serial Monitor - Marginally Clever Robotsw to Control Arduino Through the Se…

    5/9

    Linear Stewart Platform testvideo #2

    Hypocycloid reduction drives  

      Serial.println("Done.");

    }

    }

    Share this:

     

    Related

    How to use a Ten Pin Seven

    Segment display with Arduino

    Decoding Morse Code with

    an Arduino and a Microphone

    Building and testing

    micromouse sensors

    Leave a ReplyYour email address will not be published. Required 䆗elds are marked *

    Comment 

    https://www.marginallyclever.com/2016/05/building-testing-micromouse-sensors/https://www.marginallyclever.com/2015/02/decoding-morse-code-arduino-microphone/https://www.marginallyclever.com/2016/03/use-ten-pin-seven-segment-display-arduino/https://www.marginallyclever.com/2011/10/controlling-your-arduino-through-the-serial-monitor/?share=reddit&nb=1https://www.marginallyclever.com/2011/10/controlling-your-arduino-through-the-serial-monitor/?share=google-plus-1&nb=1https://www.marginallyclever.com/2011/10/controlling-your-arduino-through-the-serial-monitor/?share=facebook&nb=1https://www.marginallyclever.com/2011/10/controlling-your-arduino-through-the-serial-monitor/?share=twitter&nb=1https://www.marginallyclever.com/2011/10/hypocycloid-reduction-drives/https://www.marginallyclever.com/2011/10/linear-stewart-platform-test-2/

  • 8/16/2019 How to Control Arduino Through the Serial Monitor - Marginally Clever Robotsw to Control Arduino Through the Se…

    6/9

    Name * 

    Email * 

    Website 

    Je ne suis pas un robotreCAPTCHA

    Con䆗dentialité - Conditions

      Post Comment

     Notify me of follow-up comments by email.

     Notify me of new posts by email.

    https://www.google.com/intl/fr/policies/terms/https://www.google.com/intl/fr/policies/privacy/

  • 8/16/2019 How to Control Arduino Through the Serial Monitor - Marginally Clever Robotsw to Control Arduino Through the Se…

    7/9

    Subscribe to Blog via Email

    Search…

     Micromouse maze solving with Processing and the Right Hand Rule

     Makelangelo 7.5.0

     Micromouse encoders to measure distance

     Micromouse motors with continuous servos

     Building and testing micromouse sensors

    RECENT POSTS

    Wesley Knapp on Makelangelo 7.5.0

    Micromouse encoders to measure distance - Marginally Clever Robots on Micromouse motors

    with continuous servos

    Micromouse contest update 2 - Marginally Clever Robots on Micromouse contest update 1

    Micromouse robot building contest - Vancouver Mini Maker FaireVancouver Mini Maker Faire on

    Vancouver Mini Maker Fair 2016 Robot Contest

    Micromouse contest update 1 - Marginally Clever Robots on Vancouver Mini Maker Fair 2016

    Robot Contest

    RECENT COMMENTS

    https://www.marginallyclever.com/2016/02/vancouver-mini-maker-fair-2016-robot-contest/#comment-2635https://www.marginallyclever.com/2016/04/micromouse-contest-update-1/https://www.marginallyclever.com/2016/02/vancouver-mini-maker-fair-2016-robot-contest/#comment-2705http://makerfaire.ca/micromouse/https://www.marginallyclever.com/2016/04/micromouse-contest-update-1/#comment-2709https://www.marginallyclever.com/2016/04/micromouse-contest-update-2/https://www.marginallyclever.com/2016/05/micromouse-motors-continuous-servos/#comment-3624https://www.marginallyclever.com/2016/05/measuring-micromouse-distance-travelled-encoders/https://www.marginallyclever.com/2016/05/makelangelo-7-5-0/#comment-3703https://www.marginallyclever.com/2016/05/building-testing-micromouse-sensors/https://www.marginallyclever.com/2016/05/micromouse-motors-continuous-servos/https://www.marginallyclever.com/2016/05/measuring-micromouse-distance-travelled-encoders/https://www.marginallyclever.com/2016/05/makelangelo-7-5-0/https://www.marginallyclever.com/2016/05/micromouse-maze-solving-processing-right-hand-rule/

  • 8/16/2019 How to Control Arduino Through the Serial Monitor - Marginally Clever Robotsw to Control Arduino Through the Se…

    8/9

    Enter your email address to subscribe to this blog and receive noti䆗cations of new posts by

    email.

    Join 20 other subscribers

    Email Address

    Subscribe

    Follow Us

    Even more options

    RSS - Posts

    RSS - Comments

    More Info

    About us

    Checkout

    Contact Us

    Jobs Now Hiring

    My Account

    My Cart

    News

    Order Tracking

    Privacy

    Shop

    Support

    Terms of Service

    https://www.marginallyclever.com/terms-conditions/https://www.marginallyclever.com/support/https://www.marginallyclever.com/https://www.marginallyclever.com/privacy/https://www.marginallyclever.com/order-tracking/https://www.marginallyclever.com/news/https://www.marginallyclever.com/cart/https://www.marginallyclever.com/my-account/https://www.marginallyclever.com/job/https://www.marginallyclever.com/contact/https://www.marginallyclever.com/checkout/https://www.marginallyclever.com/about/https://www.marginallyclever.com/comments/feed/https://www.marginallyclever.com/feed/https://www.youtube.com/channel/UCfbRxqjuOgE2EzRKxcePArw/https://github.com/MarginallyClever/https://instagram.com/imakerobots/https://twitter.com/aggrav8d/https://www.facebook.com/MarginallyClever/

  • 8/16/2019 How to Control Arduino Through the Serial Monitor - Marginally Clever Robotsw to Control Arduino Through the Se…

    9/9

    Your Name (required)

    Your Email (required)

    Subject

    Your Message

    Human test

    Send

    © Marginally Clever Robots 2016

    Storefront designed by WooThemes.

    http://www.woothemes.com/