Interface Arduino w/computer w/out ArduinoSoftware

Hey,

Short question:
Is it possible to send data to the Arduino board from a computer via the USB port but without using the Arduino program but something simpler and more popular e.g. a browser or MSDOS. And if this is possible how do I go about it (preferably without any special hardware) ?

Long question (including the reason I ask):
I'm creating a prototype of a device for one of my design classes in school using the Arduino board (Duemilanove with the Atmega328) and the first time the consumer uses the device, the arduino is supposed to know his location (in terms of longitude & latitude), and the current date and time.

I was hoping this could be done using a browser (i.e. the user would choose his location from a list and the corresponding latitude & longitude would be obtained from a database; and the current date and time would be obtained directly from the computer using javascript). However, I have not been able to find any way the browser would be able to send these values to the Arduino board. Is this possible? Or is there anything else other than a browser that would work?

Thanks,
Sadiq.

Sure you can. The Arduino USB serial device maps as a simple comm port in Windows. So any simple terminal application can send and/or receive from the Arduino board. The terminal application must be selected to the correct comm port and the proper baudrate/bits/no parity/stop bits need to match the Arduino settings. In Windows hyperterminal can be used and any windows programming language that can talk to a comm port can therefore to used to create programs that can talk to a connected Arduino board.

I have no idea if any browser type application can talk to a comm port, maybe someone else knows for sure.

Lefty

My favorite Windows terminal program is putty (PuTTY: a free SSH and Telnet client). Better than hyperterm in every possible way. In particular, it is more configurable and far more stable.

Thanks for your help Lefty. I don't think I ever knew about the Hyperterminal thing but I tried it the way you advised and it seems it working (it's giving the same output as the arduino was giving in the IDE.)

But I have two problems though:

  1. Is it correct that it is the FTDI USB Drivers (that needed to be installed before using Arduino) that allow the USB port to be seen as a comm port? If that is the case, then I'd rather not use it since I would not want the final user (i.e. "consumer" in a real life situation) to have to install an extra program on his computer. Or is there no other option to use the USB the way I intend?

  2. I don't know how to use a programming language with the Hyperterminal. Could you please advice me as regards that? [I'm most comfortable with Java-type languages.]

Thanks again for your help. I really appreciate it.

Sadiq.

Thanks rocketgeek. I just noticed your message. But I'm afraid I might not able to deal with PuTTY - the site alone is putting me into confusion. Maybe I'll come back to look at it. Thanks though.

But I have two problems though:

  1. Is it correct that it is the FTDI USB Drivers (that needed to be installed before using Arduino) that allow the USB port to be seen as a comm port? If that is the case, then I'd rather not use it since I would not want the final user (i.e. "consumer" in a real life situation) to have to install an extra program on his computer. Or is there no other option to use the USB the way I intend?

  2. I don't know how to use a programming language with the Hyperterminal. Could you please advice me as regards that? [I'm most comfortable with Java-type languages.]

#1 I'm afraid you have no choice, that is the only method of communications from the Arduino to the PC via the USB port emulating a serial port.
No other option short of wiring and programming the Arduino to emulate a PS2 keyboard or parrellel port, but that is kind of ackward and takes quite a bit of Arduino code space I would think.
There is a nice windows applacation written by a contrubutor here called gobetwino that can act like an interface between the Arduino (via a comm port) and pass stuff off to other windows applications, check it out:

#2 I didn't mean use a programming language AND hyperterminal, just that if you did know how to program you could talk to a Arduino directly from a user written application if it could talk to a comm port.
Java is a programming language and I bet it has comm port capablities in some libary function or other means?

Lefty

I have no idea if any browser type application can talk to a comm port, maybe someone else knows for sure.

Under the Windows operating systems, I do not believe this is supported. With the addition of an ActiveX control, it is possible and not terribly difficult. It would require a bit of browser scripting. I think Microsoft has an ActiveX wrapper for serial ports (COMMCTRL.OCX perhaps?) that ships with the operating system.

  • Brian

The problem is that all newer computers do not have a real seria port, so without the FTDI drivers there is no way of communicating with the serial port on Arduino.

The Com port OCX control also needs a serial port, either real or virtual.

