Show Posts
Pages: 1 ... 3 4 [5] 6
61  Forum 2005-2010 (read only) / Interfacing / Re: Serial string with fixed name and variable data: on: April 03, 2010, 06:21:43 pm
Dear PaulS,

I need to thank you very mutch.
Sorry for all,now the code works perfectly...

I've make some error when incorporate your portion of code..the position is important!

The sketch now work perfectly,but It don't work with java program that send to arduino the data..
I think is a issue of line terminator,now java use \n to end every command.
I've tried to substitute some \0 with \n but still don't work.
Tomorrow I will make new experiment...
What I can change to decode different command terminator?

Thank's again for all

Giorgio
62  Forum 2005-2010 (read only) / Interfacing / Re: Serial string with fixed name and variable data: on: April 03, 2010, 04:32:01 pm
I'm going crazy:
this code don't work,and HANG UP my Mac.. when I try to activate debug echo,the computer crash smiley-sad

Please,Please,Please,can you help me with a COMPLETE skecth?
I want to know where is the problem,cannot understand single row change..
please help me,thank's in advance.

This is the code

Code:
int BrakeLed=12; // pin number for led in Arduino Hardware

void setup()

{
 pinMode (BrakeLed, OUTPUT); //set pin for output (+5v)
 Serial.begin(115200); //set serial speed
}

char inData[30];
int index = 0;
char *name;
char *value;



void loop()
{ //begin loop
    
    
    while(Serial.available() > 0)
    {
       char aChar = Serial.read();

       if(index < 29)
       {
        if(aChar != '_')
     inData[index] = aChar;
  else
     inData[index] = ' ';
  index++;

          inData[index] = '\0';
       }
    }

    if(index == 25)
        {

//Serial.print("inData: [");
//Serial.print(inData);//Serial.println("]");
          
          name = strtok(inData, "=");
          value = strtok(NULL, "\0");



        index = 0;
        inData[index] = '\0';
    }
    
float valueAsNumber = atof(value);



if (strcmp(name, "wbrak") ==0)
{
 if (valueAsNumber == +000000.000000) {digitalWrite (BrakeLed, LOW);}
  if (valueAsNumber == +000001.000000) {digitalWrite (BrakeLed, HIGH);}
}

} //end loop


// string to decode
// wbrak_____=+000001.000000
63  Forum 2005-2010 (read only) / Interfacing / Re: Serial string with fixed name and variable data: on: April 03, 2010, 02:56:15 pm
Hi
I can not put a terminator char at the end of the string,
but now I have a New incoming structure of data:

Now I have:
name fixed lenght 10char
=
value composed by 6.6 char with + or -

example

name______=+000001.000000
total of fixed 25 char

I have to decode it smiley
64  Forum 2005-2010 (read only) / Interfacing / Re: Serial string with fixed name and variable data: on: April 03, 2010, 11:08:47 am
Ok but I need this code to run no in Serial Monitor,
but in a particoular enviroment: a JAR programm (written in java) send to arduino serial the data.

So I don't need a terminator or a start,right?

I want to use Serial monitor only for debug.
65  Forum 2005-2010 (read only) / Interfacing / Re: Serial string with fixed name and variable data: on: April 03, 2010, 09:49:25 am
Uhm...can you explain me?

I send gear______=1.00000 and hit enter..
The program that send the data use \n between string..so for example:


gear______=0.000000\n
wbrak_____=0.000000\n
lbrak_____=0.000000\n
66  Forum 2005-2010 (read only) / Interfacing / Re: Serial string with fixed name and variable data: on: April 03, 2010, 09:27:14 am
Ok,but now I've a not correct name/value division:
Code:
int BrakeLed=13; // pin number for led in Arduino Hardware

void setup()

{
 pinMode (BrakeLed, OUTPUT); //set pin for output (+5v)
 Serial.begin(115200); //set serial speed
}

char inData[30];
int index = 0;
char *name;
char *value;



