Atlas Scientific Multiplexer

I’m in the beginning design stages of another project that includes the pH, ORP and EC stamps from Atlas Scientific. I’ve run into a snag I guess because they all use the serial connection along with my Bluetooth module. The attached code is the sample that Atlas provides. Since i’d only be using 3 of the 4 ports for the sensors can I use the 4th for my bluetooth module to send and receive the serial data from my android app. Or can I still use the regular serial port (0,1) for my bluetooth module in conjunction with the Software Serial library for the Altas Multiplexer?

/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This software was made to demonstrate how to quickly get your RS-232 connector running.
An Arduino Duemilanove board was used to test this code. Modify the code to fit your system.
Code efficacy was not considered, this is a demo only.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The soft serial port TX line (pin 3) goes to the RS-232 connector RX pin found in the Z block.
The soft serial port RX line (pin 2) goes to the RS-232 connector TX pin found in the Z block.
Data from the RS-232 connector is received and re-sent through the Arduinos hardware UART
TX line. Open TOOLS > serial monitor, set the serial monitor to the correct serial port and set the
baud rate to 38400. The data from your Atlas Scientific products will appear on the serial monitor.
The RS-232 connector has 3 control pins; TX and RX are connected to the Z pins.
S0 (Arduino Duemilanove board pin 4)
S1 (Arduino Duemilanove board pin 5)
E (pull to GND)
E is the enable pin. This pin is active low; in this example, we don't use E. Instead we just pull E to
GND. S0 and S1 are the control pins that direct where the input/output comes from. There are 4
locations from where the input/output can be directed.
Y0 | S0=0 S1=0
Y1 | S0=1 S1=0
Y2 | S0=0 S1=1
Y3 | S0=1 S1=1
*/
#include <SoftwareSerial.h>
#define rxpin 2
#define txpin 3
SoftwareSerial myserial(rxpin, txpin);
String sensorstring = "";
short ec=0;
short d_o=1;
short orp=2;
short ph=3;
boolean sensor_stringcomplete=false;
short ack_channel_read=0;
void setup(){
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
sensorstring.reserve(30);
myserial.begin(38400);
Serial.begin(38400);
}
while(ack_channel_read==0){
Open_channel(ec);
ack_channel_read=read_channel(ec);
}
while(ack_channel_read==1){
Open_channel(d_o);
read_channel(d_o);
}
while(ack_channel_read==2){
Open_channel(orp);
read_channel(orp);
}
while(ack_channel_read==3){
Open_channel(ph);
read_channel(ph);
}
if(ack_channel_read==4){ack_channel_read=0;}
}
void Open_channel(short channel){
switch (channel) {
case 0:
digitalWrite(4, LOW);
digitalWrite(5, LOW);
break;
case 1:
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
break;
case 2:
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
break;
case 3:
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
break;
}
// myserial.print('/r');
return;
}
short read_channel(short channel){
if (sensor_stringcomplete){
delay(1100);
//let 1.1 sec pass
myserial.print("r");
myserial.write(13);
while (myserial.available()) {
char inchar = (char)myserial.read();
sensorstring += inchar;
if (inchar == '\r') {sensor_stringcomplete = true;}
}
if(channel==0){
Serial.print("EC: ");
ack_channel_read=1;
}
if(channel==1){
Serial.print("D.O: ");
ack_channel_read=2;
}
if(channel==2){
Serial.print("ORP: ");
ack_channel_read=3;
}
if(channel==3){
Serial.print("Ph: ");
ack_channel_read=4;
}
Serial.print(sensorstring);
sensorstring = "";
sensor_stringcomplete = false;
}
return ack_channel_read;
}

The code is horribly formated, I don't want to look at such a mess. Please post formated code, the IDE provides a tool for that.

Because you're writing about 4 port I guess you own a Mega2560, don't you?

I'd always use the available hardware serial interfaces to connect to the devices and use SoftwareSerial for the debugging. SoftwareSerial is blocking interrupts while it's sending or receiving so it may cause race conditions and data losses. If you just use it for debugging you can eliminate it completely once you finished the debugging and you get a stable and reliable system.

No, No Mega. Code is fine. I answered my own question this morning after sleeping on it...thanks though.