@mohamad_ir (Mohamad Ir) posted a new topic, subject "Send recive data separated by comma". It read:

   String read;  
    String write;  
    void setup() {  
    Serial.begin(9600);  
    }
    
    void loop()  
    {  
    while(Serial.available()){  
    read= Serial.readString();  
    write= Serial.writeString();
    
    }  
    }
    
    how i can recive data?  
    example my data is :  
    a,b,c  
    a and b and c is number from 0 to 9999  
    a and b and c after recived put into variable:  
    sensor1=a  
    sensor2=b  
    sensor3=c
    
    how i can send data?  
    example my data is :  
    a,b,c  
    a and b and c is number from 0 to 9999  
    a and b and c must sended by serial  
    sensor1=a  
    sensor2=b  
    sensor3=c

To which @StefanL38 (Stefan Ludwig) replied

    hi mohammad,
    
    welcome to the arduino-forum.  
    For a small demo-code that shows the principle additional information is needed  
    at what baudrate is the data sended?  
    is there some kind of endmarker that is added after the number?
    
    What device is sending the data?  
    another arduino?  
    a computer?
    
    best thing would be if you could post a real example of the data
    
    best regards  
    Stefan

@J-M-L (J-M-L) replied

    Hello, do yourself a favour and please read How to get the best out of this forum and modify your post accordingly ➜ please edit your post, select the code part and press the `</>` icon in the tool bar to mark it as code. (also make sure you indented the code in the IDE before copying, that's done by pressing `ctrl``T` on a PC or `cmd``T` on a Mac)

After which, @GolamMostafa (gm) added

    Would you mind to learn first how to receive (transmit) only one character from the InputBox (to the OutputBox) of the Serial Monitor (Fig-1) and then learn multi-characters (the string)?  
    
    
    SerialMonitorX746×474 26.9 KB
    
      
    Figure-1:

@mohamad_ir (Mohamad Ir) replied

    I can send and receive between Arduino and LabVIEW successful.  
    But I want send this form:  
    a,b,c  
    A and b and c is variable.  
    And my received data from LabVIEW is a,b,c format .  
    After received in Arduino I can put into sensor variable,but I can't separate sensor=a,b,c and put into sensor1-3.

Then @gcjr (greg) said

    consider
    [code] 
        #define MAX_TOKS   10
        char * toks [MAX_TOKS];
        float  vals [MAX_TOKS];
        
        int
        tokenize (
            char *t )
        {
            char s [80];
            int  i = 0;
        
            printf ("%s: %s\n", __func__, s);
        
            strcpy (s, t);
        
            for (toks [i] = strtok (s, ","); toks [i]; )  {
                vals [i] = atof (toks [i]);
                toks [++i] = strtok (NULL, ",");
            }
        
            return i;
        }
        
        // -----------------------------------------------------------------------------
        const char t [] = "12.3,23,45.6,345,67";
        
        void
        setup (void)
        {
            Serial.begin (9600);
        
            int nTok = tokenize ((char*) t);
        
            for (int n = 0; n < nTok; n++)
                Serial.println (vals [n]);
        }
        
        void
        loop (void)
        {
        }
        
    [/code]

After which, @mrburnette (mrburnette) added

    mohamad_ir:
    
    > After received in Arduino I can put into sensor variable,but I can't separate sensor=a,b,c and put into sensor1-3.
    
    The comma-delimited format is often known as System Data Format, SDF. This is the format used in GPS NMEA, so GPS libraries offer a good view into how to parse SDF streams.
    [code] 
          if (strstr(nmea, "$GPRMC")) {
           // found RMC
            char *p = nmea;
        
            // get time
            p = strchr(p, ',')+1;
            float timef = atof(p);
            uint32_t time = timef;
            hour = time / 10000;
            minute = (time % 10000) / 100;
            seconds = (time % 100);
        
            milliseconds = fmod(timef, 1.0) * 1000;
            p = strchr(p, ',')+1;  // A/V?
            p = strchr(p, ',')+1;  // lat
            p = strchr(p, ',')+1;  // N/S?
            p = strchr(p, ',')+1;  // lon
            p = strchr(p, ',')+1;  // E/W?
            p = strchr(p, ',')+1;  // speed
            p = strchr(p, ',')+1;  // angle
        
            p = strchr(p, ',')+1;
            uint32_t fulldate = atof(p);
            day = fulldate / 10000;
            month = (fulldate % 10000) / 100;
            year = (fulldate % 100);
            // we dont parse the remaining, yet!
            return true;
          }
        
          return false;
        }
        
        
    [/code]

@sterretje (sterretjeToo) replied

    Robin's Serial Input Basics - updated might be a good read. It does not use String objects but it can give you the idea.
    
    Please edit your post, select all code and click the `</>` button to apply so-called code tags and next save your post. It makes it easier to read, easier to copy and prevents the forum software from incorrect interpretation of the code. This is described in How to get the best out of this forum.

To which @StefanL38 (Stefan Ludwig) replied

    the support to you could be much more specific if you would post the byte.seqeunce  
    byte for byte that your labVIEW-computer is sending
    
    additionally there can be differencies in
    
      * odd or even parity,
    
      * 7 or 8 databits,
    
      * no stopbit, 1 stopbits two stopbits
    
      * no line-ending
    
      * cr as line-ending
    
      * nl as line-ending
    
      * cr and nl as line-ending

To which @GolamMostafa (gm) replied

    StefanL38:
    
    > no stopbit, 1 stopbits two stopbits
    
    Is it possible to create an asynchronous frame without a **Stop Bit**? There is also the option for 1.5 stopbits.
    
    StefanL38:
    
    >   * odd or even parity,
    > 
    
    
    Or parity OFF (disabled).

After which, @gcjr (greg) added

    GolamMostafa:
    
    > Is it possible to create an asynchronous frame without a **Stop Bit**?
    
    how do you guarantee that the start bit is the opposite value?

After which, @GolamMostafa (gm) added

    gcjr:
    
    > how do you guarantee that the start bit is the opposite value?

After which, @gcjr (greg) added

    hence the "requirement" for a stop bit


{'source': 'discourse', 'url': 'https://forum.arduino.cc/t/send-recive-data-separated-by-comma/1019415', 'title': 'Send recive data separated by comma', 'views': 194, 'has_accepted_answer': False, 'word_count': 867, 'like_count': 1, 'reply_count': 5, 'participant_count': 7, 'posts': 13, 'tags': '', 'author': '@mohamad_ir (Mohamad Ir)', 'participants': '@mohamad_ir (Mohamad Ir), @StefanL38 (Stefan Ludwig), @J-M-L (J-M-L), @GolamMostafa (gm), @gcjr (greg), @mrburnette (mrburnette), @sterretje (sterretjeToo)', 'image_url': [None], 'created_at': '2022-08-05T05:29:42.444Z', 'last_posted_at': '2022-08-06T09:31:36.569Z'}