Loading...
Pages: [1]   Go Down
Author Topic: serial comunication  (Read 204 times)
0 Members and 1 Guest are viewing this topic.
indonesia
Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi guys,...
Would u help me?
I looking for a way to make my arduino-uno can received many variables from PC. smiley-cool

Exactly I have a project that requires sending data (variables) from Delphi output to arduino, and process it on arduino. smiley-roll-sweat
probably 10 variables.

Please help me.......
Logged

Global Moderator
UK
Online Online
Brattain Member
*****
Karma: 143
Posts: 19368
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

And how are these variables formatted?
Logged

Pete, it's a fool looks for logic in the chambers of the human heart.

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

it's all  parameters..
example

VS 2000
its mean VS(Viscosity standard) have a value 2000 smiley-twist
Logged

California
Offline Offline
Edison Member
*
Karma: 51
Posts: 2175
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What do you have so far?
Logged

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

i'm sorry... So far i try to use gobetwino, but i confused with the syntax. and its really complicated for me smiley-roll-sweat
Logged

Global Moderator
UK
Online Online
Brattain Member
*****
Karma: 143
Posts: 19368
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you worked through any of the supplied examples?
Logged

Pete, it's a fool looks for logic in the chambers of the human heart.

Queens, New York
Offline Offline
Edison Member
*
Karma: 31
Posts: 1730
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Arduino does not have a split function like Processing does, SO, you need to make your own split function.
Here is something I made to help me. this will take in 3 values and change them to ints.
Code:
#include<string.h>
int X,Y,State,currentCommand=0;
String x,y,state;


// LED connected to pin 13 (on-board LED)
byte ledpin = 13;

void setup()
{
  pinMode(ledpin, OUTPUT);
  Serial.begin(9600);       // start serial communication at 9600bps
}

void loop() {
  if( Serial.available())       // if data is available to read
  {
    digitalWrite(ledpin, HIGH); //if data is being entered
    char val= Serial.read();
    if (val == ','){
      currentCommand++;
    }
    else {
      switch (currentCommand) { //add more case statements for more data
      case 0:
        x += val; //stores as a string
        val = ' '; //clear for new char
        break;
      case 1:    
        y += val; //stores as a string
        val = ' ';
        break;
      case 2:    //gets the last data
        state += val; //stores as a string
        val = ' ';
        currentCommand = 0; // this only allows one char to be saved here, modify to save more.
        X=x.toInt();               //delete .toInt() if needed
        Y=y.toInt();               //delete .toInt() if needed
        State = state.toInt(); //delete .toInt() if needed
        //shows what you entered
        Serial.print(X);
        Serial.print(", ");
        Serial.print(Y);
        Serial.print(", ");
        Serial.println(State);
        
        x="";y="";state=""; //clear values
        X=0;Y=0;State=0; //clear values
        break;
      }
    }  
  }
  digitalWrite(ledpin, LOW);
}

Hope this is able to get you started.

Moderator edit: CODE TAGS dammit.
« Last Edit: November 13, 2012, 12:40:39 pm by AWOL » Logged

UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W

"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown

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

Yes... But
it doesnt work correctly. And i can't trace the error because i confused with the sintax.
maybe someone can help me with the other ways?
Logged

Global Moderator
UK
Online Online
Brattain Member
*****
Karma: 143
Posts: 19368
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
i can't trace the error
First mention of an error.
Care to expand?
Logged

Pete, it's a fool looks for logic in the chambers of the human heart.

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

thanks a lot HazardsMind smiley-kitty smiley-kitty....
It really helps me:)
Logged

Offline Offline
Jr. Member
**
Karma: 1
Posts: 83
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes... But it doesnt work correctly. And i can't trace the error because i confused with the sintax.
maybe someone can help me with the other ways?
Maybe you can tell us (1) what you're doing already (i.e., show us your code), (2) what you expect it to do, (3) what it's actually doing, and (4) what errors you're getting?
Logged

Pages: [1]   Go Up
Print
 
Jump to: