Cooking Hacks Forum
https://www.cooking-hacks.com/forum/

Open Aquarium - Problemas al leer resultados
https://www.cooking-hacks.com/forum/viewtopic.php?f=34&t=10620
Page 1 of 1

Author:  claf [ Thu Sep 07, 2017 4:41 am ]
Post subject:  Open Aquarium - Problemas al leer resultados

Hola,

Este es mi primer post y soy principiante en esto del Arduino, entonces espero me ayuden. Tengo un Arduino uno, el open auarium y el aquaponics.

Tengo un Open Aquarium con el aquaponics board y el medidor de ph y EC.

Cuando uso el sketch standard el sistema si lee los resultados esperados para el pH y el EC (ya que estoy midiendo con sustancias "calibration kits").

Ahora,
El problema esta que estoy usando un sketch que se connecta a mi pc con un home automation. Cuando leo los valores de pH y de EC estos son muy differentes que el los valores obtenidos usando el sketch standard. Los resultados son mas altos.
?Es possible que el codigo del sketch al usar los siguientes codigos que el sistema este "guardando" el valor de la variable pH y EC?
En otros lenguajes de programacion se 'reinician' los valores de las variables para no "sumar" los nuevos valores de las variables. Creo que esta pasando algo asi ya que los valores de pH y de EC son mayores a los obtenidos con el standard sketch. Es esto posible con arduino??

Las variables son ph, EC, etc..
calibratepH(calibration_point_4,calibration_point_7,calibration_point_10) //pH sensor calibration
readpH() //Return pH value in mV
pHConversion(mvpH) //Returns the value of the pH sensor
calibrateEC(point_1_cond,point_1_cal,point_2_cond,point_2_cal) //EC sensor calibration
readResistanceEC() //Returns EC Value in resistance
ECConversion(_resistanceEC) //Returns EC Value in µS/cm

anexo abajo el codigo que estoy usando para el sketch que se conecta a la pc:
Note: estoy usando Homeseer Automation por si alguien necesita saber.

MUCHAS GRACIAS
Chris
Code:
 /*************************************************************
  Arduino to Homeseer 3 Plugin API written by Enigma Theatre.
   V1.0.0.140
 *************************************************************/
int FromHS[50];
boolean IsConnected = false;
//************************************************************
#include "OpenAquarium.h"
#include "Wire.h"

#define point_1_cond 12880   // Write here your EC calibration value of the solution 1 in µS/cm
#define point_1_cal 140       // Write here your EC value measured in resistance with solution 1
#define point_2_cond 1413   // Write here your EC calibration value of the solution 2 in µS/cm
#define point_2_cal 668      // Write here your EC value measured in resistance with solution 2

#define calibration_point_4 2568  //Write here your measured value in mV of pH 4
#define calibration_point_7 2519  //Write here your measured value in mV of pH 7
#define calibration_point_10 2465 //Write here your measured value in mV of pH 10

//**************Declare your variables here*******************

float Hardness;  //23 to convert EC to Harndess
float temperature; //30 read temps
int tempF; //convert temperature to Farenheit
float psival; // read pressure sensor voltage value
int Psipin = 1;  //pressure voltage connected to analog input # 1
int HSvalue = 0; //intial value of zero to not send data until device changes to 255
// everything works above
int AcidPump = 3; //25 Acid pump connected to digital output Pin # 3 of board to Relay # 1
int HSpumppower = 0; //initial value of zero for Pump to be OFF
int Poollights = 4; //Poollights to Digital Output Pin # 4 to relay # 2
int HSPoollights = 0; // Read variable from Homeseer Output # 2 to see if pool light should toggle
//****************************************************************

void HSSetup() {

  //************************
  //Add YOUR SETUP HERE;
  //************************
  //CPLT INSERTS START HERE
  Serial.begin(115200);  //serial needed to "start comms or something
  OpenAquarium.init();
  OpenAquarium.calibrateEC(point_1_cond, point_1_cal, point_2_cond, point_2_cal);
  OpenAquarium.calibratepH(calibration_point_4, calibration_point_7, calibration_point_10);
  delay(1500);

  // digitalWrite(DigitaloutA, OUTPUT); // digital output pin 7 controlling relay # 3

  // CPLT INSERTS END HERE

}

void HSloop() {

  //************************
  //Add YOUR CODE HERE;
  //************************
  /* To Send Data to Homeseer use SendToHS(Device,Value)
    Eg.. SendToHS(1,200); where 1 is the API device in homeseer and 200 is the value to send
    To Recieve data from Homeseer look up the FromHS array that is updated when the device value changes.
    Eg.. FromHS[5] would be the data from API Output device 5
    All code that is located just below this block will execute regardless of connection status!
    You can include SendToHS() calls, however when there isn't an active connection, it will just return and continue.
    If you only want code to execute when HomeSeer is connected, put it inside the if statement below.
  */

  /*Execute regardless of connection status*/

  //CPLT INSERTS END HERE


  if (IsConnected == true) {
    /*Execute ONLY when HomeSeer is connected*/

    //CPLT INSERTS STARTS HERE

    OpenAquarium.calibrateEC(point_1_cond, point_1_cal, point_2_cond, point_2_cal);
    OpenAquarium.calibratepH(calibration_point_4, calibration_point_7, calibration_point_10);
    delay(1500);

    digitalWrite(AcidPump, HIGH); //initial value of pump to be OFF until HSvalue is higher than 1 below
    //  digitalWrite(Poollights, HIGH); //initial value of Poollights to relay # 2 turn lights OFF

    HSpumppower = FromHS[1];  //Read value from Homeseer into HSpumppower Homeseer Output:1
    if (HSpumppower > 0) {  //If HSpumpower is 255 then turn the Acid Pump ON
      digitalWrite(AcidPump, LOW);
    }

    //  HSPoollights = FromHS[2]; //Read the value of Pool Lights from Homeseer Output:2
    //  if (HSPoollights > 0) {   // If HSPoollights is 255 then turn the pool lights on
    //   digitalWrite(Poollights, LOW); //Turn the lights ON
    //  }



    //Inserting the check to see if Arduino should send data to Homeseer
    HSvalue = FromHS[0]; //To read value from Homeseer into HSvalue Homeseer Output:0
    if (HSvalue > 0 ) {  //Reads value and compares if HSvalue = 255 then code is active

      float resistanceEC = OpenAquarium.readResistanceEC(); //EC Value in resistance
      // Serial.print(F("EC Value in resistance = "));
      // Serial.print(resistanceEC);

      // Serial.print(F(" // EC Value = "));
      float EC = OpenAquarium.ECConversion(resistanceEC); //EC Value in µS/cm
      // Serial.print(EC);
      // Serial.println(F(" uS/cm"));

      int mvpH = OpenAquarium.readpH(); //Value in mV of pH
      //  Serial.print(F("pH Value in mV = "));
      //  Serial.print(mvpH);

      // Serial.print(F(" // pH = "));
      float pH = OpenAquarium.pHConversion(mvpH); //Calculate pH value
      // Serial.println(pH);

    //  delay(2000);

      temperature = OpenAquarium.readtemperature(); //30 Read the sensor
      float tempF = (temperature * 1.8) + 32;  //30 convert to Farenheit
      // Serial.print("temperaturever2 'F ");
      // Serial.println(tempF);
      psival = analogRead(Psipin);
      float y = (psival - 102) * 30 / (921 - 30);
      float Hardness = (EC * 0.67); //23 pto convert EC to water hardness 0.67 factor

      SendToHS(1, pH);
      SendToHS(2, resistanceEC);  //just for testing resistance to hs3
      SendToHS(3, HSvalue); //just for reading and checking the value that was read from homeseer
      SendToHS(4, mvpH); //just for testing to be removed pH vaklue in mV
      SendToHS(5, tempF);  //send over to Homeseer the value in degrees F
      //  SendToHS(6, y);     //send over to Homeseer the value of pressure in psi
      //  SendToHS(7, psival); //send over the value of the pressure sensor for testing only

      // }  // este cierra 1 el delay de 30 segundos
    } //closes the IF HSvalue = 255 (activated) send data to HS3

  } //este cierra si la coneccion to HS esta activada
} //este cierra el main HSloop

//************Do not change anything after Here*****************

#define ISIP 0
#define BoardType 1
const byte BoardAdd = 1;

#include <EEPROM.h>

#if BoardType == 3
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
char ssid[] = "TALKTALK-C94ECC";
char pass[] = "YNH9EXWA";
#else
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#endif


#if ISIP == 1


byte mac[] = {0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x01};
IPAddress ip(10, 0, 0, 152);  //IP entered In HS config.
const unsigned int localPort = 8900;      //port entered In HS config.
IPAddress HomeseerIP(10, 0, 0, 151); //Homeseer IP address
IPAddress ServerIP(EEPROM.read(2), EEPROM.read(3), EEPROM.read(4), EEPROM.read(5));
IPAddress gateway(192, 168, 0, 1);
IPAddress subnet(255, 255, 255, 0);
byte EEpromVersion = EEPROM.read(250);
char packetBuffer[UDP_TX_PACKET_MAX_SIZE];
const unsigned int ServerPort = 8888;
#endif




#if BoardType == 3
WiFiUDP Udp;
WiFiUDP SendPort;
#else
EthernetUDP Udp;
#endif

#if BoardType == 3
void resetFunc() {
  ESP.restart();
}
#else
void(* resetFunc) (void) = 0;
#endif




































char* Version = "API1.0.0.140";

byte Byte1, Byte2, Byte3;
unsigned int Byte4, Byte5;


void setup() {

#if BoardType == 3
  // WiFi.persistent(false);
  EEPROM.begin(256);
  EEpromVersion = EEPROM.read(250);
#endif

#if ISIP == 1
  if (EEpromVersion != 22) {
    ServerIP = HomeseerIP;
    EEPROM.write(2, ServerIP[0]);
    EEPROM.write(3, ServerIP[1]);
    EEPROM.write(4, ServerIP[2]);
    EEPROM.write(5, ServerIP[3]);
    EEPROM.write(250, 22); //Store the version where the eeprom data layout was last changed
    EEpromVersion = 22;
  }
#if BoardType == 3
  //Serial.begin(115200);
  WiFi.begin(ssid, pass);
  WiFi.config(ip, gateway, subnet);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
  }
#else
  Ethernet.begin(mac, ip, gateway, gateway, subnet);
#endif
  Udp.begin(localPort);
  Udp.setTimeout(0);
  delay(1000);
  SendConnect();
#else
  Serial.begin(115200);
  Serial.flush();
  Serial.setTimeout(0);
  delay(1000);
  Serial.print("Connect ");
  Serial.println(BoardAdd);
#endif

  IsConnected = false;
  HSSetup();
}


void loop() {
  HSloop();
#if ISIP == 1
  UDPCheck();
#endif
}


void SendConnect()
{
#if ISIP == 0
  Serial.print("Connect ");
  Serial.println(BoardAdd);
#else
  Udp.beginPacket(HomeseerIP, ServerPort); //First send a connect packet to the dynamic IP stored in eeprom
  Udp.print("Connect ");
  Udp.print(BoardAdd);
  Udp.endPacket();
  if (ServerIP != HomeseerIP) {
    Udp.beginPacket(HomeseerIP, ServerPort); //Then if the stored value doesn't match the pre-specified one, send a connect packet there also
    Udp.print("Connect ");
    Udp.print(BoardAdd);
    Udp.endPacket();
  }

#endif
}



#if ISIP == 1
void UDPCheck() {
  int packetSize = Udp.parsePacket();
  if (packetSize)
  {

#if BoardType == 3
    IPAddress remote = Udp.remoteIP();
    Byte1 = Udp.parseInt();
    Udp.read();
    Byte2 = Udp.read();
    Udp.read();
    Byte3 = Udp.parseInt();
    Udp.read();
    Byte4 = Udp.parseInt();
    Udp.read();
    Byte5 = Udp.parseInt();
    DataEvent();
#else

    ServerIP = Udp.remoteIP();
    Byte1 = Udp.parseInt();
    Udp.read();
    Byte2 = Udp.read();
    Byte3 = Udp.parseInt();;
    Byte4 = Udp.parseInt();
    Byte5 = Udp.parseInt();;

    DataEvent();
#endif
  }
}

#else
void serialEvent() {
  while (Serial.available() > 0) {
    delay(17);


    Byte1 = Serial.parseInt();
    Serial.read();
    Byte2 = Serial.read();
    Byte3 = Serial.parseInt();
    Byte4 = Serial.parseInt();
    Byte5 = Serial.parseInt();
    DataEvent();
  }
}
#endif


