Convert serial.read() into a useable string using Arduino?

后端 未结 15 1134
盖世英雄少女心
盖世英雄少女心 2020-11-29 15:27

I\'m using two Arduinos to sent plain text strings to each other using newsoftserial and an RF transceiver.

Each string is perhaps 20-30 characters in length. How do

15条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-29 16:33

    Use string append operator on the serial.read(). It works better than string.concat()

    char r;
    string mystring = "";
    
    while(serial.available()) 
       {
        r = serial.read();
        mystring = mystring + r; 
       }
    

    After you are done saving the stream in a string(mystring, in this case), use SubString functions to extract what you are looking for.

提交回复
热议问题