Command line arduino control

Hello, guys. This is my first post here. Great platform, great community!

I am new in arduino world, but have some programming knowledge. Normally use autoit script - basic like language for automization. And ofcourse look for the best way to connect arduino with Autoit, BUT THIS TOPIC IS NOT ABOUT AUTOIT!! :) . Serial communication is simple, but not for me :). I already establish some connection, but have an idea how to do some control simpler.

The idea is simple: command line tool - just run it with some parameters and it control the pins on arduino. I know this will never be a powerfull tool as is the arduino language, but will help a lot of people to control arduino project without any arduino programming, using their favorite language.

Some examples commands:

comduino digitalWrite 10 HIGH comduino digitalWrite A3 LOW comduino analogRead 5 comduino digitalRead 5

You see I try to keep it close to the original commands. This is a basic communication between pins on arduino and a PC. Someday may have other functionality as servo control, etc, but the close target is to get these 3 simple commands to work.

How I can see the program part: 01. command line based tool (comduino is a good name I think) - you just send parameters to the exe (sorry I am windows user, but this tool can have alternatives on other platforms too), comduino converts and send this information to arduino using serial connection. 02. Arduino code who listen the serial, get the commands and just do what they say.

If you have this combination you can just buy a board, put some sensors, leds, etc, just upload the arduino code and program everything on your favorite language.

If there is already a tool with this functionalaty - just give me a link.

I already start some work for it. You can see the Autoit code and autoit topic here: http://www.autoitscript.com/forum/topic/127431-arduino-command-line-tool/page__p__884308__fromsearch__1#entry884308 I don't expect to give me info about autoit part, ofcource.

Honestly I don't have idea how to send the variables in way that arduino to see them properly and to react.

I have some Arduino code too, but It just don't work so far :). Maybe will help you to get my point and will help me to fix it ;):

int command=2;
int pin=9;
int writebyte=1;
int pinType = 1;
int dread = 0;

void setup()
{
  Serial.begin(9600);
}
int i=0;
void loop()
{
  if (Serial.available() > 0) {
  //  incomingByte = Serial.read();
  
  
  if (command==1){
    pinMode(pin,OUTPUT);
    dread = digitalRead(pin);
    Serial.println(dread);
  };
  
    if (command==2){
    Serial.write("kur");
    pinMode(pin,INPUT);
      if (writebyte == 0) {
        digitalWrite(pin,LOW);
        Serial.print("LOW was write on pin ");
        Serial.println(pin);
      };
      
      if (writebyte == 1) {
        digitalWrite(pin,HIGH);
        Serial.print("HIGH was write on pin ");
        Serial.println(pin);
      };
    };
   
  };
  delay(1000);
};

Thank you for your attention.

Are you reinventing Firmata?

Bitlash does something like what you are describing; it might be worth a look to see if there are ideas you can steal for your project: http://bitlash.net

Bitlash is an interpreted language and serial command shell that runs entirely on Arduino. You can use it to develop and automate small applications like the ones you describe.

Normally one talks to Bitlash using the serial monitor, a terminal emulator, or a program which talks to the serial port, rather than a command line program. But it would be easy to write a little PC-side command program to take the argument text and send it to Bitlash.

Happy hacking,

-br http://bitlash.net http://entropymouse.com

I second the motion to look at Bitlash as described above.

Also consider Forth for Arduino:

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1293896012/all

-- The Gadget Shield: accelerometer, RGB LED, IR transmit/receive, speaker, microphone, light sensor, potentiometer, pushbuttons

First I suggest you experiment with your code using he seral monitor until you can send the desired strings and have the arduino do what you want it to do. Once that works, you will then probably need to defeat the arduino auto reset when the connected comport is opened. Commandline programs usually open the comport, send the serial data, then close the port. This type behavior will cause the arduino to miss the sent data as it is still resetting when the data arrives. Below is some simple test code I use that captures a string from the arduino serial port, parses the string for the desired data, converts the data to a number, and then positions servos per the data. You should be able to modify it to do most of what you want to do.

// zoomkat 11-22-10 serial servo (2) test
// for writeMicroseconds, use a value like 1500
// for IDE 0019 and later
// Powering a servo from the arduino usually DOES NOT WORK.
// two servo setup with two servo commands
// send eight character string like 15001500 or 14501550

#include <Servo.h> 
String readString, servo1, servo2;
Servo myservo1;  // create servo object to control a servo 
Servo myservo2;

void setup() {
  Serial.begin(9600);
  myservo1.attach(6);  //the pin for the servo control 
  myservo2.attach(7);
  Serial.println("servo-test-21"); // so I can keep track of what is loaded
}

void loop() {

  while (Serial.available()) {
    delay(1);  
    if (Serial.available() >0) {
      char c = Serial.read();  //gets one byte from serial buffer
      readString += c; //makes the string readString
    } 
  }

  if (readString.length() >0) {
      Serial.println(readString); //see what was received
      
      // expect a string like 07002100 containing the two servo positions      
      servo1 = readString.substring(0, 4); //get the first four characters
      servo2 = readString.substring(4, 8); //get the next four characters 
      
      Serial.println(servo1);  //print to serial monitor to see results
      Serial.println(servo2);
      
      int n1; //declare as number  
      int n2;
      
      char carray1[6]; //magic needed to convert string to a number 
      servo1.toCharArray(carray1, sizeof(carray1));
      n1 = atoi(carray1); 
      
      char carray2[6];
      servo2.toCharArray(carray2, sizeof(carray2));
      n2 = atoi(carray2); 
      
      myservo1.writeMicroseconds(n1); //set servo position 
      myservo2.writeMicroseconds(n2);
    readString="";
  } 
}

Hello guys. Thanks for your replies. I will try to figure out what is Bitlash and can I use it :). I see the firmata website - not a single exe to test. I am not sure that I try to reinvent it :) zoomkat, thank you for the code. I will try it later :).

EDIT: Bitslash is great idea! :).