#include a EC-probe Libraries

Hi Particles,

I just started working with Particle Photon and the IDE it includes. My first project is to calibrate an EC-probe. I found the code in on the product information site: https://wiki.dfrobot.com/Gravity__Analog_Electrical_Conductivity_Sensor___Meter_V2__K=1__SKU_DFR0300

I copied it and paste it into the code section in particle WEB IDE.
When I try to verify the code it states DFRobot_EC.h: No such file or directory
How do I include this library?

Here is the full code

/*
 * file DFRobot_EC.ino
 * @ https://github.com/DFRobot/DFRobot_EC
 *
 * This is the sample code for Gravity: 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:
 *   enter -> enter the calibration mode
 *   cal -> calibrate with the standard buffer solution, two buffer solutions(1413us/cm and 12.88ms/cm) will be automaticlly recognized
 *   exit -> save the calibrated parameters and exit from calibration mode
 *
 * Copyright   [DFRobot](https://www.dfrobot.com), 2018
 * Copyright   GNU Lesser General Public License
 *
 * version  V1.0
 * date  2018-03-21
 */




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

#define EC_PIN A1
float voltage,ecValue,temperature = 25;
DFRobot_EC ec;

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

void loop()
{
    static unsigned long timepoint = millis();
    if(millis()-timepoint>1000U)  //time interval: 1s
    {
      timepoint = millis();
      voltage = analogRead(EC_PIN)/1024.0*5000;  // read the voltage
      //temperature = readTemperature();  // read your temperature sensor to execute temperature compensation
      ecValue =  ec.readEC(voltage,temperature);  // convert voltage to EC with temperature compensation
      Serial.print("temperature:");
      Serial.print(temperature,1);
      Serial.print("^C  EC:");
      Serial.print(ecValue,2);
      Serial.println("ms/cm");
    }
    ec.calibration(voltage,temperature);  // calibration process by Serail CMD
}

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

If the library doesn’t already exist in the library repository of Web IDE (image ) you’d need to add some extra files to your project via this button image in the top right corner and copy/past the respective code for .h and .cpp.

The original Arduino library may require some slight porting.

I tried adding the .h and .app files to the new taps. Still get the same error message. I also tried to edit the Include Arduino with Particle.

You can post a SHARE THIS REVISION link for us to have a look at your project as is.

Here you go :slight_smile:

You have named your new files lib1.h and lib1.cpp but you are including DFRobot_EC.h - naming the new files the way you intend to include them or include them as you have named them would be a good idea :wink:

When done that right, you should remove all #include <EEPROM.h> lines - as they are not needed with Particle.h already included - and your code should build.

Thank you for the advice :slight_smile: now I cancelled all the include <EEPROM.h> lines. Now the IDE is complaning about not including the 'EEPROM_read' was not declared in this scope and 'EEPROM_write' was not declared in this scope shold i also delete does?

It’s not complaining on my side tho’
These macros are defined in DFRobot_EC.cpp and that should also be the only place where they are used, so I wouldn’t see why you get these errors (unless you also deleted these definitions :wink: )

Have you got another link to share?

I think I fixed it now :slight_smile: but I will attach a link again. https://go.particle.io/shared_apps/5f69e30f5e1db50017c501d7

Now my next target is to serial monitor the values from the EC probe. should I use the Particle Workbench on my computer instead?

Having Workbench available is never a mistake :wink:

However, you can use any serial terminal program (e.g. PuTTY) or even Particle CLI particle serial monitor --follow to see the output of the device - although the latter is only a monitor and cannot send data to the device.

Hi ScruffR, thank you so much for all the guidance! I have now tried to edit the serial.print out with the Particle.publish. I now get alt of error messages when I try to compile? :confused:

You may want to read the docs for Particle.publish() again.
The first and second parameter can only be string types. You are using numeric datatypes - that’s what the error messages mean: “There is no function that would take these types there”.
And you can only publish at a rate of 1 publish per second on average (burst of 4 back to back publishes is possible with a 4 second cool down).

What you want to do there would be best done with a single publish like this

  char msg[128];
  snprintf(msg, sizeof(msg), "Temp: %.1f °C, EC: %.2f ms/cm", temperature, ecValue);
  Particle.publish("EC_Probe", msg, PRIVATE);

Hi again ScruffR,

one again thank you soo much for your guidance! I have one more question: what are the f for behind 1 and 2 ind the code?

These are the datatype place holders for float or double variables.
Have a look at this printf() reference

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.