void loop()
{ //begin loop
    
    
    while(Serial.available() > 0)
    {
       char aChar = Serial.read();

       if(index < 29)
       {
        if(aChar != '_')
            {
               inData[index] = aChar;
               index++;
            }
 
          inData[index] = '\0';
       }
    }

    if(index > 0)
        {

          Serial.print("inData: [");
Serial.print(inData);Serial.println("]");
          
          name = strtok(inData, "=");
          value = strtok(NULL, "\0");



        index = 0;
        inData[index] = '\0';
    }
    
float valueAsNumber = atof(value);

if (strcmp(name, "gear") ==0)
{
 if (valueAsNumber == 0.0) {digitalWrite (BrakeLed, LOW);}
  if (valueAsNumber == 1.0) {digitalWrite (BrakeLed, HIGH);}
}

} //end loop

return this when sending gear______=0.000000 or gear______=1.000000:

inData: [g]
inData: [ear=1.000000]
inData: [g]
inData: [ear=1.000000]
inData: [gea]
inData: [r=0.000000]

and led still not working..

67  Forum 2005-2010 (read only) / Interfacing / Re: Serial string with fixed name and variable data: on: April 03, 2010, 09:07:03 am
mmm...still not working with strange problem:

this
Code:
// X-Plane to Arduino TEST V.0001


int BrakeLed=13; // pin number for led in Arduino Hardware

void setup()

{
 pinMode (BrakeLed, OUTPUT); //set pin for output (+5v)
 Serial.begin(115200); //set serial speed
}

char inData[30];
int index = 0;
char *name;
char *value;



void loop()
{ //begin loop
    
    
    while(Serial.available() > 0)
    {
       char aChar = Serial.read();

       if(index < 29)
       {
        if(aChar != '_')
            {
               inData[index] = aChar;
               index++;
            }
 
          inData[index] = '\0';
       }
    }

    if(index > 0)
    {

          name = strtok(inData, "=");
          value = strtok(NULL, "\0");


Serial.print(name);
Serial.print(value);
        index = 0;
        inData[index] = '\0';
    }
    
float valueAsNumber = atof(value);

if (strcmp(name, "gear") ==0)
{
 if (valueAsNumber == 0.0) {digitalWrite (BrakeLed, LOW);}
  if (valueAsNumber == 1.0) {digitalWrite (BrakeLed, HIGH);}
}

} //end loop

  
  

return,if I send gear______=0.000000 in Serial Monitor

"g6ea6r606.06000006"

or "ge6ar6661.600000606" if I send gear______=1.000000
and the led is still off smiley-sad

68  Forum 2005-2010 (read only) / Interfacing / Re: Serial string with fixed name and variable data: on: April 03, 2010, 08:40:51 am
Ok,
I've writed this:
Code:
int BrakeLed=13; // pin number for led in Arduino Hardware

void setup()

{
 pinMode (BrakeLed, OUTPUT); //set pin for output (+5v)
 Serial.begin(115200); //set serial speed
}

char inData[30];
int index = 0;
char *name;
char *value;



void loop()
{ //begin loop
    
    
    while(Serial.available() > 0)
    {
       char aChar = Serial.read();

       if(index < 29)
       {
        if(aChar != '_')
            {
               inData[index] = aChar;
               index++;
            }
 
          inData[index] = '\0';
       }
    }

    if(index > 0)
    {

          name = strtok(inData, "=");
          value = strtok(NULL, "\0");

        index = 0;
        inData[index] = '\0';
    }
    
Serial.println(name); //debug only
Serial.println(value); //debug only

if (strcmp(name, "gear") ==0)
{
 if (valueAsNumber == 0.0) {digitalWrite (BrakeLed, LOW)}
  if (valueAsNumber == 1.0) {digitalWrite (BrakeLed, HIGH)}
}

} //end loop
  
  

But when tryng to compile I receive this error:

error: 'valueAsNumber' was not declared in this scope

and also this Serial.print for debug are not working..
Code:
Serial.println(name); //debug only
Serial.println(value); //debug only

Where is the problem?


Thank's againg!


69  Forum 2005-2010 (read only) / Interfacing / Re: Serial string with fixed name and variable data: on: April 03, 2010, 05:38:46 am
Thank's for fast reply:

I'm newbie in programming:

When I have build char by char the name and value string,what I have to do to manage it?
I don't know what I have to do for use ATOF function..

With fixed lenght string I use this code,and it work for "name" but not for value..


