B4R Code Snippet Arduino Serial Command Framework

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

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

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

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.


FilmProcessor


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.


ArduinoConsole


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

33100916625_ee8da74d8c_o_d.jpg


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.
 

Attachments

  • FilmProcesser.zip
    2.4 KB · Views: 627
  • framework.zip
    1.6 KB · Views: 632
  • ArduinoConsole.zip
    8.6 KB · Views: 677
Last edited:

mrred128

Active Member
Licensed User
Longtime 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.
 
Top