You can try this "Arduino and Java" in the Arduino: Playground

http://www.arduino.cc/playground/Interfacing/Java

Thanks a lot for your help guys. I appreciate all the responses. I decided on using gobetwino and it works quite well (thanks a lot retrolefty & MikMo!). One problem I'm having though is this:

I'm using gobetwino to go to a url at which there is a html form. When the form is filled, it creates a file and I would like gobetwino to download the file so that it can read the contents. So, to wait till the file is created, I used this:

    serInString[0]='1';
    // Wait till GoBetWino indicates that file is downloaded
    while (serInString[0]!='0') {
      Serial.println("#S|DLDATA|[]#");       
      readSerialString (serInString, 10000);  
    }

And after that I close the browser with this:

    Serial.print("#S|SENDK|[");
    Serial.print(itoa((pId), buffer, 10));
    Serial.print("&");
    Serial.print("^w");  
    Serial.println("]#");

But for some reason, it seems the while loop is exited and the browser is closed even before the file is ever created. Using a delay before the while loop works but is there a better way to solve this without using a delay?

Also, I noticed that if I open up GoBet after uploading the sketch, it doesn't restart the arduino. Could this feature be added so that it resets the arduino whenever it starts? And lastly, I think a connect/disconnect button like the one on the arduinospy would be cool too.

Thanks a lot guys,
Sadiq.

ps: I really enjoy working with the arduino, but I was wondering: does it only work well for small scale projects or is it used in manufacturing, for example, consumer devices, in the real-world?

ps: I really enjoy working with the arduino, but I was wondering: does it only work well for small scale projects or is it used in manufacturing, for example, consumer devices, in the real-world?

Explanation and Understanding through Simplification

The arduino is really a a very nice tool for teaching and as an "enabling" solution for people new to electronics. It tries real hard to make all the difficult bits about micro controller programming hide behind a curtain. It is still based a powerful off-the-shelf AVR microcontroller and does not lose anything but a little EEPROM space to the BOOTLOADER to make it ARDUINO compatible.