Code:
if (strcmp(inData, "gear______") ==0)
{
if (strcmp(inData, "0.0") ==0) {digitalWrite (GearLed, LOW)}
if (strcmp(inData, "1.0") ==0) {digitalWrite (GearLed, HIGH)}
}





and another question..is possible automatically delete the "_" when building string?
In this mode my string is if (strcmp(inData, "gear") ==0)  and not if (strcmp(inData, "gear______") ==0)

Thank's!!

Giorgio

70  Forum 2005-2010 (read only) / Interfacing / Serial string with fixed name and variable data: on: April 02, 2010, 05:39:05 pm
Hi,

I need to receive string in the serial port of arduino,
and the string is composed like this:

name___=value

for example:

vindkias__=294.287048
vindkeas__=297.044189
vtruektas_=313.840454
vtruektgs_=313.794830
vindmph___=338.659485
vtruemphas=361.161133
vtruemphgs=361.108643
mach______=0.489340
vvi_______=2239.381836
gloadnorma=1.138424
gloadaxial=0.117916
gloadside_=0.020181
gear______=0.000000
wbrak_____=0.000000
lbrak_____=0.000000
rbrak_____=0.000000

the name is 10 chars fixed,then "=" and then a not fixed value.

I receive this feed many times in a second,and I have to decode some data,
for example if GEAR=1 I have to turn on a led,if GEAR=0 I need to turn off it,

But in the future I need to print on a LCD display the value of vindkias string,like "VINDKIAS:294,28"

Can anyone help me?

71  Forum 2005-2010 (read only) / Italiano / Prime Armi.. Dati su Rs485 on: March 06, 2009, 03:39:47 pm
Salve a tutti,
devo ancora acquistare le mie prime schede,
e proprio per questo approfitto della vostra gentilezza per chiedere se è possibile fare quanto segue.

Avrei la necessità di pilotare da 1 a 10 relais mediante Arduino,
interpretando dei semplici comandi ricevuti su una RS485.

In buona sostanza,avrei la necessità che Arduino,ricevuto un comando tipo "P11" sulla seriale 485 accendesse e tenesse acceso il relais 1,una volta ricevuto il comando P10 lo spegnesse,stessa cosa con i comandi P21 e P20 per il relais 2 e cosi via...

E' facilmente fattibile con Arduino?
E' fattibile anche da un principiante?
Sareste anche magari così gentili da indicarmi quale hardware acquistare?

grazie infinite a tutti,

Giorgio
72  Forum 2005-2010 (read only) / Italiano / Re: Semplice buffer seriale on: March 12, 2009, 06:17:01 pm
Così come gentilmente mi suggerisci mi da alcuni oscuri errori in fase di compilazione.
Devo ancora studiare e apprendere bene la sintassi e la struttura del linguaggio:




Code:
#char val;
char val[3];

int ledPin0 = 13;    // LED connected to the Wiring I/O board pin0
int ledPin1 = 12;    // LED connected to the Wiring I/O board pin1
int ledPin2 = 11;    // LED connected to the Wiring I/O board pin2
void setup()
{
  pinMode(ledPin0, OUTPUT); // sets the digital pin as output
  pinMode(ledPin1, OUTPUT); // sets the digital pin as output
  pinMode(ledPin2, OUTPUT); // sets the digital pin as output
  Serial.begin(9600);       // opens the serial port
}

void off()
{
  // sets all LEDs off
  digitalWrite(ledPin0, LOW);
  digitalWrite(ledPin1, LOW);
  digitalWrite(ledPin2, LOW);
  Serial.println("All off");
}

void on()
{
  // sets all LEDs on
  digitalWrite(ledPin0, HIGH);
  digitalWrite(ledPin1, HIGH);
  digitalWrite(ledPin2, HIGH);
  Serial.println("All on");
}

void loop() {

  if(Serial.available() > 0) {

  #val = Serial.read();
val[0] = Serial.read();
val[1] = Serial.read();
val[2] = Serial.read();

    if(val == 'F11'){
      digitalWrite(ledPin0, HIGH);  // sets the LED on
      Serial.println("LED 0 on");   // sends:on
    }
    else if(val == 'F10'){
      digitalWrite(ledPin0, LOW);   // sets the LED off
      Serial.println("LED 0 off");  // sends:off
    }
    else if(val == '3'){
      digitalWrite(ledPin1, HIGH);  // sets the LED on
      Serial.println("LED 1 on");   // sends:off
    }
    else if(val == '4'){
      digitalWrite(ledPin1, LOW);   // sets the LED off
      Serial.println("LED 1 off");  // sends:off
    }
    else if(val == '5'){
      digitalWrite(ledPin2, HIGH); // sets the LED on
      Serial.println("LED 2 on");  // sends:off
    }
    else if(val == '6'){
      digitalWrite(ledPin2, LOW);  // sets the LED off
      Serial.println("LED 2 off"); // sends:off
    }
    else if(val == 'o'){
      on();
    }
    else if(val == 'x')
    {
      off();
    }

  }
  delay(100); // wait 100ms for next reading
}

73  Forum 2005-2010 (read only) / Italiano / Semplice buffer seriale on: March 12, 2009, 02:22:49 pm
Ciao a tutti,
 con questo semplice codice,faccio accendere e spegnere i led inviando un carattere  alla seriale.

Avrei la necessità di creare un buffer di lettura della seriale per strutturare meglio il comando,
anzichè inviare "1" avrei la necessità di inviare 3 caratteri ovvero A01

qualcuno mi spiega come costruire il buffer di lettura?

grazie!

Code:
char val;
int ledPin0 = 13;    // LED connected to the Wiring I/O board pin0
int ledPin1 = 12;    // LED connected to the Wiring I/O board pin1
int ledPin2 = 11;    // LED connected to the Wiring I/O board pin2
void setup()
{
  pinMode(ledPin0, OUTPUT); // sets the digital pin as output
  pinMode(ledPin1, OUTPUT); // sets the digital pin as output
  pinMode(ledPin2, OUTPUT); // sets the digital pin as output
  Serial.begin(9600);       // opens the serial port
}

void off()
{
  // sets all LEDs off
  digitalWrite(ledPin0, LOW);
  digitalWrite(ledPin1, LOW);      
  digitalWrite(ledPin2, LOW);    
  Serial.println("All off");
}

void on()
{
  // sets all LEDs on
  digitalWrite(ledPin0, HIGH);
  digitalWrite(ledPin1, HIGH);      
  digitalWrite(ledPin2, HIGH);    
  Serial.println("All on");
}

void loop() {

  if(Serial.available() > 0) {  

    val = Serial.read();

    if(val == '1'){
      digitalWrite(ledPin0, HIGH);  // sets the LED on
      Serial.println("LED 0 on");   // sends:on
    }
    else if(val == '2'){
      digitalWrite(ledPin0, LOW);   // sets the LED off
      Serial.println("LED 0 off");  // sends:off
    }
    else if(val == '3'){
      digitalWrite(ledPin1, HIGH);  // sets the LED on
      Serial.println("LED 1 on");   // sends:off
    }
    else if(val == '4'){
      digitalWrite(ledPin1, LOW);   // sets the LED off
      Serial.println("LED 1 off");  // sends:off
    }
    else if(val == '5'){
      digitalWrite(ledPin2, HIGH); // sets the LED on
      Serial.println("LED 2 on");  // sends:off
    }
    else if(val == '6'){
      digitalWrite(ledPin2, LOW);  // sets the LED off
      Serial.println("LED 2 off"); // sends:off
    }
    else if(val == 'o'){
      on();
    }
    else if(val == 'x')
    {
      off();
    }

  }
  delay(100); // wait 100ms for next reading
}

74  Forum 2005-2010 (read only) / Interfacing / Re: works: MIDI-IN: code + schematics on: April 02, 2009, 05:36:02 pm
tetracon,
your code seems to work,but I need some things:

I need 3 separate leds for 3 program change,and when is active the program 20 is active the ONLY led1,when active the program 21 is ONLY active the led2,and obviousily the PC22 activate only led3.

When I'm using Control Change,I need to activate it with CC36,and DEACTIVATE with CC36 (or for example CC00)


Is complicated do this?
Thank's in advance,

Giorgio


75  Forum 2005-2010 (read only) / Interfacing / Re: works: MIDI-IN: code + schematics on: April 02, 2009, 12:02:07 pm
Thank'you very mutch,this night I try all and reply this.

Giorgio
Pages: 1 ... 3 4 [5] 6