ArduinoGeneral

SENO0169 Showing nan or inf

userHead Account cancelled 2019-01-04 19:47:17 7582 Views7 Replies
Hi,

I could it to work with the pH meter sample code v1.0 though I saw there was a newer version with the EC included (which I'll order once I know this is working. It says all I need to do is put it into ph 4 or 7 calibration liquid, which I have and all I'm getting is inf and if I do try CALPH is fails. I run the eeprom_clear code with no luck.

I also saw on another thread here for EC part of it to run the code below, doing so seems to make the reading go into the EC part of the Serialmonitor. I've added the V2.0 code at the bottom also.

Any help would be greatly appreciated!

Drew.

Code: Select all
#include <EEPROM.h>
#define KVALUEADDR 0x0A
void setup(){
for(byte i = 0;i< 8; i++ ){
EEPROM.write(KVALUEADDR+i, 0xFF);
}
}
void loop(){
}
Code: Select all
/*
 * file DFRobot_PH_EC.ino
 * @ https://github.com/DFRobot/DFRobot_PH
 *
 * This is the sample code for The Mixed use of two sensors: 
 *       1、Gravity: Analog pH Sensor / Meter Kit V2, SKU:SEN0161-V2
 *       2、Analog Electrical Conductivity Sensor / Meter Kit V2 (K=1.0), SKU: DFR0300.
 * In order to guarantee precision, a temperature sensor such as DS18B20 is needed, to execute automatic temperature compensation.
 * You can send commands in the serial monitor to execute the calibration.
 * Serial Commands:
 *
 *  PH Calibration:
 *   enterph -> enter the PH calibration mode
 *   calph   -> calibrate with the standard buffer solution, two buffer solutions(4.0 and 7.0) will be automaticlly recognized
 *   exitph  -> save the calibrated parameters and exit from PH calibration mode
 *
 *  EC Calibration:
 *   enterec -> enter the EC calibration mode
 *   calec   -> calibrate with the standard buffer solution, two buffer solutions(1413us/cm and 12.88ms/cm) will be automaticlly recognized
 *   exitec  -> save the calibrated parameters and exit from EC calibration mode
 *
 * Copyright   [DFRobot](http://www.dfrobot.com), 2018
 * Copyright   GNU Lesser General Public License
 *
 * version  V1.0
 * date  2018-04
 */

#include "DFRobot_PH.h"
#include "DFRobot_EC.h"
#include <EEPROM.h>

#define PH_PIN A1
#define EC_PIN A2
float  voltagePH,voltageEC,phValue,ecValue,temperature = 25;
DFRobot_PH ph;
DFRobot_EC ec;

void setup()
{
    Serial.begin(115200);  
    ph.begin();
    ec.begin();
}

void loop()
{
    char cmd[10];
    static unsigned long timepoint = millis();
    if(millis()-timepoint>1000U){                            //time interval: 1s
        timepoint = millis();
        //temperature = readTemperature();                   // read your temperature sensor to execute temperature compensation
        voltagePH = analogRead(PH_PIN)/1024.0*5000;          // read the ph voltage
        phValue    = ph.readPH(voltagePH,temperature);       // convert voltage to pH with temperature compensation
        Serial.print("pH:");
        Serial.print(phValue,2);
        voltageEC = analogRead(EC_PIN)/1024.0*5000;
        ecValue    = ec.readEC(voltageEC,temperature);       // convert voltage to EC with temperature compensation
        Serial.print(", EC:");
        Serial.print(ecValue,2);
        Serial.println("ms/cm");
    }
    if(readSerial(cmd)){
        strupr(cmd);
        if(strstr(cmd,"PH")){
            ph.calibration(voltagePH,temperature,cmd);       //PH calibration process by Serail CMD
        }
        if(strstr(cmd,"EC")){
            ec.calibration(voltageEC,temperature,cmd);       //EC calibration process by Serail CMD
        }
    }
}

int i = 0;
bool readSerial(char result[]){
    while(Serial.available() > 0){
        char inChar = Serial.read();
        if(inChar == '\n'){
             result[i] = '\0';
             Serial.flush();
             i=0;
             return true;
        }
        if(inChar != '\r'){
             result[i] = inChar;
             i++;
        }
        delay(1);
    }
    return false;
}

float readTemperature()
{
  //add your code here to get the temperature from your temperature sensor
}

I saw on another thread it was suggested
2020-11-10 11:04:05 @slergos
It is strange. On my UNO board, I copy your code and upload it. It works fine. The readings are correct. Do you have a UNO board to test the same code? Thanks.
userHeadPic Youyou
2020-10-24 18:03:37 Same problem here !
i have recently bought an Analog pH Sensor/Meter Kit V2 SKU:SEN0161-V2
for a hydroponic controller project.
The controller I use for this project is Arduino Nano Every.
ti seems that the library you provide for this sensor is not functional for this controller.
when i'm done with hardware setup (sensors directly connected to controller via hook up wires) and upload the sketch i got the right readings on serial monitor for temperature and Ph voltage , on Ph conversion i get nan or inf outputs.
i have tried the same code on a second brand new arduino nano every , with clean EEPROM but i always get the same result.
Is there any functional library for this controller or any modifications that i can do on the library you provide to solve the problem ?
Ph sketch is attached.
Thank you .
sketch :
Code: Select all
//PH Sensor (SKU:SEN0161-V2)
#include "DFRobot_PH.h"
#include <EEPROM.h>
#define PH_PIN 14
float voltage,phValue,temperature = 25;
DFRobot_PH ph;

//Temperature sensor (LM35)
const int lm35_pin = 20;         //* LM35 pin
int LM_Temperature_sensor_read;

void setup()
{
Serial.begin(115200);
//Ph Sensor.  
  ph.begin();

// LM35 Sensor.
 pinMode(lm35_pin, INPUT);  
}

void loop()
{
    static unsigned long timepoint = millis();
    if(millis()-timepoint>1000U)                          //time interval: 1s
    {
      timepoint = millis();
      voltage = analogRead(PH_PIN)/1024.0*5000;        // read the voltage
      LM_Temperature_sensor_read = analogRead(lm35_pin);
      temperature = (LM_Temperature_sensor_read*0.488);   // read your temperature sensor to execute temperature compensation
      phValue = ph.readPH(voltage,temperature);        // convert voltage to pH with temperature compensation
      Serial.print("temperature:");
      Serial.print(temperature,1);
      Serial.print(" C  ");
      Serial.print("voltage: ");
      Serial.print(voltage,2);
      Serial.print("  pH:");
      Serial.println(phValue,3);
    }
    ph.calibration(voltage,temperature);               // calibration process by Serail CMD
}
userHeadPic slergos
2019-09-12 18:56:56 It seems that some special values in the EEPROM, which cuase the problem. Would you like to clear all EEPROMs, then upload the sample code? userHeadPic Youyou
2019-08-19 14:03:01 Hi, I have the same problem calibrating my pH sensor with buffer solutions and use the exact same wiring and calibration code from DFRobot. I’m using Arduino Uno Board with sensor V2 module

[https://github.com/DFRobot/DFRobotMedia ... SEN0161-V2]

However, the serial monitor prints pH: nan or sometimes pH: inf

Can anyone help me resolve this issue? Cheers
userHeadPic amirulhafizan1995
2019-01-07 14:29:27 For the pH sensor, the V1.0 code can not work with V2.0 sensor, you can not use together. userHeadPic robert.chen