That said... once programmed, the chip could be removed (in some Arduino variations it's SOCKETED) and become part of a REAL WORLD device with little difficulty. Using a standard Arduino development board in a final production seems impractical but the same developed code could be used for a customized solution with it's own PCB.

No reason why not.

I think that the problem is that GoBetwino has no way of knowing what is going on after the browser is started, so i just returns "0" as soon as i has started the browser. I can't think of a better way than a delay to solve this, right now. Will think about it though.

Willard & Mik, thanks for your replies.

Mik, I'm still having some other problems working with GoBetWino, and I hope you can help me figure out whats wrong - perhaps there's something that I'm just not seeing.

Sometimes, when I use GoBet to run the code below, it does not execute the last print statement (in the getData function). And if I were to restart the arduino, it would then show the result of that statement and re-run the code. But when it re-runs the (after the restart), some errors occur: it doesn't print some lines and even if goBetWino reads the lines of the file correctly (it shows up in the output box), the readData lines in the code return an empty string or the value of a previous string . What could be wrong?

int serInLen=25;
char serInString[25], moreThanLatString[9];
char code[25], lonString[8], latString[8];
char t1String[7], t2String[5];
long timeT, timeT1, timeT2;

int pId =0;
int result;

void setup()                    // run once, when the sketch starts
{
  Serial.begin(19200);
  getData();
}

void getData(){
  delay(3000);
  char buffer[15];
  
  //wait till I start GobetWino
  delay(3000);
  Serial.flush();
  Serial.println("#S|RDCODE|[1]#");
  readData(code, 5000, 7);
  
  Serial.println("#S|INTERNET|[]#");    // start IE
  readSerialString(serInString, 5000);  // wait  5  seconds (max) for answer from Gobetwino (=porcess ID)
  pId= atoi(serInString);               // convert result to integer 
  
  //Wait for IE to start then enter a url, and go there
  delay(5000);
  Serial.print("#S|SENDK|[");
  Serial.print(itoa((pId), buffer, 10));
  Serial.print("&");
  Serial.print("http://url.com/sunfollower/products.php?code=");
  Serial.print(code);
  Serial.print(" {ENTER} ");
  Serial.println("]#");

  //wait till file is created then tell GoBetWino to download the file 
  delay(15000);  
  Serial.println("#S|DLDATA|[]#");

  //Close the IE window
  Serial.flush();
  Serial.print("#S|SENDK|[");
  Serial.print(itoa((pId), buffer, 10));
  Serial.print("&");
  Serial.print("^w");  
  Serial.println("]#");
  
  Serial.flush();
  delay(5000);
  //GoBetWino reads lines of data from the file and attempts to store them in strings
  Serial.flush();
  Serial.print("#S|RDDATA|[");
  Serial.print(itoa((1), buffer, 10));
  Serial.println("]#");
  delay(100);
  readData(moreThanLatString, 10000, 9);
  //to remove '00' which always comes before
  //the actual latString for some reason I don't know
  for (int i = 0; i < 7; i++) {
    latString[i] = moreThanLatString[i];
  }
  //readData(latString, 10000, 7);
  Serial.println(latString);
  double lat = atof(latString);
  Serial.print("Lat = ");
  Serial.println(lat);
  
  Serial.flush();
  Serial.print("#S|RDDATA|[");
  Serial.print(itoa((2), buffer, 10));
  Serial.println("]#");
  delay(100);
  readData(lonString, 10000, 7);
  delay(100);
  readData(lonString, 10000, 7);
  double lon = atof(lonString);
  Serial.print("Lon = ");
  Serial.println(lon);
  
  Serial.flush();
  Serial.print("#S|RDDATA|[");
  Serial.print(itoa((3), buffer, 10));
  Serial.println("]#");
  delay(100);
  readData(t1String, 10000, 6);
  
  Serial.flush();
  Serial.print("#S|RDDATA|[");
  Serial.print(itoa((4), buffer, 10));
  Serial.println("]#");
  delay(100);
  readData(t2String, 10000, 4);
  
  Serial.print("Time_T = ");
  Serial.println(t1String);
  Serial.println(t2String);
  timeT1 = (atol(t1String))*10000;
  timeT2 =  atol(t2String);
  timeT = timeT1 + timeT2;
  Serial.print("Time_T = ");
  Serial.println(timeT);
}


void loop() 
{ 
}

void readSerialString (char *strArray,long timeOut) {
  // Wait up to timeOut miliseconds for data to arrive at the serial port, then read the data and put it in the char array strArray
   long startTime=millis();
   int i = 0;

   while (!Serial.available()) {
      if (millis()-startTime >= timeOut) {
         return;
      }
   }
   while (Serial.available() && i < serInLen) {
      strArray[i] = Serial.read();
      i++;
   }
}

void readData (char *strArray,long timeOut, int length) {
  // Wait up to timeOut miliseconds for data to arrive at the serial port, then read the data and put it in the char array strArray
   long startTime=millis();
   int i;

   while (!Serial.available() || Serial.available() < length) {
      if (millis()-startTime >= timeOut) {
         return;
      }
   }
   if (Serial.available() > (length-1)) {
     for (i = 0; i < length; i++) {
       /* tried this so that non-zero values are read but it seems to cause an infinite loop
       while (i = 0 && Serial.read() == '0')
         ;
       */
       strArray[i] = Serial.read();
     }
   }
}

By the way, the many flushes and some of the delays were just so that the serial.read would work right.

Thanks.

I just took a quick look at your code and stumbeled over this fragment

...

Serial.flush();
Serial.print("#S|RDDATA|[");
Serial.print(itoa((2), buffer, 10));
Serial.println("]#");
delay(100);
readData(lonString, 10000, 7);
delay(100);
readData(lonString, 10000, 7);
double lon = atof(lonString);
Serial.print("Lon = ");
Serial.println(lon);

.....

Is it intentionally that you try to read the same string twice without sending anything to GoBetwino in between the 2 calls to readData?

I have a very busy day ahead of me, so i don't know when i will be online or able to do a more detaild check, but probably not before tomorrow.

Thanks MikMo. Yes, that was intentionally - perhaps, my thinking was wrong but I was assuming that it wouldn't hurt to re-read the serial line again. And it seem it worked for a while at least. But now, it doesn't seem to work. I even tried removing one of the "readData" lines but it still didn't work.