Fout in code?

Software die niet past in bovenstaande onderwerpen
Berichten: 340
Geregistreerd: 23 Okt 2016, 20:29

Fout in code?

Berichtdoor benvo » 22 Jan 2018, 21:29

Al wat langer gebruik ik een PH kallibratie code waar ik een update van vond op Github. Voor mij lijkt dit interessant maar er blijkt een fout in te zitten die ik niet kan herleiden.
Zit het in de struct regel?
Hopelijk ziet iemand van jullie het wel?

cpp code
#include <AnalogPHMeter.h>
#include <EEPROM.h>


AnalogPHMeter pHSensor(A0);
unsigned int pHCalibrationValueAddress = 0;


void setup(void) {
Serial.begin(9600);


struct PHCalibrationValue pHCalibrationValue;
EEPROM.get(pHCalibrationValueAddress, pHCalibrationValue);
pHSensor.initialize(pHCalibrationValue);

Serial.println("Analog PH Meter Calibration");
Serial.println("The value will be saved on EEPROM");
Serial.println("Procedure:");
Serial.println(" - Put pH on pH 7 solution");
Serial.println(" - Wait until stable");
Serial.println(" - Press 'm' to calibrate");
Serial.println(" - Same process for pH 4 and/or pH 10,");
Serial.println(" except press 'l' for pH 4, and 'h' for pH 10");
Serial.println();
Serial.println("All calibration value will be reset after restart.");
Serial.println("In this example, press 's' to save the value to EEPROM");
Serial.println("You can freely change the storage.");
Serial.println("It is not limited to EEPROM only");
Serial.println();
Serial.println("*to clear calibration value press 'c'");
delay(3000);
}


void loop(void) {
static unsigned long t = millis();
if (millis() - t > 1000) {
Serial.println(pHSensor.singleReading().getpH());
t = millis();
}


if (Serial.available()) {
char c = Serial.read();
if (c == 'm') {
pHSensor.calibrationMid(7.000f);
} else if (c == 'l') {
pHSensor.calibrationLow(4.000f);
} else if (c == 'h') {
pHSensor.calibrationHigh(10.000f);
} else if (c == 'c') {
pHSensor.calibrationClear();
} else if (c == 's') {
EEPROM.put(pHCalibrationValueAddress, pHSensor.getCalibrationValue());
}
}
}



Dit is de library;

cpp code
#ifndef __ANALOG_PH_METER_H__
#define __ANALOG_PH_METER_H__

struct PHCalibrationValue {
char point;
float value[2];
int adc[2];
float slope;
int adcOffset;
};

class AnalogPHMeter {
private:
struct PHCalibrationValue calibrationValue;

unsigned int pin;
float pH;
float temperature;
bool debug;

bool stable;
unsigned char stableCount;
float precision;
unsigned char index;
float valueBefore, deltaValue, sumOfDeltaValue;
float deltaValueBuffer[10];

int readADC(int oversampling = 64);
void inputValue(float value);

public:
AnalogPHMeter(unsigned int pin);

AnalogPHMeter &initialize(struct PHCalibrationValue = (struct PHCalibrationValue){});

AnalogPHMeter &singleReading(void);
AnalogPHMeter &temperatureCompensation(float temperature);
AnalogPHMeter &calibration(void);
AnalogPHMeter &calibrationClear(void);
AnalogPHMeter &calibrationMid(float mid);
AnalogPHMeter &calibrationLow(float low);
AnalogPHMeter &calibrationHigh(float high);
AnalogPHMeter &factoryReset(void);

float getpH(void) { return this->pH; };
float getTemperature(void) { return this->temperature; };
float getCalibrationPoint(void) { return this->calibrationValue.point; };
struct PHCalibrationValue getCalibrationValue(void) {
return calibrationValue;
};

bool ispHStable(void) { return this->stable; };
void setpHPrecision(float precision) { this->precision = precision; };
};

#endif

#include <Arduino.h>
#include "AnalogPHMeter.h"

int AnalogPHMeter::readADC(int oversampling) {
long pHADCTotal = 0;

for (int i = 0; i < oversampling; i++) {
pHADCTotal += analogRead(pin);
}

return (int)(pHADCTotal / oversampling);
}

void AnalogPHMeter::inputValue(float value) {
sumOfDeltaValue -= deltaValueBuffer[index];
deltaValueBuffer[index] = value - valueBefore;
sumOfDeltaValue += deltaValueBuffer[index];
valueBefore = value;

if (++index == 10) index = 0;

if (-precision < sumOfDeltaValue && sumOfDeltaValue < precision)
stableCount++;
else
stableCount = 0;

stable = (stableCount > 10);
if (stable) stableCount = 10;
}

AnalogPHMeter::AnalogPHMeter(unsigned int pin) {
this->pin = pin;
this->pH = 0.00f;

this->stable = false;
this->stableCount = 0;
this->index = 0;
this->valueBefore = 0.00f;
for (size_t i = 0; i < sizeof(deltaValueBuffer) / sizeof(float); i++)
this->deltaValueBuffer[i] = 0.00f;
this->sumOfDeltaValue = 0.00f;
this->deltaValue = 0.00f;
this->precision = 0.050f;
}

