/*This software was made to demonstrate how to quickly get your Atlas Scientific product running on the Arduino platform.An Arduino MEGA 2560 board was used to test this code.This code was written in the Arudino 1.0 IDEModify the code to fit your system.**Type in a command in the serial monitor and the Atlas Scientific product will respond.****The data from the Atlas Scientific product will come out on the serial monitor.**Code efficacy was NOT considered, this is a demo only.The TX3 line goes to the RX pin of your product.The RX3 line goes to the TX pin of your product.Make sure you also connect to power and GND pins to power and a common ground.Open TOOLS > serial monitor, set the serial monitor to the correct serial port and set the baud rate to 38400.Remember, select carriage return from the drop down menu next to the baud rate selection; not "both NL & CR".*/

String inputstring = ""; //a string to hold incoming data from the PCString sensorstring = ""; //a string to hold the data from the Atlas Scientific productboolean input_stringcomplete = false; //have we received all the data from the PCboolean sensor_stringcomplete = false; //have we received all the data from the Atlas Scientific product

void serialEvent() { //if the hardware serial port_0 receives a char char inchar = (char)Serial.read(); //get the char we just received inputstring += inchar; //add it to the inputString if(inchar == '\r') {input_stringcomplete = true;} //if the incoming character is a <CR>, set the flag }

void serialEvent3(){ //if the hardware serial port_3 receives a char char inchar = (char)Serial3.read(); //get the char we just received sensorstring += inchar; //add it to the inputString if(inchar == '\r') {sensor_stringcomplete = true;} //if the incoming character is a <CR>, set the flag }

void loop(){ //here we go....

if (input_stringcomplete){ //if a string from the PC has been recived in its entierty Serial3.print(inputstring); //send that string to the Atlas Scientific product inputstring = ""; //clear the string: input_stringcomplete = false; //reset the flage used to tell if we have recived a completed string from the PC }

if (sensor_stringcomplete){ //if a string from the Atlas Scientific product has been recived in its entierty Serial.println(sensorstring); //send that string to to the PC's serial monitor sensorstring = ""; //clear the string: sensor_stringcomplete = false; //reset the flage used to tell if we have recived a completed string from the Atlas Scientific product } }

int main(void){init();#if defined(USBCON)USB.attach();#endifsetup();for (;;) {loop();if (serialEventRun) serialEventRun();}return 0;}Not a "multitasking background event" but checked once per loop and it won't interfere with your loop code ..Never used it, as it gives no clue about the amount of data available --> http://arduino.cc/forum/index.php/topic,139353.msg1046447.html#msg1046447