/*

  Used Data Input Cases
  D Disconnect
  r reset
  K Keepalive
  O PinMode Output Set
  d Input debounce time set
  C Connect request
  c Connection established - report current status
*/
void DataEvent() {

  if (Byte1 == BoardAdd) {

#if ISIP == 1
    if (Udp.remoteIP() != ServerIP) {
      ServerIP = Udp.remoteIP();
      EEPROM.write(2, ServerIP[0]);
      EEPROM.write(3, ServerIP[1]);
      EEPROM.write(4, ServerIP[2]);
      EEPROM.write(5, ServerIP[3]);
    }
#endif

    switch (Byte2) {
      case 'c':
        IsConnected = true;
        break;

      case 'C':
#if ISIP == 1
        Udp.beginPacket(HomeseerIP, ServerPort);
        Udp.print("Version ");
        Udp.print(BoardAdd);
        Udp.print(" ");
        Udp.print(Version);
        Udp.println(" HS3");
        Udp.endPacket();

        Udp.beginPacket(HomeseerIP, ServerPort);
        delay(100);
        Udp.print("Connected ");
        Udp.println(BoardAdd);
        Udp.endPacket();
#else
        Serial.print("Version ");
        Serial.print(BoardAdd);
        Serial.print(" ");
        Serial.print(Version);
        Serial.println(" HS3");
        delay(100);
        Serial.print("Connected ");
        Serial.println(BoardAdd);
#endif
        delay(100);
        IsConnected = false;
        break;

      case 'K':
        delay(200);
#if ISIP == 1
        Udp.beginPacket(HomeseerIP, ServerPort);
        Udp.print("Alive ");
        Udp.println(BoardAdd);
        Udp.endPacket();
        if (Udp.remoteIP() != ServerIP) {
          ServerIP = Udp.remoteIP();
          EEPROM.write(2, ServerIP[0]);
          EEPROM.write(3, ServerIP[1]);
          EEPROM.write(4, ServerIP[2]);
          EEPROM.write(5, ServerIP[3]);
        }
#else
        Serial.print("Alive ");
        Serial.println(BoardAdd);
#endif
        break;

      case 'r':
        delay(200);
        resetFunc();  //call reset
        break;

      case 'O':
        FromHS[Byte3] = Byte4;
        break;

      case 'D':
        IsConnected = false;
        break;
    }
  }
}

void SendToHS(byte Device, long Data) {
  if (IsConnected == true) {
#if ISIP == 1
    Udp.beginPacket(HomeseerIP, ServerPort);
    Udp.print(BoardAdd);
    Udp.print(" API ");
    Udp.print(Device);
    Udp.print(" ");
    Udp.print(Data);
    Udp.endPacket();
#else
    Serial.print(BoardAdd);
    Serial.print(" API ");
    Serial.print(Device);
    Serial.print(" ");
    Serial.println(Data);
#endif
  }
}

void SendToHS(byte Device, int Data) {
  if (IsConnected == true) {
#if ISIP == 1
    Udp.beginPacket(HomeseerIP, ServerPort);
    Udp.print(BoardAdd);
    Udp.print(" API ");
    Udp.print(Device);
    Udp.print(" ");
    Udp.print(Data);
    Udp.endPacket();
#else
    Serial.print(BoardAdd);
    Serial.print(" API ");
    Serial.print(Device);
    Serial.print(" ");
    Serial.println(Data);
#endif
  }
}

void SendToHS(byte Device, float Data) {
  if (IsConnected == true) {
#if ISIP == 1
    Udp.beginPacket(HomeseerIP, ServerPort);
    Udp.print(BoardAdd);
    Udp.print(" API ");
    Udp.print(Device);
    Udp.print(" ");
    Udp.print(Data);
    Udp.endPacket();
#else
    Serial.print(BoardAdd);
    Serial.print(" API ");
    Serial.print(Device);
    Serial.print(" ");
    Serial.println(Data);
#endif
  }
}

void SendToHS(byte Device, double Data) {
  if (IsConnected == true) {
#if ISIP == 1
    Udp.beginPacket(HomeseerIP, ServerPort);
    Udp.print(BoardAdd);
    Udp.print(" API ");
    Udp.print(Device);
    Udp.print(" ");
    Udp.print(Data);
    Udp.endPacket();
#else
    Serial.print(BoardAdd);
    Serial.print(" API ");
    Serial.print(Device);
    Serial.print(" ");
    Serial.println(Data);
#endif
  }
}

Author:  libelium-dev [ Thu Sep 07, 2017 7:41 am ]
Post subject:  Re: Open Aquarium - Problemas al leer resultados

Hola claf,

Si el código de ejemplo te funciona y te da unos valores, ve modificándolo poco a poco para ver en qué momento los valores se alteran.

Además, te recomienda que compruebes que de todo lo que usas compruebes que ningún elemento utiliza los mismos pines que otros elementos no vaya a ser que altere la medición.

Un saludo

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/