AnalogPHMeter &AnalogPHMeter::initialize(struct PHCalibrationValue calibrationValue) {
this->calibrationValue = calibrationValue;
if (this->calibrationValue.point < '0' || '2' < this->calibrationValue.point ||
this->calibrationValue.adc[0] == 0 || this->calibrationValue.adc[1] == 0) {
this->calibrationValue.point = '0';
this->calibrationValue.value[0] = 7.000f;
this->calibrationValue.adc[0] = 410;
this->calibrationValue.value[1] = 4.000f;
this->calibrationValue.adc[1] = 112;
this->calibrationValue.slope = (this->calibrationValue.value[1] - this->calibrationValue.value[0]) /
(this->calibrationValue.adc[1] - this->calibrationValue.adc[0]);
this->calibrationValue.adcOffset = this->calibrationValue.adc[0] - (int)(this->calibrationValue.value[0] / this->calibrationValue.slope);
}

return *this;
}

AnalogPHMeter &AnalogPHMeter::singleReading(void) {
pH = calibrationValue.slope * (readADC() - calibrationValue.adcOffset);
inputValue(pH);

return *this;
}

AnalogPHMeter &AnalogPHMeter::temperatureCompensation(float temperature) {
this->temperature = temperature;

return *this;
}

AnalogPHMeter &AnalogPHMeter::calibration(void) {
return *this;
}

AnalogPHMeter &AnalogPHMeter::calibrationClear(void) {
calibrationValue.point = '0';
calibrationValue.value[0] = 7.000f;
calibrationValue.adc[0] = 410;
calibrationValue.value[1] = 4.000f;
calibrationValue.adc[1] = 112;
calibrationValue.slope = (calibrationValue.value[1] - calibrationValue.value[0]) /
(calibrationValue.adc[1] - calibrationValue.adc[0]);
calibrationValue.adcOffset = calibrationValue.adc[0] - (int)(calibrationValue.value[0] / calibrationValue.slope);

return *this;
}

AnalogPHMeter &AnalogPHMeter::calibrationMid(float mid) {
calibrationValue.point = '1';
calibrationValue.value[0] = mid;
calibrationValue.adc[0] = readADC();
calibrationValue.value[1] = 4.000f;
calibrationValue.adc[1] = calibrationValue.adc[0] - 302;
calibrationValue.slope = (calibrationValue.value[1] - calibrationValue.value[0]) /
(calibrationValue.adc[1] - calibrationValue.adc[0]);
calibrationValue.adcOffset = calibrationValue.adc[0] - (int)(calibrationValue.value[0] / calibrationValue.slope);

return *this;
}

AnalogPHMeter &AnalogPHMeter::calibrationLow(float low) {
calibrationValue.point = '2';
calibrationValue.value[1] = low;
calibrationValue.adc[1] = readADC();
calibrationValue.slope = (calibrationValue.value[1] - calibrationValue.value[0]) /
(calibrationValue.adc[1] - calibrationValue.adc[0]);
calibrationValue.adcOffset = calibrationValue.adc[0] - (int)(calibrationValue.value[0] / calibrationValue.slope);

return *this;
}

AnalogPHMeter &AnalogPHMeter::calibrationHigh(float high) {
calibrationValue.point = '2';
if (calibrationValue.point == '1') {
calibrationValue.value[1] = calibrationValue.value[0];
calibrationValue.adc[1] = calibrationValue.value[0];
}
calibrationValue.value[0] = high;
calibrationValue.adc[0] = readADC();
calibrationValue.slope = (calibrationValue.value[1] - calibrationValue.value[0]) /
(calibrationValue.adc[1] - calibrationValue.adc[0]);
calibrationValue.adcOffset = calibrationValue.adc[0] - (int)(calibrationValue.value[0] / calibrationValue.slope);

return *this;
}

AnalogPHMeter &AnalogPHMeter::factoryReset(void) {
calibrationClear();

return *this;
}

Advertisement

Gebruikers-avatar
Berichten: 5043
Geregistreerd: 13 Mei 2013, 20:57
Woonplaats: Heemskerk

Re: Fout in code?

Berichtdoor nicoverduin » 23 Jan 2018, 09:21

Jij moet toch zo langzamerhand wel weten dat je de foutboodschappen die je krijgt erbij moet zetten
Docent HBO Technische Informatica, Embedded ontwikkelaar & elektronicus
http://www.verelec.nl

Berichten: 340
Geregistreerd: 23 Okt 2016, 20:29

Re: Fout in code?

Berichtdoor benvo » 23 Jan 2018, 16:49

Oke Nico, bij dezen;

Arduino: 1.6.13 (Windows 10), Board:"Arduino/Genuino Uno"

C:\Users\ribe2\Documents\Arduino\AnalogPHMeter2\AnalogPHMeter2.ino: In function 'void setup()':

AnalogPHMeter2:17: error: no matching function for call to 'AnalogPHMeter::initialize(PHCalibrationValue&)'

pHSensor.initialize(pHCalibrationValue);

^

C:\Users\ribe2\Documents\Arduino\AnalogPHMeter2\AnalogPHMeter2.ino:17:41: note: candidate is:

In file included from C:\Users\ribe2\Documents\Arduino\AnalogPHMeter2\AnalogPHMeter2.ino:3:0:

C:\Users\ribe2\Documents\Arduino\libraries\AnalogPHMeter-master/AnalogPHMeter.h:35:18: note: AnalogPHMeter& AnalogPHMeter::initialize()

AnalogPHMeter &initialize(void);

^

C:\Users\ribe2\Documents\Arduino\libraries\AnalogPHMeter-master/AnalogPHMeter.h:35:18: note: candidate expects 0 arguments, 1 provided

C:\Users\ribe2\Documents\Arduino\AnalogPHMeter2\AnalogPHMeter2.ino: In function 'void loop()':

AnalogPHMeter2:57: error: 'class AnalogPHMeter' has no member named 'getCalibrationValue'

EEPROM.put(pHCalibrationValueAddress, pHSensor.getCalibrationValue());

^

exit status 1
no matching function for call to 'AnalogPHMeter::initialize(PHCalibrationValue&)'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Gebruikers-avatar
Berichten: 5043
Geregistreerd: 13 Mei 2013, 20:57
Woonplaats: Heemskerk

Re: Fout in code?

Berichtdoor nicoverduin » 23 Jan 2018, 20:51

Heb jij die oude lib opgeruimd? Of overschreven. Hij refereert naar een functie die helemaal niet in de library staat.....
Docent HBO Technische Informatica, Embedded ontwikkelaar & elektronicus
http://www.verelec.nl

Berichten: 340
Geregistreerd: 23 Okt 2016, 20:29

Re: Fout in code?

Berichtdoor benvo » 24 Jan 2018, 13:57

Deze lib's zaten bij het geupdated programma. Dit heb ik verder nog niet gebruikt omdat ik de fout niet kon herleiden. In het door mij gebruikte programma zitten een andere lib. Dit werkt op zich zonder fouten maar het programma doet iets niet goed. Om het niet te verwarrend te maken laat ik dat probleem nog maar even buiten beschouwing. Misschien is het goed dat ik mijn eigen programma laat zien. Hier is het PHprogramma deel aan- en ingepast in mijn programma dat ook op een Nextion scherm draait.

Code: Alles selecteren
#include <Nextion.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <RTClib.h>
#include <ChannelManager.h>
#include <EEPROM.h>
#include <AnalogPHMeter.h>


//Data aansluiting is aangesloten op pin 7 on the Arduino.
#define ONE_WIRE_BUS 7

// Legt een oneWire aan om te communiceren met elk oneWire apparaat.
OneWire oneWire(ONE_WIRE_BUS);

// Verbind onze oneWire referentie aan Dallas Temperature.
DallasTemperature sensors(&oneWire);

AnalogPHMeter pHSensor(A5);


//Zet de meters in NexGauge pointer

NexGauge lichtrood = NexGauge(0, 1, "z0");
NexGauge lichtblauw = NexGauge(0, 2, "z1");
NexGauge lichtwit = NexGauge (0, 3, "z2");
NexGauge pH = NexGauge(0, 4, "z3");
NexGauge temp = NexGauge(0, 5, "z4");





// ----------------------- Constanten -----------------------

const int MaxChannels = 3;       // Maximaal te gebruiken kanaalnummers, indien nodig te wijzigen naar meer of minder
const int MaxPoints = 25;        // Maximaal te gebruiken en in te voeren licht intensiteits punten, indien nodig te wijzigen in meer of minder
const int TxPin = 16;            //Tx ledPin op 16
const int numReadings = 10;      //aantal afgelezen monsters van de pH sensor/electrode.

// RTC
RTC_DS3231 rtc;

// Time
DateTime CurrentTime;

unsigned long temperatuurMillis;
unsigned long tijdMillis;
unsigned long updateMillis;


// ----------------------- Variabelen -----------------------

int phInt = 0;
int readings [numReadings];              //aflezingen van analoge ingang A2.
int readIndex = 0;                       //Arraypositie van de huidige pH sensor aflezing.
int total = 0;                           //het lopende totaal aantal aflezingen.
//int pHsensorPin = A5;                  //pin nummer verbonden met de Po uitgang van de pH sensormodule.

float average = 0;                         //het gemiddelde van de pH sensor aflezingswaarden.


int relaisPin = 8;                      //relais uitgang

float maxPH = 7.00;                    // Waarde hierboven zet de magneetklep open   

float minPH = 6.95;                    //waarde hieronder sluit de magneetklep

float x = 0;                           //Wordt gebruikt om temperatuurmetingswaarde in op te slaan.



// ----------------------- Licht -----------------------

// Invul wijze (Uur, Minuut, Intensiteit)
// De verschillen in intensiteit tussen de ingegeven punten zullen gradueel toenemen of afnemen.


Channel Channels[MaxChannels];
Point Points[MaxChannels][MaxPoints];


void InitializeChannels(int channels) {


  // Channel 0:
  int channelNo = 0;                               // Kanaal 0 wordt in gebruik genomen
  int redPin = 9;                                      // Kanaal 0 gebruikt  pin 9 voor de wit-rode balk
  Channels[channelNo] = Channel(redPin, MaxPoints, fademode_linear, Points[channelNo]);      // Initialiseerd kanaal en kiest de FadeMode
  Channels[channelNo].AddPoint(8, 30, 0);           // Voeg punt toe (Kunt ook decimale waarden gebruiken van 0 tot 1 als dat de voorkeur heeft)
  Channels[channelNo].AddPoint(9, 0, 76);
  Channels[channelNo].AddPoint(9 , 30, 204);
  Channels[channelNo].AddPoint(18, 30, 204);
  Channels[channelNo].AddPoint(20, 0, 76);
  Channels[channelNo].AddPoint(20, 30, 25);
  Channels[channelNo].AddPoint(21, 0, 10);
  Channels[channelNo].AddPoint(23, 0, 0);




  // Channel 1:In te voeren
  channelNo = 1;                                // Kanaal 1 wordt in gebruik genomen
  int bluePin = 10;                                     // Kanaal 1 gebruikt pin 10 voor de wit-blauwe balk
  Channels[channelNo] = Channel(bluePin, MaxPoints, fademode_linear, Points[channelNo]);
  Channels[channelNo].AddPoint(9, 0, 0);
  Channels[channelNo].AddPoint(9, 15, 76);
  Channels[channelNo].AddPoint(9, 30, 204);
  Channels[channelNo].AddPoint(18, 30, 204);
  Channels[channelNo].AddPoint(19, 30, 127);
  Channels[channelNo].AddPoint(20, 30, 51);
  Channels[channelNo].AddPoint(22, 0, 25);
  Channels[channelNo].AddPoint(23, 0, 0);



  // Channel 2:
  channelNo = 2;                              // Kanaal 2 wordt in gebruik genomen
  int whitePin = 11;                                   // Kanaal 2 gebruikt pin 11 voor de witte balk
  Channels[channelNo] = Channel(whitePin, MaxPoints, fademode_linear, Points[channelNo]);
  Channels[channelNo].AddPoint(9, 0, 0);
  Channels[channelNo].AddPoint(9, 15, 102);
  Channels[channelNo].AddPoint(9, 30, 204);
  Channels[channelNo].AddPoint(17, 30, 204);
  Channels[channelNo].AddPoint(17, 45, 102);
  Channels[channelNo].AddPoint(18, 00, 10);
  Channels[channelNo].AddPoint(18, 15, 0);




}

// ----------------------- Functies -----------------------


long lastUpdateTime = 0;

// Update licht intensiteit waarden

void UpdateLights(DateTime CurrentTime)
{
  long now = Seconds(CurrentTime.hour(), CurrentTime.minute(), CurrentTime.second());         // Zet de huidige tijd naar seconden sinds middernacht
  if (now != lastUpdateTime)                                                                 // Geeft alleen een update als er een duidelijk waarneembaar verschil in tijd.
  {
    for (int channel = 0; channel < MaxChannels; channel++)                                    // Voor elk kanaal
    {
      analogWrite(Channels[channel].GetPin(), Channels[channel].GetLightIntensityInt(now));   // Krijgt de geupdate licht intensiteit en schrijft de waarde naar de desbetreffende pin
      // update wordt uitgevoerd wanneer de waarde ingelezen wordt




      //Bereken  het percentage output gebaseerd op de huidige licht intensiteit.

      {

        int channel = 0;
        float intensityNow = Channels[channel].GetLightIntensityInt(now);
        float maxIntensity = 255;
        float a = intensityNow / maxIntensity;
        float currentPercent = a * 100;

        //omrekening lichtwaarde naar naar graden voor lichtschaal
        // licht in percentage is linear
        //licht uit (0) angle=-45 degrees
        //licht 100% aan angle=+225degrees
        //range light % is 100
        //range of angle is 270(225+45)
        //float intensity
        float angle = (currentPercent / 100.0 * 270.0) - 45.0;
        if (angle < 0)                          //Als de stand lager is dan 0 en dus negatief wordt.
        {
          angle += 360;                         //maak een positief aantal graden voor de meter
        }
        int rood = int(angle);
        lichtrood.setValue(rood);
      }

      {
        int channel = 1;
        float intensityNow = Channels[channel].GetLightIntensityInt(now);
        float maxIntensity = 255;
        float a = intensityNow / maxIntensity;
        float currentPercent = a * 100;


        //omrekening lichtwaarde naar naar graden voor lichtschaal
        // licht in percentage is linear
        //licht uit (0) angle=-45 degrees
        //licht 100% aan angle=+225degrees
        //range light % is 100
        //range of angle is 270(225+45)
        //float intensity
        float angle = (currentPercent / 100.0 * 270.0) - 45.0;
        if (angle < 0)                            //Als de stand lager is dan 0 en dus negatief wordt.
        {
          angle += 360;                           //maak een positief aantal graden voor de meter
        }
        int blauw = int(angle);
        lichtblauw.setValue(blauw);
      }

      {
        int channel = 2;
        float intensityNow = Channels[channel].GetLightIntensityInt(now);
        float maxIntensity = 255;
        float a = intensityNow / maxIntensity;
        float currentPercent = a * 100;

        //omrekening lichtwaarde naar naar graden voor lichtschaal
        // licht in percentage is linear
        //licht uit (0) angle=-45 degrees
        //licht 100% aan angle=+225degrees
        //range light % is 100
        //range of angle is 270(225+45)
        //float intensity
        float angle = (currentPercent / 100.0 * 270.0) - 45.0;
        if (angle < 0)                               //Als de stand lager is dan 0 en dus negatief wordt.
        {
          angle += 360;                              //maak een positief aantal graden voor de meter
        }
        int wit = int(angle);
        lichtwit.setValue(wit);
      }
    }
  }
  lastUpdateTime = now;
}


// Converteerd de uren:minuten naar seconden sinds middernacht

long Seconds(int hours, int minutes, int seconds) {
  return ((long)hours * 60 * 60) + (minutes * 60) + seconds ;
}

//-------------------- pagina 1 -------------------------------

NexButton b0 = NexButton(0, 6, "b0");                 //knop Instellingen
NexButton b2 = NexButton(1, 2, "b2");                 //knop plus maximum pH
NexButton b3 = NexButton(1, 3, "b3");                 //knop min maximum pH
NexButton b4 = NexButton(1, 4, "b4");                 //knop plus minimum pH
NexButton b5 = NexButton(1, 5, "b5");                 //knop min minimum pH
NexButton for_c = NexButton(1, 6, "b6");              //knop "Clear"
NexButton for_l = NexButton(1, 7, "b7");              //knop "pH 4.0"
NexButton for_m = NexButton(1, 8, "b8");              //knop "pH 7.0"
NexButton for_h = NexButton(1, 9, "b9");              //knop "pH 10.0"



//Declaratie tekstvelden

//Op de homepagina 0

NexText t0 = NexText(0, 11, "t0");                     //uren, minuten en seconden
NexText t1 = NexText(0, 12, "t1");                     //dag, maand en jaar


//Op pagina 1

NexText t11 = NexText(1, 11, "t11");                    //maximum pH
NexText t12 = NexText(1, 12, "t12");                    //minimum pH
NexText t10 = NexText(1, 10, "t10");                    //pH kalibratie waarde


//buffer definities

char buffer_pHtemp[10];                                  //buffer pH sensor
char buffer_maxPH[10];                                   //buffer pH maximum instel waardes
char buffer_minPH[10];                                   //buffer pH minimum instel waardes

// Registeer een button object op de touch event lijst.

NexTouch *nex_listen_list[] =
{
  &b0,
  &b2,
  &b3,
  &b4,
  &b5,
  &for_c,
  &for_l,
  &for_m,
  &for_h,
  &t0,
  &t1,
  &t10,
  &t11,
  &t12,
  NULL
};





//------------ pagina 1 Instellingen en kalibratie pH ----------------
void b0PopCallback(void*ptr)
{
  dtostrf(maxPH, 5, 2, buffer_maxPH);                  //drukt maxPH af.
  t11.setText(buffer_maxPH);

  dtostrf(minPH, 5, 2, buffer_minPH);                   //drukt minPH af.
  t12.setText(buffer_minPH);
}

void t11PopCallback(void*ptr)
{
  dtostrf(maxPH, 5, 2, buffer_maxPH);                  //drukt maxPH af.
  t11.setText(buffer_maxPH);
}

void t12PopCallback(void*ptr)
{
  dtostrf(minPH, 5, 2, buffer_minPH);                  //drukt minPH af.
  t12.setText(buffer_minPH);
}

void b2PopCallback(void*ptr)
{
  maxPH += 0.01;
  dtostrf(maxPH, 5, 2, buffer_maxPH);
  t11.setText(buffer_maxPH);
}

void b3PopCallback(void*ptr)
{
  maxPH -= 0.01;
  dtostrf(maxPH, 5, 2, buffer_maxPH);
  t11.setText(buffer_maxPH);
}

void b4PopCallback(void*ptr)
{
  minPH += 0.01;
  dtostrf(minPH, 5, 2, buffer_minPH);
  t12.setText(buffer_minPH);
}

void b5PopCallback(void*ptr)
{
  minPH -= 0.01;
  dtostrf(minPH, 5, 2, buffer_minPH);
  t12.setText(buffer_minPH);
}

void PopCallback_c(void*ptr)
{
  pHSensor.calibrationClear();                           //Clear
}

void PopCallback_l(void*ptr)
{
  pHSensor.calibrationLow(4.000f);                       //pH 4
}

void PopCallback_m(void*ptr)
{
  pHSensor.calibrationMid(7.000f);                       //pH 7
}

void PopCallback_h(void*ptr)
{
  pHSensor.calibrationHigh(10.000f);                     //pH 10
}








// ----------------------- Setup -----------------------
void setup()
{
  Wire.begin();

  // Klok
  rtc.begin();


  //Zet de baudrate nodig voor de communicatie met het Nextion scherm
  nexInit();
  //merkt de tekstvensters op.
 
  t11.attachPop(t11PopCallback, &t11);
  t12.attachPop(t12PopCallback, &t12);
 
  //Merkt de losgelaten knop op.
 
  b0.attachPop(b0PopCallback, &b0);
  b2.attachPop(b2PopCallback, &b2);
  b3.attachPop(b3PopCallback, &b3);
  b4.attachPop(b4PopCallback, &b4);
  b5.attachPop(b5PopCallback, &b5);

  for_c.attachPop(PopCallback_c, &for_c);
  for_l.attachPop(PopCallback_l, &for_l);
  for_m.attachPop(PopCallback_m, &for_m);
  for_h.attachPop(PopCallback_h, &for_h);




  //Pin is uitgang
  pinMode(TxPin, OUTPUT);                                   //TxPin wordt als uitgang gebruikt.
  pinMode(relaisPin, OUTPUT);                               //relaisPin wordt als uitgang gebruikt
 

  sensors.begin();                                          //Start de Temperatuurlibrary/sensor


  pHSensor.initialize();                                    //Start de pH sensor


  // Initialiseer de kanaal schema's
  InitializeChannels(MaxChannels);

  //rtc.adjust(DateTime(2018,1,20,10,33,0));                  // Stelt de RTC tijd in op de sketch samenstelling, wordt gebruikt voor één run. De tijd wordt gereset op het moment dat een apparaat wordt gereset!
 
}


// ----------------------- Loop -----------------------


void loop(void)
{

  nexLoop(nex_listen_list);


  // Stelt in op de huidige tijd

  CurrentTime = rtc.now();

  //------------- temperatuurmeting -----------------

  unsigned long huidigeTemp = millis();
  if (huidigeTemp - temperatuurMillis >= 6000)
  {
    sensors.requestTemperatures();                            // Zend het commando om de temperatuurmeting te halen.
    x = sensors.getTempCByIndex(0);                           //Zet de verkregen waarde in x



    //Omrekening waarde naar graden voor de temperatuurschaal
    // Temperature (linear)
    // temperature = 0, angle = -45 degrees
    // temperature = 50, angle = +225 degrees.
    // range of temperature is 50
    // range of angle is 270 (225 + 45)
    //float temperature;
    float angle = (x / 50.0 * 270.0) - 45.0;
    int degrees = int(angle);
    temp.setValue(degrees);
    if (angle < 0)                                             //Als de stand lager is dan 0 en dus negatief wordt.
    {
      angle += 360;                                            //maak een positief aantal graden voor de meter
    }
    temperatuurMillis = huidigeTemp;
  }



  //--------------------- pH waarden meting  --------------------------

  static unsigned long t = millis();
  if (millis() - t > 1000)
  {


    float pHvalue = (pHSensor.singleReading().getpH());
    total = total - readings[readIndex];                       //Trek van de laatste pH sensor aflezing af.
    readings[readIndex] = pHvalue * 100;                       //Leest de pH waarde in.
    total = total + readings[readIndex];                       //Voeg de pH sensor aflezing toe aan het totaal.
    readIndex = readIndex + 1;                                 //Vooruit naar de volgende positie in de array.

    if ( readIndex >= numReadings)                             //Als we aan het einde van de array staan...
    {
      readIndex = 0;                                           //...ga terug naar het begin.
    }
    average = total / numReadings;                             //Bereken het gemiddelde.

    pHvalue = average / 100;


    dtostrf(pHvalue, 5, 2, buffer_pHtemp);                     //conversie pH value naar een string
    t10.setText(buffer_pHtemp);

    if (pHvalue >= maxPH)                                     //Als de gemeten pH waarde groter is dan de maxPH waarde
    {
      digitalWrite(relaisPin, LOW);                           //relais is aangetrokken, magneetklep open. CO2 toevoer.
    }

    if (pHvalue <= minPH)                                     //Als de gemeten pH waarde kleiner is dan de minPH waarde
    {
      digitalWrite(relaisPin, HIGH);                          //relais is open, magneetklep gesloten. Geen CO2 toevoer.
    }


    //omrekening naar ronde meter

    phInt = pHvalue * 100;                                   // alles met 100 vermenigvulden om een heel getal te hebben
    signed int graden = map (phInt, 600, 850, -45, 225);     // nu heb je de graden

    if (graden < 0)                                          // Als de stand lager is als nul en dus negatief wordt.
    {
      graden += 360;                                        // maak een positief aantal graden voor de meter
    }

    pH.setValue(graden);                                    //zet de meternaald
    t = millis();
  }


  // Tijd en datum update
  unsigned long huidigetijdMillis = millis();
  if (huidigetijdMillis - tijdMillis > 1000)
  {
    DateTime now = rtc.now();
    char tijdString[9];
    static char vorigeTijd[9];

    sprintf(tijdString, "%02d:%02d:%02d", now.hour(), now.minute(), now.second());

    if (strcmp(tijdString, vorigeTijd) != 0)
    {
      t0.setText (tijdString);                              //Tijd update
      strcpy(vorigeTijd, tijdString);                       //Bewaar vorigeTijd voor de volgende vergelijking
    }



    char datumString[9];
    static char vorigeDatum[9];

    sprintf(datumString, "%02d-%02d-%02d", now.day(), now.month(), now.year());

    if (strcmp(datumString, vorigeDatum) != 0)
    {
      t1.setText (datumString);                            //Datum update
      strcpy(vorigeDatum, datumString);                    //Bewaar vorigeDatum voor de volgende vergelijking
    }
    tijdMillis = huidigetijdMillis;
  }

  // Update lights
  unsigned long huidigeupdateMillis = millis();
  if (huidigeupdateMillis - updateMillis > 10000)
  {
    UpdateLights(CurrentTime);
    updateMillis = huidigeupdateMillis;
  }
}




