Pages: [1] 2   Go Down
Author Topic: Interfacing Arduino with PC (2-way communication)  (Read 2621 times)
0 Members and 1 Guest are viewing this topic.
Ohio, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I am looking to interface an Arduino unit with a computer over a network socket bridged to a serial port (Via linksys wifi router and DDWRT) in hopes of remote controlling a robot. Problem is, I want to do most of the processing on the Arduino end (I know I'm crazy smiley ) so that I can still hook up a wired controller for preliminary testing and for PC-free use. I also want to be able to send sensor data back to the PC from the Arduino smiley-eek. I would like to use visual basic since the robot is the majority of my project, not the programming on the PC end. I am kinda clueless where to start smiley-cry so any advice would be great. smiley-mr-green
Thanks everyone!
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I would like to use visual basic
I don't understand that, but, you are welcome to use it.

Quote
I am looking to interface an Arduino unit with a computer over a network socket bridged to a serial port (Via linksys wifi router and DDWRT)
The Arduino won't care what is on the other end of the serial port. However, adding 22 layers of complexity to an already challenging project is hardly the recommended path to success, especially in light of this:
Quote
not the programming on the PC end.
I am kinda clueless where to start

Quote
so any advice would be great.
Start simple. Connect the Arduino directly to the PC.



Logged

Ohio, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The whole reason for visual basic is because I know what I am doing in there, but if there is a better programming language to use, please let me know.
Is there a prebuilt protocol for interfacing a Arduino to some easier programming languages? I looked at firmata and it seemed attractive, but I really don't wanna try to learn a new programming language unless its REALLY user friendly. I want to be able to click things in a GUI and have the robot do what you tell it to. To me, the serial communication seems kind of confusing.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I want to be able to click things in a GUI and have the robot do what you tell it to.
If you are clicking in a GUI, and the robot does what I tell it to, won't that be confusing?

Quote
but if there is a better programming language to use, please let me know.
Well, I like C# for defining interfaces and the ease of communicating with the serial port. Getting data from the serial port displayed back in the GUI can be a little challenging, given the need to use multiple threads and get the threads to communicate, but once you get it all worked out (I did, send me a PM if interested in the sample program) it becomes transparent to the operation of the program.

Code:
I looked at firmata and it seemed attractive, but I really don't wanna try to learn a new programming language
Firmata isn't a programming language, isn't supported for the Arduino (it's available, but there is no support), and is somewhat limiting in that there is a servo sketch, a standard sketch, etc., but no one do-it-all sketch like you could write.

Quote
To me, the serial communication seems kind of confusing.
I don't see why. Think of it like posting on this forum. It takes a while to type a message (send some data). It may or may not actually get to the server (it may get lost). It may, or may not, actually get read (reading it is your responsibility), and it may, or may, not be easy to understand and implement the suggestions being made.

But, since you are controlling both the sender and the receiver, it can be quite rewarding to develop a protocol that both ends can understand, and get them to actually play well together.
Logged

Ohio, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I want to be able to click things in a GUI and have the robot do what you tell it to.
If you are clicking in a GUI, and the robot does what I tell it to, won't that be confusing?
Now I know who to yell at if I click forward and it goes backwards  smiley-razz

Quote
Quote
To me, the serial communication seems kind of confusing.
I don't see why. Think of it like posting on this forum. It takes a while to type a message (send some data). It may or may not actually get to the server (it may get lost). It may, or may not, actually get read (reading it is your responsibility), and it may, or may, not be easy to understand and implement the suggestions being made.

But, since you are controlling both the sender and the receiver, it can be quite rewarding to develop a protocol that both ends can understand, and get them to actually play well together.
What I see as confusing is the whole read one character at a time. The important part right now is that I need to figure out how to get the data to the Arduino. I can slowly work on phasing the rest of it in.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
What I see as confusing is the whole read one character at a time.
Isn't that how everyone reads?
Logged

Ohio, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
What I see as confusing is the whole read one character at a time.
Isn't that how everyone reads?
I guess it would be... I really need to watch what I say. I meant that I would like it to just read a whole string out of the serial buffer at once so that I can work with it.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I meant that I would like it to just read a whole string out of the serial buffer at once so that I can work with it.
There are a number of new methods in the Serial (Stream) class with 1.0. But, they basically read one character at a time.

The trickiest part of "just read a whole string" at once is defining what constitutes a packet.

With anything else we read, punctuation is important. For instance, we know that there are different packets in the stuff we read, called words, and packets called sentences, and packets called paragraphs, and packets called chapters, and packets called books.

If you read the data, yourself, one character at a time, you can recognize the various end-of-packet markers yourself, and take appropriate action when they arrive.

If you have a specific definition of a packet, run it by us for comment, and help writing code to read that packet, one character at a time, and to make use of that packet contents.
Logged

Ohio, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
If you have a specific definition of a packet, run it by us for comment, and help writing code to read that packet, one character at a time, and to make use of that packet contents.
To me a serial data packet would be the variable and the value to set it to. What would be the best start/end of packet marker?

Would it be easier for the PC to tell the Arduino it needs data from a sensor then have the Arduino send it, or to just have the Arduino send it every time a command is received and processed?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
What would be the best start/end of packet marker?
I don't know about best, but I use < and >, and this code to read the serial data.
 
Code:
#define SOP '<'
#define EOP '>'

bool started = false;
bool ended = false;

char inData[80];
byte index;

void setup()
{
   Serial.begin(57600);
   // Other stuff...
}

void loop()
{
  // Read all serial data available, as fast as possible
  while(Serial.available() > 0)
  {
    char inChar = Serial.read();
    if(inChar == SOP)
    {
       index = 0;
       inData[index] = '\0';
       started = true;
       ended = false;
    }
    else if(inChar == EOP)
    {
       ended = true;
       break;
    }
    else
    {
      if(index < 79)
      {
        inData[index] = inChar;
        index++;
        inData[index] = '\0';
      }
    }
  }

  // We are here either because all pending serial
  // data has been read OR because an end of
  // packet marker arrived. Which is it?
  if(started && ended)
  {
    // The end of packet marker arrived. Process the packet

    // Reset for the next packet
    started = false;
    ended = false;
    index = 0;
    inData[index] = '\0';
  }
}
Where it says "Process the packet", you can deal with the name = value data.

Quote
Would it be easier for the PC to tell the Arduino it needs data from a sensor then have the Arduino send it, or to just have the Arduino send it every time a command is received and processed?
It would be easiest, but not necessarily best, to have the Arduino send a response after every command.
Logged

Ohio, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
It would be easiest, but not necessarily best, to have the Arduino send a response after every command.
I need to keep latency down so that this will be pretty close to realtime, because with 2 3000w motors on a 25lb contaption, it could get moving pretty fast. I also will be running an if statement with a few mathematical equations thrown in there, because I need to vary the range of differential drive turning depending upon the forward speed so I don't throw tracks or flip the thing smiley-eek.
Would that method of sending sensor data cause any noticeable slowdown?
Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
What I see as confusing is the whole read one character at a time.
Isn't that how everyone reads?

Actually no. I believe that the prevailing model is still that most people (certainly in the English and European based languages) read a word (or more) at a time, based on the 'shape' of the words.
« Last Edit: February 12, 2012, 07:14:43 am by dxw00d » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have a similar problem to solve. I need an application to be able to do things like check for Arduino connected through ethernet and determine their IP address. I also need to be able to update their IP address from the application.

The next task would be to change some PWM channel values and display some general information to the user about the device (status, etc..).

Serial would be nice, but I may end up going with ethernet only and using UDP (?). One thought is to send UDP packets to update the controller.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I need an application to be able to do things like check for Arduino connected through ethernet and determine their IP address.
If your PC is acting as a server, your server software should have tools to manage that. Apache does, for instance.

Quote
I also need to be able to update their IP address from the application.
Good luck with that. The server gets a request, and servers up a response. Then, the connection is closed. Until the client connects again. A server can not initiate communication with a client.

Quote
The next task would be to change some PWM channel values and display some general information to the user about the device (status, etc..).
You can supply new values when a client requests them. You can not push new values to a client.

Quote
Serial would be nice, but I may end up going with ethernet only and using UDP (?). One thought is to send UDP packets to update the controller.
Everything up to this point assumed that the Arduino-as-client was connecting via ethernet...
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hello.

i just want some advice/help  smiley

my project is about sending data from pc-xbee(Tx)-xbee(Rx)-fan. in simple words, i just want to switch on/off the fan.. however, i find it very hard to start but i think http://tutorial.cytron.com.my/2011/08/13/project-14-wireless-temperature-logging/ was a very good tutorial for my project right ??

i have ..

2 Arduino Duemilanove(Compatible)-Main Board
2 Arduino-XBee Shield (without module)
2 XBee 1mW Wire Antenna - Series 2

can i use this tutorial http://antipastohw.blogspot.com/2009/01/xbee-shield-to-xbee-shield.html to make my xbee communicate to each other first?? if not, can someone help to link other tutorial (similar to my project)?? please teach me... thanx~
Logged

Pages: [1] 2   Go Up
Jump to: