Atlas-Scientific / Ezo_I2c_lib

Library for using Atlas Scientific EZO devices in I2C mode
MIT License
65 stars 39 forks source link

Getting status messages from pumps? #4

Closed servetcoskun closed 5 years ago

servetcoskun commented 5 years ago

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,?");?

servetcoskun commented 5 years ago

Alright found a solution which I though would be nice to share. To save messages something similar to the following will work. Remember to modify the following parameters if you wish to try and run the example.

The command "Pv,?" should return the voltage on the motor of your peristaltic pump

char sensordata[30];
uint8_t buffer_len = 30;
Ezo_board PH_PUMP = Ezo_board(103, "PH_PUMP");

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

void loop() {
  if (reading_request_phase) {
    PH_PUMP.send_cmd("Pv,?");
    next_poll_time = millis() + response_delay;
    reading_request_phase = false;
  }
  else {                             
    if (millis() >= next_poll_time) {
      PH_PUMP.receive_cmd(sensordata, 30);
      Serial.print(sensordata);
      reading_request_phase = true;
    }
  }
}