const int multiplexadorS0Pin = 16; // S0
const int multiplexadorS1Pin = 17; // S1
byte ph1 = 0; // Y0
byte ph2 = 1; // Y1
byte orp = 2; // Y2
byte ec = 3; // Y3
int ORP = 0;
int DEN = 0;
float PHA = 0.0;
float PHR = 0.0;
long millis_antes = 0;
void setup()
{
Serial.begin(38400);
Serial3.begin(38400);
Serial.println("I'm alive!");
Serial.println();
pinMode(multiplexadorS0Pin, OUTPUT);
pinMode(multiplexadorS1Pin, OUTPUT);
StartStampTankPH();
}
void loop()
{
if((millis() - millis_antes) >= 10000)
{
Serial.println("testing loop");
CheckTankPH();
millis_antes = millis();
Serial.println(" ****************************** ");
Serial.println();
}
}
void CheckTankPH()
{
boolean done = false;
char inData[150];
char *inParse[150];
int index = 0;
int contador = 0;
boolean stringComplete = false;
char *str;
int count = 0;
Serial.println("stage1");
do{
Open_channel(ph1);
delay(50);
while(Serial3.available())
{
char c = Serial3.read();
}
Serial3.print('\r');
Serial.println("stage2");
delay(1000);
Serial3.print("R"); // Envia um comando.
Serial3.print('\r');
Serial.println("stage3");
delay(1000);
Serial.println("stage4");
if (Serial3.available()>3)
{
char inChar = Serial3.read();
inData[index] = inChar;
index++;
Serial.println("stage5");
if (inChar == '\r')
{
contador ++;
}
if(contador == 23)
{
inData[index] = '\0';
contador = 0;
stringComplete = true;
}
}
while(stringComplete == false);
Serial.println("stage6");
for (int i= 0; i <= index; i++)
{
if (inData[i] == '\r')
{
inData[i] = ',';
}
}
char *p = inData;
if (stringComplete == true)
{
while ((str = strtok_r(p, ",", &p)) != NULL)
{
inParse[count] = str;
count++;
}
PHA = 0;
for(int i= 13; i < 21; i++)
{
PHA += atof(inParse[i]);
}
PHA /= 8;
Serial.print("Tank pH: ");
Serial.print(PHA);
Serial.print(", Values = [");
Serial.print(inParse[13]);
Serial.print(", ");
Serial.print(inParse[14]);
Serial.print(", ");
Serial.print(inParse[15]);
Serial.print(", ");
Serial.print(inParse[16]);
Serial.print(", ");
Serial.print(inParse[17]);
Serial.print(", ");
Serial.print(inParse[18]);
Serial.print(", ");
Serial.print(inParse[19]);
Serial.print(", ");
Serial.print(inParse[20]);
Serial.println("]");
Serial.println();
}
}
while (done == true);
}
void StartStampTankPH()
{
Open_channel(ph1); // Open channel for tank pH
delay(50);
Serial3.print("R"); // To get a value
Serial3.print('\r');
delay(1000);
Serial3.print("C,0"); // To stop continuous reading
Serial3.print('\r');
delay(1000);
Serial3.print("L,0"); // To turn off the LEDs of debug
Serial3.print('\r');
delay(1000);
Serial3.print("RESPONSE,0"); // To disable response code
Serial3.print('\r');
delay(1000);
}
void Open_channel(short channel)
{
switch (channel)
{
case 0:
//open channel Y0
//S0=0
//S1=0
digitalWrite(multiplexadorS0Pin, LOW);
digitalWrite(multiplexadorS1Pin, LOW);
break;
case 1:
//open channel Y1
//S0=1
//S1=0
digitalWrite(multiplexadorS0Pin, HIGH);
digitalWrite(multiplexadorS1Pin, LOW);
break;
case 2:
//open channel Y2
//S0=0
//S1=1
digitalWrite(multiplexadorS0Pin, LOW);
digitalWrite(multiplexadorS1Pin, HIGH);
break;
case 3:
//open channel Y3
//S0=1
//S1=1
digitalWrite(multiplexadorS0Pin, HIGH);
digitalWrite(multiplexadorS1Pin, HIGH);
break;
}
Serial3.print('\r');
return;
}
const int multiplexadorS0Pin = 16; // S0
const int multiplexadorS1Pin = 17; // S1
byte ph1 = 0; // Y0
byte ph2 = 1; // Y1
byte orp = 2; // Y2
byte ec = 3; // Y3
int ORP = 0;
int DEN = 0;
float PHA = 0.0;
float PHR = 0.0;
long millis_antes = 0;
void setup()
{
Serial.begin(38400);
Serial3.begin(38400);
Serial.println("I'm alive!");
Serial.println();
pinMode(multiplexadorS0Pin, OUTPUT);
pinMode(multiplexadorS1Pin, OUTPUT);
StartStampTankPH();
}
void loop()
{
if((millis() - millis_antes) >= 10000)
{
Serial.println("testing loop");
CheckTankPH();
millis_antes = millis();
Serial.println(" ****************************** ");
Serial.println();
}
}
void CheckTankPH()
{
boolean done = false;
char inData[150];
char *inParse[150];
int index = 0;
int contador = 0;
boolean stringComplete = false;
char *str;
int count = 0;
Serial.println("stage1");
do{
Open_channel(ph1);
delay(50);
if (Serial3.available()>3)
{
char inChar = Serial3.read();
inData[index] = inChar;
index++;
Serial.println("stage2");
if (inChar == '\r')
{
contador ++;
}
if(contador == 23)
{
inData[index] = '\0';
contador = 0;
stringComplete = true;
}
}
while(stringComplete == false);
Serial.println("stage3");
for (int i= 0; i <= index; i++)
{
if (inData[i] == '\r')
{
inData[i] = ',';
}
}
char *p = inData;
if (stringComplete == true)
{
while ((str = strtok_r(p, ",", &p)) != NULL)
{
inParse[count] = str;
count++;
}
PHA = 0;
for(int i= 13; i < 21; i++)
{
PHA += atof(inParse[i]);
}
PHA /= 8;
Serial.print("Tank pH: ");
Serial.print(PHA);
Serial.print(", Values = [");
Serial.print(inParse[13]);
Serial.print(", ");
Serial.print(inParse[14]);
Serial.print(", ");
Serial.print(inParse[15]);
Serial.print(", ");
Serial.print(inParse[16]);
Serial.print(", ");
Serial.print(inParse[17]);
Serial.print(", ");
Serial.print(inParse[18]);
Serial.print(", ");
Serial.print(inParse[19]);
Serial.print(", ");
Serial.print(inParse[20]);
Serial.println("]");
Serial.println();
}
}
while (done == true);
}
void StartStampTankPH()
{
Open_channel(ph1); // Open channel for tank pH
delay(50);
Serial3.print("R"); // To get a value
Serial3.print('\r');
delay(1000);
Serial3.print("C,1"); // To enable continuous reading
Serial3.print('\r');
delay(1000);
Serial3.print("L,0"); // To turn off the LEDs of debug
Serial3.print('\r');
delay(1000);
Serial3.print("RESPONSE,0"); // To disable response code
Serial3.print('\r');
delay(1000);
}
void Open_channel(short channel)
{
switch (channel)
{
case 0:
//open channel Y0
//S0=0
//S1=0
digitalWrite(multiplexadorS0Pin, LOW);
digitalWrite(multiplexadorS1Pin, LOW);
break;
case 1:
//open channel Y1
//S0=1
//S1=0
digitalWrite(multiplexadorS0Pin, HIGH);
digitalWrite(multiplexadorS1Pin, LOW);
break;
case 2:
//open channel Y2
//S0=0
//S1=1
digitalWrite(multiplexadorS0Pin, LOW);
digitalWrite(multiplexadorS1Pin, HIGH);
break;
case 3:
//open channel Y3
//S0=1
//S1=1
digitalWrite(multiplexadorS0Pin, HIGH);
digitalWrite(multiplexadorS1Pin, HIGH);
break;
}
Serial3.print('\r');
return;
}
if((millis() - millis_antes) >= 10000)
const int multiplexadorS0Pin = 16; // S0
const int multiplexadorS1Pin = 17; // S1
byte ph1 = 0; // Y0
byte ph2 = 1; // Y1
byte orp = 2; // Y2
byte ec = 3; // Y3
int ORP = 0;
int DEN = 0;
float PHA = 0.0;
float PHR = 0.0;
long millis_antes = 0;
void setup()
{
Serial.begin(38400);
Serial3.begin(38400);
Serial.println("I'm alive!");
Serial.println();
pinMode(multiplexadorS0Pin, OUTPUT);
pinMode(multiplexadorS1Pin, OUTPUT);
StartStampTankPH();
//StartStampReactorPH();
//StartStampORP();
}
void loop()
{
if((millis() - millis_antes) >= 10000)
{
CheckTankPH();
//CheckReactorPH();
//CheckORP();
millis_antes = millis();
Serial.println(" ****************************** ");
Serial.println();
}
}
void CheckTankPH()
{
char inData[150];
char *inParse[150];
int index = 0;
int contador = 0;
boolean stringComplete = false;
char *str;
int count = 0;
Open_channel(ph1);
delay(50);
do
{
if (Serial3.available()>3)
{
char inChar = Serial3.read();
inData[index] = inChar;
index++;
if (inChar == '\r')
{
contador ++;
}
if(contador == 23)
{
inData[index] = '\0';
contador = 0;
stringComplete = true;
}
}
}
while(stringComplete == false);
for (int i= 0; i <= index; i++)
{
if (inData[i] == '\r')
{
inData[i] = ',';
}
}
char *p = inData;
if (stringComplete == true)
{
while ((str = strtok_r(p, ",", &p)) != NULL)
{
inParse[count] = str;
count++;
}
PHA = 0;
for(int i= 13; i < 21; i++)
{
PHA += atof(inParse[i]);
}
PHA /= 8;
Serial.print("Tank pH: ");
Serial.print(PHA);
Serial.print(", Values = [");
Serial.print(inParse[13]);
Serial.print(", ");
Serial.print(inParse[14]);
Serial.print(", ");
Serial.print(inParse[15]);
Serial.print(", ");
Serial.print(inParse[16]);
Serial.print(", ");
Serial.print(inParse[17]);
Serial.print(", ");
Serial.print(inParse[18]);
Serial.print(", ");
Serial.print(inParse[19]);
Serial.print(", ");
Serial.print(inParse[20]);
Serial.println("]");
Serial.println();
}
}
void CheckReactorPH()
{
char inData[150];
char *inParse[150];
int index = 0;
int contador = 0;
boolean stringComplete = false;
char *str;
int count = 0;
Open_channel(ph2);
delay(50);
do
{
if (Serial3.available()>3)
{
char inChar = Serial3.read();
inData[index] = inChar;
index++;
if (inChar == '\r')
{
contador ++;
}
if(contador == 23)
{
inData[index] = '\0';
contador = 0;
stringComplete = true;
}
}
}
while(stringComplete == false);
for (int i= 0; i <= index; i++)
{
if (inData[i] == '\r')
{
inData[i] = ',';
}
}
char *p = inData;
if (stringComplete == true)
{
while ((str = strtok_r(p, ",", &p)) != NULL)
{
inParse[count] = str;
count++;
}
PHR = 0;
for(int i= 13; i < 21; i++)
{
PHR += atof(inParse[i]);
}
PHR /= 8;
Serial.print("Reactor pH: ");
Serial.print(PHR);
Serial.print(", Values = [");
Serial.print(inParse[13]);
Serial.print(", ");
Serial.print(inParse[14]);
Serial.print(", ");
Serial.print(inParse[15]);
Serial.print(", ");
Serial.print(inParse[16]);
Serial.print(", ");
Serial.print(inParse[17]);
Serial.print(", ");
Serial.print(inParse[18]);
Serial.print(", ");
Serial.print(inParse[19]);
Serial.print(", ");
Serial.print(inParse[20]);
Serial.println("]");
Serial.println();
}
}
void CheckORP()
{
char inData[150];
char *inParse[150];
int index = 0;
int contador = 0;
boolean stringComplete = false;
char *str;
int count = 0;
Open_channel(orp);
delay(50);
do
{
if (Serial3.available()>3)
{
char inChar = Serial3.read();
inData[index] = inChar;
index++;
if (inChar == '\r')
{
contador ++;
}
if(contador == 23)
{
inData[index] = '\0';
stringComplete = true;
}
}
}
while(stringComplete == false);
for (int i= 0; i <= index; i++)
{
if (inData[i] == '\r')
{
inData[i] = ',';
}
}
char *p = inData;
if (stringComplete == true)
{
while ((str = strtok_r(p, ",", &p)) != NULL)
{
inParse[count] = str;
count++;
}
ORP = 0;
for(int i= 13; i < 21; i++)
{
ORP += atoi(inParse[i]);
}
ORP /= 8;
Serial.print("ORP: ");
Serial.print(ORP);
Serial.print(", Values = [");
Serial.print(inParse[13]);
Serial.print(", ");
Serial.print(inParse[14]);
Serial.print(", ");
Serial.print(inParse[15]);
Serial.print(", ");
Serial.print(inParse[16]);
Serial.print(", ");
Serial.print(inParse[17]);
Serial.print(", ");
Serial.print(inParse[18]);
Serial.print(", ");
Serial.print(inParse[19]);
Serial.print(", ");
Serial.print(inParse[20]);
Serial.println("]");
Serial.println();
}
}
void StartStampTankPH()
{
Open_channel(ph1); // Tank pH
Serial3.print("L,0");
Serial3.print('\r');
delay(1000);
Serial3.print("C,1");
Serial3.print('\r');
delay(1000);
Serial3.print("RESPONSE,0"); // To disable response code
Serial3.print('\r');
delay(1000);
}
void StartStampReactorPH()
{
Open_channel(ph2); // Reactor pH
delay(50);
Serial3.print("E");
Serial3.print('\r');
delay(1000);
Serial3.print("L0");
Serial3.print('\r');
delay(1000);
Serial3.print("C");
Serial3.print('\r');
}
void StartStampORP()
{
Open_channel(orp); // ORP
delay(50);
Serial3.print("E");
Serial3.print('\r');
delay(1000);
Serial3.print("L0");
Serial3.print('\r');
delay(1000);
Serial3.print("C");
Serial3.print('\r');
}
void Open_channel(short channel)
{
switch (channel)
{
case 0:
//open channel Y0
//S0=0
//S1=0
digitalWrite(multiplexadorS0Pin, LOW);
digitalWrite(multiplexadorS1Pin, LOW);
break;
case 1:
//open channel Y1
//S0=1
//S1=0
digitalWrite(multiplexadorS0Pin, HIGH);
digitalWrite(multiplexadorS1Pin, LOW);
break;
case 2:
//open channel Y2
//S0=0
//S1=1
digitalWrite(multiplexadorS0Pin, LOW);
digitalWrite(multiplexadorS1Pin, HIGH);
break;
case 3:
//open channel Y3
//S0=1
//S1=1
digitalWrite(multiplexadorS0Pin, HIGH);
digitalWrite(multiplexadorS1Pin, HIGH);
break;
}
Serial3.print('\r');
return;
}
Return to Show your controller
Users viewing this topic: No registered users and 1 guest