B4R Code Snippet Arduino Serial Command Framework

Discussion in 'B4R Code Snippets' started by mrred128, Feb 25, 2017.

  1. mrred128

    mrred128 Active Member Licensed User

    This framework simplifies serial interfacing via a command / response infrastructure. My Arduino projects are usually purely gadget interfaces linked to a higher functioning PC/ORDROID/Android device to actually do the orchestration. There is a built in method to identify the board via an ID and physically by blinking an on board led (pin 13).

    Basic commands:

    All commands implemented in lower case.


    id 1234

    By itself, will give you the id written in the first 2 bytes of the eeprom. With an argument, it will assign the id (16bit uint) to that board.

    In a multi-board implementation, this is the ideal way to identify which controller you are communicating with. This alleviates the issue of re-assigned com port assignments on the OS side.


    blink on

    blink off

    By itself, gives the status (on or off) of the blink function. Otherwise it turns it on or off.

    Blinking is approximately 300ms. This function is to physically identify the board.


    sync YourOwnSyncString

    “sync” produces “00 sync” in the output and “sync lalala” produces “00 lalala”.

    This puts a sync stamp on the output. It is helpful at times to find the last place of your output. The supplied ArduinoConsole uses sync to skip startup messages.

    That is all the built in commands. In the Astream_NewData sub, you can add your own commands to the select statement.

    The command line is parsed for up to 10 arguments. You can change the amount to suit your needs. The variables argc and args(x) are their respective storage.


    This is a real module from a film development processor I am developing. It uses the stock motor shield and drives two standard low torque motors (12v) and gives my PC or Tablet all the necessary control over agitation. The project has other modules (uno) tasked with other functions.

    There is no rocket science involved and the source code should answer your questions. It should be re-usable for any of your own projects involving this shield.


    Inspired by Erel's code, this console is geared for command / response operation.


    The COMx & OPEN/CLOSE buttons are strait forward. The IDE selection determines if the console responds to IDE requests to share the com port. The Sync selection uses the sync function to skip all startup messages and just give an OK message when ready.

    The “Command” box submits the type command when return is pressed. No need for a “Send” button. The main response area is automatically cleared on every command.

    The project is included here FYI.

    Attached Files:

    Last edited: Feb 25, 2017
  2. mrred128

    mrred128 Active Member Licensed User

    ArduinoConsole had a bug and has been updated. If you had more than one console open for multiple boards, on reopen of the intended shared port, it would trigger all consoles to reopen.
  3. victormedranop

    victormedranop Active Member Licensed User

    Amazing WORK !!!!!!!!!!!! :eek::oops::)

    mrred128 likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice