Coder Social home page Coder Social logo

ezo_i2c_lib's Introduction

Ezo_I2c_lib

Library for using Atlas Scientific EZO devices in I2C mode

Instructions

To use the library with Arduino, follow this link.

For instructions on how to set up the devices in I2C mode, see this instructable

See our instructables page to learn how to assemble the hardware for some of the examples

Documentation

//errors
enum errors {SUCCESS, FAIL, NOT_READY, NO_DATA, NOT_READ_CMD};

//constructors
Ezo_board(uint8_t address);	 //Takes I2C address of the device
Ezo_board(uint8_t address, const char* name); 
//Takes I2C address of the device
//as well a name of your choice
Ezo_board(uint8_t address, TwoWire* wire); //Takes I2C address and TwoWire interface
Ezo_board(uint8_t address, const char* name, TwoWire* wire); //Takes all 3 parameters

void send_cmd(const char* command);	
//send any command in a string, see the devices datasheet for available i2c commands

void send_read_cmd();	
//sends the "R" command to the device and sets issued_read() to true, 
//so we know to parse the data when we receive it with receive_read()

void send_cmd_with_num(const char* cmd, float num, uint8_t decimal_amount = 3);
//sends any command with the number appended as a string afterwards.
//ex. PH.send_cmd_with_num("T,", 25.0); will send "T,25.000"

void send_read_with_temp_comp(float temperature);
//sends the "RT" command with the temperature converted to a string
//to the device and sets issued_read() to true, 
//so we know to parse the data when we receive it with receive_read()

enum errors receive_cmd(char* sensordata_buffer, uint8_t buffer_len); 
//receive the devices response data into a buffer you supply.
//Buffer should be long enough to hold the longest command 
//you'll receive. We recommand 32 bytes/chars as a default

enum errors receive_read_cmd(); 
//gets the read response from the device, and parses it into the reading variable
//if send_read() wasn't used to send the "R" command and issued_read() isnt set, the function will 
//return the "NOT_READ_CMD" error

bool is_read_poll();		
//function to see if issued_read() was set. 
//Useful for determining if we should call receive_read() (if is_read_poll() returns true) 
//or receive_cmd() if is_read_poll() returns false) 

float get_last_received_reading();		
//returns the last reading the device received as a float

const char* get_name();		
//returns a pointer to the name string. This gets the name given to the object by the constructor
//not the device name returned by the "name,?" command. 
//To get the device name use [device].send_cmd("name,?") and read the response with receive_cmd

uint8_t get_address();
//returns the address of the device
    
void set_address(uint8_t address);
//lets you change the I2C address of the device

enum errors get_error();	
//returns the error status of the last received command, 
//used to check the validity of the data returned by get_reading()

Ezo_i2c_util

Common functions used by Atlas Scientific Ezo sample code for printing various responses and info that would otherwise be duplicated in many examples.

void print_device_info(Ezo_board &Device);
//prints the name and address of the given device

void print_success_or_error(Ezo_board &Device, const char* success_string);
//prints different responses depending on whether the device has successfully 
//recieved its message or not
//for the error case, where the device gets an improper command, it prints "Failed "
//for the not ready case, where the device isnt done processing the command, it prints "Pending "
//for the no data case, where it cannot communicate with the device, it prints "No Data "
//if the message is received correctly it prints the success_string that's passed in. This can be used
//to print the reading in cases where the command succeeds for example

void receive_and_print_reading(Ezo_board &Device);
//used to handle receiving readings and printing them in a common format
//typical use case is calling it 1 second after sending the send_read_cmd function from the Ezo_i2c_lib

void receive_and_print_response(Ezo_board &Device);
//used to handle receiving responses and printing them in a common format
//typical use case is calling it after sending commands like send_cmd or send_cmd_with_num 
//from the Ezo_i2c_lib and waiting the appropriate amount of time for the command

iot_cmd

Common functions used by Atlas Scientific Ezo sample code to receive user commands and send them to the circuits included in the IOT kits

bool receive_command(String &string_buffer);
//used to receive commands from the serial port, print them,
//strip them of whitespace, and uppercase them to get them ready for processing
//returns true if a command was received and false if it wasn't

void process_command(const String &string_buffer, Ezo_board device_list[], 
                     uint8_t device_list_len, Ezo_board* default_board);
void process_command(const String &string_buffer, Ezo_board* device_list[], 
                     uint8_t device_list_len, Ezo_board* &default_board);
//handles the common functions of the IOT kit command processing
//such as listing boards, sending commands to one or all boards, and
//switching which board commands are sent to by default
                     
void list_devices(Ezo_board device_list[], uint8_t device_list_len, Ezo_board* default_board);
void list_devices(Ezo_board* device_list[], uint8_t device_list_len, Ezo_board* default_board);
//prints a list of all the boards in the device list array, with an arrow showing which board is
//the default board

void iot_cmd_print_listcmd_help();
//prints the help section for the list command

void iot_cmd_print_allcmd_help();
//prints the help section for the all query

void iot_cmd_print_namedquery_help();
//prints the help section for the named reference query 

Sequencer libs

Several classes that allow easy sequencing of events without blocking. Useful for timer based events, running code concurrently, and allowing serial communication in scenarios where long delays would impede it. See the examples for how to work with this library.

ezo_i2c_lib's People

Contributors

atlas-scientific avatar jrhemmen avatar moritz89 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ezo_i2c_lib's Issues

Compile Failure

Was getting an error while trying to compile with Arduino IDE 1.8.15.

Had to add
case Ezo_board::NOT_READ_CMD:
Serial.print("No Command "); //no command
break;
to switch statement in "print_success_or_error" in Ezo_i2c_util.cpp

No longer works with Arduino Web editor

It would be really nice to use the Atlas Scientific ezo_I2c_lib for work along side the Arduino cloud services however, due to the requirement of being on a web browser in order to import the library it requires a library.properties file is there a way to add the file to the current library?

Address offset from I2C scanner

Using an Arduino Mega and the I2C scanner sketch from Arduino IDE, I get addresses that are minus 1 the addresses that I use with EZO i2c lib.

Eg : The i2c scanner returns the value 0x63 for my peristaltic pump which is 99 in decimal, But using the EZO, I must use the address 100. This is true for all my Atlas Scientific devices.

Is it because EZO addresses are index based 1 instead of 0?

Calibrating doesn't return Ok

Running any calibration command is not returning Ok status, but the sensor name and pin number only:

ph:cal,mid,7
-PH: 99

Despite this, the calibration works.

Help with process_command

Hi,
i need help to calibrate the probes from a webpage and not from the Serial Monitor.
( i have developed a full web based configurable Pool-Control-System for people without any Arduino Skills)

I found the Void: process_command:
process_command(const String &string_buffer, Ezo_board device_list[], uint8_t device_list_len, Ezo_board* &default_board)

I think this is the correct void to calibrate the Probes.
I found my probes are ID:0=PH ID:1=ORP and ID:2=RTD
I think the string_buffer i changed to e.g. "ORP:CAL,225"

But i didnt know how exactly i can fill it with correct values that it works.
Can somebody explain how i can solve this ?
Tnx

Error Compliling

I am getting a call of overload is ambiguous error.

/home/kb001/sketchbook/libraries/Ezo_I2c_lib/Ezo_i2c.cpp: In member function ‘void Ezo_board::send_cmd_with_num(const char*, float, uint8_t)’:
/home/kb001/sketchbook/libraries/Ezo_I2c_lib/Ezo_i2c.cpp:33:56: error: call of overloaded ‘String(float&, uint8_t&)’ is ambiguous
String temp = String(cmd )+ String(num, decimal_amount);
^
In file included from /usr/share/arduino/hardware/arduino/cores/arduino/Arduino.h:192:0,
from /home/kb001/sketchbook/libraries/Ezo_I2c_lib/Ezo_i2c.h:28,
from /home/kb001/sketchbook/libraries/Ezo_I2c_lib/Ezo_i2c.cpp:2:
/usr/share/arduino/hardware/arduino/cores/arduino/WString.h:70:11: note: candidate: String::String(long unsigned int, unsigned char)
explicit String(unsigned long, unsigned char base=10);
^
/usr/share/arduino/hardware/arduino/cores/arduino/WString.h:69:11: note: candidate: String::String(long int, unsigned char)
explicit String(long, unsigned char base=10);
^
/usr/share/arduino/hardware/arduino/cores/arduino/WString.h:68:11: note: candidate: String::String(unsigned int, unsigned char)
explicit String(unsigned int, unsigned char base=10);
^
/usr/share/arduino/hardware/arduino/cores/arduino/WString.h:67:11: note: candidate: String::String(int, unsigned char)
explicit String(int, unsigned char base=10);
^
/usr/share/arduino/hardware/arduino/cores/arduino/WString.h:66:11: note: candidate: String::String(unsigned char, unsigned char)
explicit String(unsigned char, unsigned char base=10);
^

Getting status messages from pumps?

How would you send a "Status" or "?PV" command to a pump and read the response?

I'm thinking it it related to receive_cmd, maybe an example of using this function could be useful.

Edit: for example how do I read the response of PH_PUMP.send_cmd("Pv,?");?

Wrong comments, likely copy-pasted

I noticed the following comments do not seem to match the code they describe. Looks like they were copy-pasted from the pH examples and not updated.

Ezo_board EC = Ezo_board(100, "EC"); //create a PH circuit object, who's address is 99 and name is "PH"

Ezo_board EC = Ezo_board(100, "EC"); //create a PH circuit object, who's address is 99 and name is "PH"

Salinity example code

Could you please upload an example for salinity calculation from conductivity and temperature sensors.
Thanks

Problem with OLED display library

I run I2c_read_mulitple_circuits.ino (with little modifications) with no issues but when adding an OLED display on the same I2C bus readings are 0.
The library I use U8g2

I am using TTGO LoRa32 v2.1.6 Board. ttgo lora32 v2.1.6 Board

This is the code, with #define OLED enable or disable the OLED.

#define OLED
#include <Ezo_i2c.h> //include the EZO I2C library from https://github.com/Atlas-Scientific/Ezo_I2c_lib
#include <Wire.h>    //include arduinos i2c library
#include <sequencer2.h> //imports a 2 function sequencer 
#include <Ezo_i2c_util.h> //brings in common print statements

Ezo_board PH = Ezo_board(99, "PH");       //create a PH circuit object, who's address is 99 and name is "PH"
Ezo_board EC = Ezo_board(100, "EC");      //create an EC circuit object who's address is 100 and name is "EC"
Ezo_board RTD = Ezo_board(102, "RTD");      //create an EC circuit object who's address is 100 and name is "EC"
Ezo_board DO = Ezo_board(97, "DO");
Ezo_board ORP = Ezo_board(98, "ORP");

void step1();  //forward declarations of functions to use them in the sequencer before defining them
void step2();

Sequencer2 Seq(&step1, 1000, &step2, 1000);  //calls the steps in sequence with time in between them

/* OLED display setup*************************************************/
#ifdef OLED
#include <U8x8lib.h>  //https://github.com/olikraus/u8g2
U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(/*rst*/ U8X8_PIN_NONE);
#endif

void setup() {
#ifdef OLED
  u8x8.begin();
  u8x8.setFont(u8x8_font_chroma48medium8_r);
  u8x8.drawString(0, 0, "Start");
  delay(1000);
  u8x8.setPowerSave(1); //LCD off
#endif
  Wire.begin(); //start the I2C
//  Wire.setClock(100000L);//400000L
  Serial.begin(115200);                     //start the serial communication to the computer

  Seq.reset();                            //initialize the sequencer
}

void loop() {
  Seq.run();                              //run the sequncer to do the polling
}

void step1() {
  //send a read command. we use this command instead of PH.send_cmd("R");
  //to let the library know to parse the reading
  PH.send_read_cmd();
  EC.send_read_cmd();
  RTD.send_read_cmd();
  DO.send_read_cmd();
  ORP.send_read_cmd();
}

void step2() {
  receive_and_print_reading(RTD);             //get the reading from the PH circuit
  Serial.print("  ");
  receive_and_print_reading(DO);             //get the reading from the PH circuit
  Serial.print("  ");
  receive_and_print_reading(ORP);             //get the reading from the PH circuit
  Serial.print("  ");
  receive_and_print_reading(PH);             //get the reading from the PH circuit
  Serial.print("  ");
  receive_and_print_reading(EC);             //get the reading from the EC circuit
  Serial.println();

  EC.send_cmd("Sleep");
  DO.send_cmd("Sleep");
  PH.send_cmd("Sleep");
  ORP.send_cmd("Sleep");
  RTD.send_cmd("Sleep");
  
#ifdef OLED
  float pH1 = PH.get_last_received_reading();
  float EC1 = EC.get_last_received_reading();
  float DO1 = DO.get_last_received_reading();
  float ORP1 = ORP.get_last_received_reading();
  float Temp = RTD.get_last_received_reading();

  u8x8.setPowerSave(0); //LCD on
  String stra;
  stra = "pH:" + String(pH1, 1);
  u8x8.drawString(0, 1, stra.c_str());
  stra = "T:" + String(Temp); //Temp
  u8x8.drawString(0, 2, stra.c_str());
  stra = "DO:" + String(DO1);
  u8x8.drawString(0, 3, stra.c_str());
  stra = "ORP:" + String(ORP1);
  u8x8.drawString(0, 4, stra.c_str());
  stra = "EC:" + String(EC1);
  u8x8.drawString(0, 5, stra.c_str());
  delay(1000);
  u8x8.setPowerSave(1); //LCD off
#endif
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.