/* * NAME: LuminoxO2_PlosOne-sketch * * BY: Paul O'Neill * * Written for ESP8266 'Amica' ESP-12E module Receives from software serial port, sends to hardware serial port. RX is digital pin 13 (connect to TX of level shifter: pin B1) TX is digital pin 15 (connect to RX of level shifter: pin B2) Seperate 5V power applied to Luminox O2 sensor Pin 1 LuminoxO2 goes to TENMA Regulated Power Supply plus terminal set at 5V Pin 2 LuminoxO2 goes to TENMA Regulated Power Supply minus terminal Pin 3 LuminoxO2-Tx goes to Amica GPIO13 (RXD2) Pin 4 LuminoxO2-Rx goes to Amica GPIO15 (TXD2) Loosely adapted from a public domain program written by S.P. Mathupala, Ph.D. */ #include //incorporate software-serial libray SoftwareSerial myserial(13, 15); //enable software serial port 10 to RX, and 11 to TX long delayPeriod; //introduce the variable delayPeriod String Luminoxstring = ""; //string to hold incoming data from Luminox-O2 sensor boolean Luminox_stringcomplete = false; //were all data from Luminox-O2 sensor received? check void setup() { Serial.begin(9600); //set baud rate for Arduino serial port to 9600 myserial.begin(9600); //set baud rate for software serial port to 9600 Luminoxstring.reserve(41); //set aside 41 bytes for receiving data from Luminox-O2 sensor } void serialEvent() //arduino.cc/en/Tutorial/SerialEvent { delayPeriod = 1000; String inchar = ""; //setup a string to hold incoming char while (Serial.available() > 0) { //when a char is avaialble in serial buffer inchar += (char)Serial.read(); //grab that char // if (inchar == "m") //if the char is a "m" // delayPeriod = 300000; //set delay period to 5 minutes (300000 milli seconds) if (inchar == "s") //if char is a "s" delayPeriod = 1000; //set delay period to 1 second (1000 milli seconds) } } void loop() { { // Serial.print("."); //start the loop sequence while (myserial.available()) { //when a char is avaialable in software serial buffer char inchar = (char)myserial.read(); //grab that char Luminoxstring += inchar; //add the received char to LuminoxString if (inchar == '\r') { //if the incoming character is a , reset Luminox_stringcomplete = true; //then a complete string of data has been recieved from Luminox-O2 sensor } } if (Luminox_stringcomplete) { //has a complete string from the Luminox sensor has been received? Luminoxstring.remove(80); //remove any serial string overruns between reads Serial.print(Luminoxstring); //use the Arduino serial port to send that data to CoolTerm Luminoxstring = ""; //then clear the Luminoxstring: Luminox_stringcomplete = false; //await the next data string from Luminox-O2 sensor delay(delayPeriod); //pause for 5 minutes(300000 millis); or 1 second (1000 millis) } } }