Ook hierbij de gebruikte PH lib.

#include "AnalogPHMeter.h"
#include <Arduino.h>
#include <EEPROM.h>

int AnalogPHMeter::readADC(int oversampling) {
long pHADCTotal = 0;

for (int i = 0; i < oversampling; i++) {
pHADCTotal += analogRead(pin);
}

return (int)(pHADCTotal / oversampling);
}

void AnalogPHMeter::inputValue(float value) {
sumOfDeltaValue -= deltaValueBuffer[index];
deltaValueBuffer[index] = value - valueBefore;
sumOfDeltaValue += deltaValueBuffer[index];
valueBefore = value;

if(++index == 10) index = 0;

if(-precision < sumOfDeltaValue && sumOfDeltaValue < precision) stableCount++;
else stableCount = 0;

stable = (stableCount > 10);
if (stable) stableCount = 10;
}

AnalogPHMeter::AnalogPHMeter(unsigned int pin, unsigned int eepromAddress) {
this->pin = pin;
this->eepromAddress = eepromAddress;
this->pH = 0.00f;

this->stable = false;
this->stableCount = 0;
this->index = 0;
this->valueBefore = 0.00f;
for (size_t i = 0; i < sizeof(deltaValueBuffer)/sizeof(float); i++)
this->deltaValueBuffer[i] = 0.00f;
this->sumOfDeltaValue = 0.00f;
this->deltaValue = 0.00f;
this->precision = 0.050f;
}

AnalogPHMeter &AnalogPHMeter::initialize(void) {
EEPROM.get(eepromAddress, calibrationValue);
if (calibrationValue.point < '0' || '2' < calibrationValue.point ||
calibrationValue.adc[0] == 0 || calibrationValue.adc[1] == 0) {
calibrationValue.point = '0';
calibrationValue.value[0] = 7.000f;
calibrationValue.adc[0] = 410;
calibrationValue.value[1] = 4.000f;
calibrationValue.adc[1] = 112;
calibrationValue.slope = (calibrationValue.value[1] - calibrationValue.value[0]) /
(calibrationValue.adc[1] - calibrationValue.adc[0]);
calibrationValue.adcOffset = calibrationValue.adc[0] - (int)(calibrationValue.value[0] / calibrationValue.slope);
EEPROM.put(eepromAddress, calibrationValue);
}

return *this;
}

AnalogPHMeter &AnalogPHMeter::singleReading(void) {
pH = calibrationValue.slope * (readADC() - calibrationValue.adcOffset);
inputValue(pH);

return *this;
}

AnalogPHMeter &AnalogPHMeter::temperatureCompensation(float temperature) {
this->temperature = temperature;

return *this;
}

AnalogPHMeter &AnalogPHMeter::calibration(void) {
EEPROM.get(eepromAddress, calibrationValue);

return *this;
}

AnalogPHMeter &AnalogPHMeter::calibrationClear(void) {
calibrationValue.point = '0';
calibrationValue.value[0] = 7.000f;
calibrationValue.adc[0] = 410;
calibrationValue.value[1] = 4.000f;
calibrationValue.adc[1] = 112;
calibrationValue.slope = (calibrationValue.value[1] - calibrationValue.value[0]) /
(calibrationValue.adc[1] - calibrationValue.adc[0]);
calibrationValue.adcOffset = calibrationValue.adc[0] - (int)(calibrationValue.value[0] / calibrationValue.slope);
EEPROM.put(eepromAddress, calibrationValue);

return *this;
}

AnalogPHMeter &AnalogPHMeter::calibrationMid(float mid) {
calibrationValue.point = '1';
calibrationValue.value[0] = mid;
calibrationValue.adc[0] = readADC();
calibrationValue.value[1] = 4.000f;
calibrationValue.adc[1] = calibrationValue.adc[0] - 302;
calibrationValue.slope = (calibrationValue.value[1] - calibrationValue.value[0]) /
(calibrationValue.adc[1] - calibrationValue.adc[0]);
calibrationValue.adcOffset = calibrationValue.adc[0] - (int)(calibrationValue.value[0] / calibrationValue.slope);
EEPROM.put(eepromAddress, calibrationValue);

return *this;
}

