You are on page 1of 1

AtlasScientific Biology • Technology

Arduino sample code

EZ COM MEGA
/*
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 IDE
Modify 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".
*/

GND TX RX

Atlas
Scientific

VCC PRB GND


center

sheild

BNC

22
GND
AREF

9
8

7
6
5
4
3
2
1
0
13
12

10
11

SDA 20
RX3 15

RX2 17

RX1 19

SCL 21
TX3 14

TX2 16

TX1 18

24
PWM
TX
RX

26
28
COMMUNICATION
30 31
32 33
PWR
1 34 35
36 37
DIGITAL

38 39
40 41
I CSP 42 43
44 45
46 47
Ardui no MEGA 48 49
www. ar dui no.c c 50 51
52 53
RESET

ANALOG IN
3V3

5V GND VIN GND


10
11
12
13
14
15
0
1
2
3
4
5
6
7

8
9

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

void setup(){ //set up the hardware


Serial.begin(38400); //set baud rate for the hardware serial port_0 to 38400
Serial3.begin(38400); //set baud rate for software serial port_3 to 38400
inputstring.reserve(5); //set aside some bytes for receiving data from the PC
sensorstring.reserve(30); //set aside some bytes for receiving data from Atlas Scientific
} //product

void serialEvent() { //if the hardware serial port_0 receives


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

void serialEvent3(){ //if the hardware serial port_3 receives


char inchar = (char)Serial3.read(); //a char
sensorstring += inchar; //get the char we just received
if(inchar == '\r') {sensor_stringcomplete = true;} //add it to the inputString
} //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 received in its entierty
Serial3.print(inputstring); //send that string to the Atlas Scientific product
inputstring = ""; //clear the string:
input_stringcomplete = false; //reset the flag used to tell if we have received a completed
} //string from the PC

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

Click here to download the *.ino file

Atlas-Scientific.com Copyright © Atlas Scientific LLC All Rights Reserved

You might also like