Show Posts
Pages: 1 2 [3] 4
31  Using Arduino / Programming Questions / Re: programming serial.data on: February 21, 2011, 05:34:12 am
Hi PaulS.
Ok, I've done something wrong here. I think I used char cause I use this code to split:
Code:
      remove(serInString, ' ');     
      char * token = strtok(serInString, ",");
     
      int i = 0;
      while(token){              // Do something with this word

      Serial.print(token);       // print as an ASCII-encoded decimal
      Serial.print(", ");
      // Lengden av stringe strlen (token).
     
      token = strtok(NULL, ",");
      i +=1;
      //Serial.print(", ");
      }

void remove(char *str, char r){
  char *p, *q;
  p = q = str;
 
  while (*p != '\0')
  {
    while (*p == r) p++;
    *q++ = *p++;
  }
  *q = '\0';
}

Do you have a tip of solving this problem of mine?
32  Using Arduino / Programming Questions / Re: programming serial.data on: February 21, 2011, 04:47:06 am
Hi robtillaart.
From my arduino, I send data like this, "s1: value, s2: value, d1: value, d2: value, etc..." where s: is analog input, and d: is digital input.
And since I wanna send setpoint such as "k1: 255, w1: 1, z1: time, etc..." where k: is a "analog" value and w: is high/low value.

The problem is when I receive data from my computer. Then I don't know how to split my data, to determ what is what.
Cause since I have various data sending, I need to split my data, find the first letter in the array, then remove the space between letters and remove the 3 first letters so I only have my values.
In vb this is the code:
Code:
        For i = 0 To UBound(aryTextFile)
            Dim countTextChar(i) As Integer
            Dim myLeft(i) As String
            Dim myInput(i) As String
            Dim myText(i) As String

            countTextChar(i) = Len(aryTextFile(i))                          ' count letters in array
            myInput(i) = Microsoft.VisualBasic.Left(aryTextFile(i), 1) ' find the first letter
            myLeft(i) = Microsoft.VisualBasic.Left(aryTextFile(i), 3)  ' find the 3 first letters

            If myInput(i) = "s" Then
                If myLeft(i) = "s1:" Then
                    myText(i) = Replace(aryTextFile(i), myLeft(i), "")
                    s1.Text = myText(i) & TempPrefix
                End If

                'And here comes the rest of the values you want to display in form.

            End If
        Next i

arduino:
Code:
void readSerialString () {
    char sb;   
    if(Serial.available()) {
       //Serial.print("reading Serial String: ");     //optional confirmation
       while (Serial.available()){
          sb = Serial.read();
         
          serInString[serInIndx] = sb;
          serInIndx++;
          //Serial.println(sb);                        //optional confirmation
       }
       //Serial.println(sb);
    } 
}

So this is my problem. I cant figure out how to determ what kind of data I recieve, and use this data later in arduino program.
Hope this was more explanatory.

Best,
Andy
33  Using Arduino / Programming Questions / programming serial.data on: February 20, 2011, 03:25:07 pm
Hi guys
Have some questions here. I have an Arduino board, with multiple input sensors and output LEDs.
I'm sending data every 30 seconds to a visual basic 2010 program. In this program,  I will also send signals to the Arduino board to turn on the LED light, and dimming them.

My question is then:
What is the best way to send data?
And how should I treat the signal in the Arduino side.
This is what I have:
Code:

   if(serInIndx > 0){
      //Serial.print("You said: ");     
     
      //loop through all bytes in the array and print them out
      for(serOutIndx=0; serOutIndx < serInIndx; serOutIndx++){
        Serial.print(serInString[serOutIndx]);    //print out the byte at the specified index
        //serInString[serOutIndx] = "";            //optional: flush out the content
      }
     
      //reset all the functions to be able to fill the string back with content
      serOutIndx = 0;
      serInIndx  = 0;
      //serInString er texten i serial data!
     
      remove(serInString, ' ');     
      char * token = strtok(serInString, ",");
     
      int i = 0;
      while(token){              // Do something with this word

      Serial.print(token);       // print as an ASCII-encoded decimal
      Serial.print(", ");
      // Lengden av stringe strlen (token).
     
      token = strtok(NULL, ",");
      i +=1;
      //Serial.print(", ");
      }
   }


Best,
Andy
34  Using Arduino / Programming Questions / Re: replace() on: February 08, 2011, 12:53:28 pm
Sweet robtillaart.
Thanks for your help smiley
It works!

Now I'm just implent in my own code...

-Andy
35  Using Arduino / Programming Questions / Re: PLC freeze on: February 08, 2011, 11:11:22 am
U have a goto():?
36  Using Arduino / Programming Questions / replace() on: February 08, 2011, 11:09:09 am
Hi.
I have this project where I use split() and replace().
Now I have a bad feeling that I can't use char* split() and replace() togehter.

code:
Code:
#include <string.h>

void setup() {
  Serial.begin(19200);
}

void loop(){
char test[] = "s1: 22, s2: 43, s3: 12, s4: 56";
test = test.replace(' ', '');
char *token = strtok(test, ",");
int i = 1;

while(token)
{  // Do something with this word
Serial.print(token);
Serial.println();
token = strtok(NULL, ",");
i +=1;
}
Serial.println();
delay(1000);
}

Cause I get this error message:
split:8: error: request for member 'replace' in 'test', which is of non-class type 'char [31]'

Anny way to solve this?

-Andy
37  Using Arduino / Programming Questions / Re: split serial communication on: February 05, 2011, 01:24:11 pm
Hi zoomkat.
Thanks for your tip. I'll try to work this out. I think I need a array or something between this:
Code:
    if (c == ',') {
      break;
    }

Or?

Best,
Andy
38  Using Arduino / Programming Questions / Re: split serial communication on: February 05, 2011, 01:11:27 pm
Hi again Graynomad.  smiley-razz
For now I only have my arduino. Connected to Arduino, there is now 2 sensors(input), and one red diode(output).
I made a visual basic winForm program, talking to Arduino with serialport.
There I have 2 TextBox'es showing temperature value(sensor1: 22, sensor2: 4,), RichTextBox showing serial data, and one TrackBar that gives value 0-255 for the sharpness of red diode.(led1: 255,)
Later in my project I'll have more nodes. Therefor it's best to split the serial string, like html Request.QueryString.
So I could just grab what I want...

I hope this was more explanatory.

Best,
Andy  smiley-grin
39  Using Arduino / Programming Questions / Re: split serial communication on: February 05, 2011, 10:30:21 am
Hi Graynomad.
Currently now, I'm trying to build a home automation system. I've been working with PLC systems for many year, and now I'm trying to make my own system.

The deal is I want a main "arduino" that works as a base station. Connected to the arduino, there is (input) Temperature sensors, movement sensors and door sensors. (output) lights, Panel Heater...
And these Nodes will be talking to arduino wierlessly.
So I'll get a hole bunch of data in serialport. And when I get the data I'll prosess them.

Best,
Andy
40  Using Arduino / Programming Questions / split() on: February 05, 2011, 08:01:23 am
Hi guys.
I'm trying desperately to figure this out.
In Visual Basic I use split() function. In C there is none!

Or is it?

VB.net code
Code:

        Dim txtData As String = SerialPort1.ReadLine

        RichTextBox1.Text = txtData

        Dim myFile As String = txtData
        myFile = Replace(myFile, " ", "")

        Dim i As Integer
        Dim aryTextFile() As String
        aryTextFile = myFile.Split(",")

        'Sett inn sensorene her
        For i = 0 To UBound(aryTextFile)
            MsgBox(i)
        Next i


How could I do this in C?

Best,
Andy
41  Using Arduino / Programming Questions / Re: split serial communication on: February 05, 2011, 06:51:19 am
Hi Graynomad.
The values I send, I need to threat. So if I just send values like "243,23,124 ", the program don't know what thees values are for...
Therefor I need to split the value "led1=243, led2=23, led3=124,..." from ",".
Then I store values in arrays[] so I could get values like:

"led1=243"
"led2=23"
"led3=124"

Then I have my values...
42  Using Arduino / Programming Questions / split serial communication on: February 04, 2011, 08:09:11 pm
Hi.
I have a project with a arduino duemilanove.
Here I got 2 sensors (Thermistors) and one led.
Also I have a Visual Basic program I made for this, and I wish to be able to have a 2-way communication between PC and Arduino.
I get the sensor values on the PC, but when I'm gonna take values from PC to arduino, I need to split the values from PC.
Example:
I have a TrackBar giving a value between 0 and 255. The name is led1.
PC writes "SerialPort1.Write = ("led1=" & TrackBar1.Value & ",")" and much more to arduino.
In arduino I need to "pick" the value from led1 and treat the code. Therefor I need to split Serial.read();.
So I split the whole code I get from serial read which can be:
"led1=243, led2=23, led3=124," after ",".

Here is my problem.
I cant get anny split functions to work!

Annyone please help ME!!!  

Best,
Andy
43  Forum 2005-2010 (read only) / Interfacing / Re: visual basic serial communication on: January 19, 2011, 12:11:23 pm
Thanks Rob.
Now I've got some code to work.
Each time I push the buttom, I'll get some temp value  smiley-grin

Next I'll try to get the temp to show from startup and update in a periode of 30sec.

Again Rob. Thank you for helping me   smiley
44  Forum 2005-2010 (read only) / Interfacing / Re: visual basic serial communication on: January 19, 2011, 11:21:34 am
Hi Graynomad
What I mean, is when I use arduino compiler and hit serial monitor, I get the temperature.

But when I ran the code you posted, I got some value from temp now. But the value from temp didn't change when I put heat on it.

If I understand it right, when I program arduino like "Serial.print"
This is what it sends to serial port?

Is there a way in VB to take spesific code from serial signal.
Like in this code I use one sensor sending value to VB.
If I had several sensors, like sensor 1-sensor6 could I split the code so I could place the value where I need it, and how?

Back to question.

The temp sensor I have, I'd like to show in a TextBox. Refreshing every 20 sec.
In my code showed above, how can I do this?

Best,
-Andy  smiley
45  Forum 2005-2010 (read only) / Interfacing / Re: visual basic serial communication on: January 19, 2011, 10:35:18 am
Hi Graynomad.
I get the value when I use serial command in Arduino compiler.
The serialport I use is com6.

Its just the Rx I don't get...   :-[
Pages: 1 2 [3] 4