AnalogPHMeter &AnalogPHMeter::calibrationLow(float low) {
calibrationValue.point = '2';
calibrationValue.value[1] = low;
calibrationValue.adc[1] = readADC();
calibrationValue.slope = (calibrationValue.value[1] - calibrationValue.value[0]) /
(calibrationValue.adc[1] - calibrationValue.adc[0]);
calibrationValue.adcOffset = calibrationValue.adc[0] - (int)(calibrationValue.value[0] / calibrationValue.slope);
EEPROM.put(eepromAddress, calibrationValue);

return *this;
}

AnalogPHMeter &AnalogPHMeter::calibrationHigh(float high) {
calibrationValue.point = '2';
calibrationValue.value[0] = high;
calibrationValue.adc[0] = readADC();
calibrationValue.slope = (calibrationValue.value[1] - calibrationValue.value[0]) /
(calibrationValue.adc[1] - calibrationValue.adc[0]);
calibrationValue.adcOffset = calibrationValue.adc[0] - (int)(calibrationValue.value[0] / calibrationValue.slope);
EEPROM.put(eepromAddress, calibrationValue);

return *this;
}

AnalogPHMeter &AnalogPHMeter::factoryReset(void) {
calibrationClear();

return *this;
}
en deze:

#ifndef __ANALOG_PH_METER_H__
#define __ANALOG_PH_METER_H__

struct PHCalibrationValue {
char point;
float value[2];
int adc[2];
float slope;
int adcOffset;
};

class AnalogPHMeter {
private:
struct PHCalibrationValue calibrationValue;

unsigned int pin;
unsigned int eepromAddress;
float pH;
float temperature;
bool debug;

bool stable;
unsigned char stableCount;
float precision;
unsigned char index;
float valueBefore, deltaValue, sumOfDeltaValue;
float deltaValueBuffer[10];

int readADC(int oversampling = 64);
void inputValue(float value);

public:
AnalogPHMeter(unsigned int pin, unsigned int eepromAddress = 0);

AnalogPHMeter &initialize(void);

AnalogPHMeter &singleReading(void);
AnalogPHMeter &temperatureCompensation(float temperature);
AnalogPHMeter &calibration(void);
AnalogPHMeter &calibrationClear(void);
AnalogPHMeter &calibrationMid(float mid);
AnalogPHMeter &calibrationLow(float low);
AnalogPHMeter &calibrationHigh(float high);
AnalogPHMeter &factoryReset(void);

float getpH(void) { return this->pH; };
float getTemperature(void) { return this->temperature; };
float getCalibrationPoint(void) { return this->calibrationValue.point; };

bool ispHStable(void) { return this->stable; };
void setpHPrecision(float precision) { this->precision = precision; };
};

#endif

Gebruikers-avatar
Berichten: 5043
Geregistreerd: 13 Mei 2013, 20:57
Woonplaats: Heemskerk

Re: Fout in code?

Berichtdoor nicoverduin » 24 Jan 2018, 21:16

Inderdaad je dus hebt een dubbele library......
Docent HBO Technische Informatica, Embedded ontwikkelaar & elektronicus
http://www.verelec.nl

Berichten: 340
Geregistreerd: 23 Okt 2016, 20:29

Re: Fout in code?

Berichtdoor benvo » 30 Jan 2018, 19:10

nicoverduin schreef:Inderdaad je dus hebt een dubbele library......


Helaas weet ik nog niet precies hoe het zit maar door wat onderzoeken die nadelig uitvielen zal ik enige tijd in het ziekenhuis moeten doorbrengen. Graag wil ik hier wat later op terugkomen.

Gebruikers-avatar
Berichten: 2655
Geregistreerd: 06 Aug 2016, 01:03

Re: Fout in code?

Berichtdoor Koepel » 01 Feb 2018, 01:10

Beterschap.
Je Arduino-buddies wensen je alle goeds.

Berichten: 340
Geregistreerd: 23 Okt 2016, 20:29

Re: Fout in code?

Berichtdoor benvo » 07 Feb 2018, 14:49

Koepel schreef:Beterschap.
Je Arduino-buddies wensen je alle goeds.



Dank je wel, Koepel!

De oplossing voor de fouten is gevonden.
Nico heeft de goede oplossing aangedragen, er zijn Libraries, in elk geval voor een deel, overschreven. Wel op een heel vreemde manier. Ik had de oude Library, zoals ik dacht, wel weggehaald maar, gek genoeg, niet compleet. Op een heel gekke manier was er een stukje, in mijn documenten, achtergebleven. Door de Library uit te printen een regel voor regel na te zien vond ik dit deel. Raar, maar wel mijn eigen schuld.
Goed, het werkt in elk geval. Dank, Nico voor je terechte aanwijzing!

Terug naar Overige Software

Wie is er online?

Gebruikers in dit forum: Google [Bot] en 6 gasten