programming serial.data

This is a discussion on programming serial.data within the C Programming forums, part of the General Programming Boards category; Hi guys Have some questions here. I have an Arduino board, with multiple input sensors and output LEDs. I'm sending ...

  1. #1
    Registered User
    Join Date
    Feb 2011
    Location
    Oslo, Norway
    Posts
    5

    programming serial.data

    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.

    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 C code:
    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 sufficiently explained.

    Best,
    Andy

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Read until you hit a , and store it in a buffer. Then just:
    Code:
    sscanf( buf, "%c%*c: %d,", &letter, &number );
    That should give you your code and your value.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21