Multiple Serial Communication On Arduino UNO


hi everyone, need help. okay have several sensor , need them work on arduino uno board although know arduino mega capable of holding 4 rx/tx want test out on uno board. okay i've read article , http://arduiniana.org/libraries/newsoftserial/ , it's on newsoftwareserial.h . i'm wondering if arduino software equipped it.
because right code communicate 1 sensor only!
code: [select]
/*
integrating flow meter , color detector work in 1 arduino board
*/

#include <softwareserial.h>                                                    //add soft serial libray
#define rxpin 2                                                                //set rx pin pin 2
#define txpin 3                                                                //set tx pin pin 3


softwareserial myserial(rxpin, txpin);                                         //enable soft serial port


string inputstring = "";                                                       //a string hold incoming data pc
string sensorstring = "";                                                      //a string hold data atlas scientific product
boolean input_stringcomplete = false;                                          //have received data pc
boolean sensor_stringcomplete = false;                                         //have received data atlas scientific product


 void setup(){                                                                //set hardware
    serial.begin(38400);                                                      //set baud rate hardware serial port 38400
    myserial.begin(38400);                                                    //set baud rate software serial port 38400
    inputstring.reserve(5);                                                   //set aside bytes receiving data pc
    sensorstring.reserve(30);                                                 //set aside bytes receiving data atlas scientific product
    }



  void serialevent() {                                                         //if hardware serial port receives char
              char inchar = (char)serial.read();                               //get char received
              inputstring += inchar;                                           //add inputstring
              if(inchar == '\r') {input_stringcomplete = true;}                //if incoming character <cr>, set flag
             }  



void loop(){                                                                   //here go....
   
 if (input_stringcomplete){                                                   //if string pc has been recived in entierty
     myserial.print(inputstring);                                             //send string atlas scientific product
     inputstring = "";                                                        //clear string:
     input_stringcomplete = false;                                            //reset flage used tell if have recived completed string pc
     }


 while (myserial.available()) {                                               //while char holding in serial buffer
        char inchar = (char)myserial.read();                                  //get new char
        sensorstring += inchar;                                               //add sensorstring
        if (inchar == '\r') {sensor_stringcomplete = true;}                   //if incoming character <cr>, set flag
        }


  if (sensor_stringcomplete){                                                 //if string atlas scientific product has been received in entirety
      serial.print(sensorstring);                                             //use hardware serial port send data pc
      sensorstring = "";                                                      //clear string:
      sensor_stringcomplete = false;                                          //reset flag used tell if have received completed string atlas scientific product
     }
}


what need change make work multiple serial port ? can define rx , tx again on other port? or there specific stuff have multiple serial communication working?

that page old , outdated.

the softwareserial has few restrictions, can receive 1 channel @ time. if want communicate sensors 1 one, not problem.
read next reference, explanes different versions.
http://arduino.cc/en/reference/softwareserial
the alternative paul stoffregen: https://www.pjrc.com/teensy/td_libs_altsoftserial.html

using standard softwareserial, use this:
code: [select]

#include <softwareserial.h>

softwareserial mysensor1 (10, 11); // rx, tx
softwareserial mysensor2 (8, 9); // rx, tx
softwareserial mysensor3(5,6); // rx, tx

void setup()  
{
 mysensor1.begin(38400);
 mysensor2.begin(38400);
 mysensor3.begin(38400);


Arduino Forum > Using Arduino > Interfacing w/ Software on the Computer > Multiple Serial Communication On Arduino UNO


arduino

Comments

Popular posts from this blog

Connecting Raspberry Pi 2 to P10(1R)-V706 LED Dot Matrix - Raspberry Pi Forums

TypeError: <unknown> is not a numpy array - Raspberry Pi Forums

datso and removing imagetitle - Joomla! Forum - community, help and support