IOT program wont function when uploaded on web editor

the sketch uploads, but i keep getting "PH: NO_DATA" in the serial monitor.
the ezo board flashes red which indicates "command not understood" according to the manufacturers datasheet. The pH EZO board is connected via I2C. Im using mkr 1010 and atlas scientific ph probe and EZO circuit.

a similar sketch without the generated IOT and wifi code works offline and gives me a reading so i know the hardware is working.

/* 
  Sketch generated by the Arduino IoT Cloud Thing "pH_Test"
  https://create.arduino.cc/cloud/things/6717560a-59d1-488f-8f50-7565b0301cea 

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  float phIOT;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"
#include <Ezo_i2c.h>                      // Link: https://github.com/Atlas-Scientific/Ezo_I2c_lib)
#include <Wire.h>                         //include arduinos i2c library
 
Ezo_board PH = Ezo_board(99, "PH");       //create a PH circuit object, who's address is 99 and name is "PH"
 
bool reading_request_phase = true;        //selects our phase
 
uint32_t next_poll_time = 0;              //holds the next time we receive a response, in milliseconds
const unsigned int response_delay = 1000; //how long we wait to receive a response, in milliseconds
 

void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  Serial.println("begin");
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500); 
  Wire.begin();                           //start the I2C

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}

void loop() {
  ArduinoCloud.update();
  // Your code here 
  if (reading_request_phase)             //if were in the phase where we ask for a reading
  {
    //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();
 
    next_poll_time = millis() + response_delay;         //set when the response will arrive
    reading_request_phase = false;                      //switch to the receiving phase
  }
  else                                                //if were in the receiving phase
  {
    if (millis() >= next_poll_time)                    //and its time to get the response
    {
      receive_reading(PH);                              //get the reading from the PH circuit
 
      reading_request_phase = true;                     //switch back to asking for readings
    }
  }
}
 
void receive_reading(Ezo_board &Sensor)                // function to decode the reading after the read command was issued
{
 
  Serial.print(Sensor.get_name());  // print the name of the circuit getting the reading
  Serial.print(": ");
 
  Sensor.receive_read_cmd();                                //get the response data and put it into the [Sensor].reading variable if successful
 
  switch (Sensor.get_error())                          //switch case based on what the response code is.
  {
    case Ezo_board::SUCCESS:
      Serial.println(Sensor.get_last_received_reading());               //the command was successful, print the reading
      phIOT = Sensor.get_last_received_reading();
      break;
 
    case Ezo_board::FAIL:
      Serial.print("Failed ");                          //means the command has failed.
      break;
 
    case Ezo_board::NOT_READY:
      Serial.print("Pending ");                         //the command has not yet been finished calculating.
      break;
 
    case Ezo_board::NO_DATA:
      Serial.print("No Data ");                         //the sensor has no data to send.
      break;
  }
  Serial.print("ph float: ");
  Serial.println(phIOT);
}

Verbose output.txt (1.4 MB)

Either the wiring is wrong (which we cannot check because you didn't provide a wiring diagram) or the I2C address is wrong. As 99 is the default I2C address of the EZO pH board I assume it's the wiring.

Another possibility is that you switched the circuit into UART mode which would also explain the error you get.

The EZO circuit is showing blue light for I2C mode, and the offline sketch works with current wiring configuation. There's 4 wires, a positive plugged into the 5v of the mkr, a negative plugged into the ground, scl to scl, sda to sda. im not sure how the wiring would need to be dfferent between an online sketch and an offline sketch.

The sketch works with an esp32, but ideally i can get it to work on the mkr1010 as im relying on it for over air uploading and other features

Post the offline sketch that works with exactly the same wiring and hardware!

#include <Ezo_i2c.h>                   // Link: https://github.com/Atlas-Scientific/Ezo_I2c_lib)
#include <Wire.h>                         //include arduinos i2c library
 
Ezo_board PH = Ezo_board(99, "PH");       //create a PH circuit object, who's address is 99 and name is "PH"
 
bool reading_request_phase = true;        //selects our phase
 
uint32_t next_poll_time = 0;              //holds the next time we receive a response, in milliseconds
const unsigned int response_delay = 1000; //how long we wait to receive a response, in milliseconds

float phIOT;
 
void setup()
{
  Wire.begin();                           //start the I2C
  Serial.begin(9600);                     //start the serial communication to the computer at baud rate of 9600
}
 
void loop()
{
  if (reading_request_phase)             //if were in the phase where we ask for a reading
  {
    //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();
 
    next_poll_time = millis() + response_delay;         //set when the response will arrive
    reading_request_phase = false;                      //switch to the receiving phase
  }
  else                                                //if were in the receiving phase
  {
    if (millis() >= next_poll_time)                    //and its time to get the response
    {
      receive_reading(PH);                              //get the reading from the PH circuit
 
      reading_request_phase = true;                     //switch back to asking for readings
    }
  }
}
 
void receive_reading(Ezo_board &Sensor)                // function to decode the reading after the read command was issued
{
 
  Serial.print(Sensor.get_name());  // print the name of the circuit getting the reading
  Serial.print(": ");
 
  Sensor.receive_read_cmd();                                //get the response data and put it into the [Sensor].reading variable if successful
 
  switch (Sensor.get_error())                          //switch case based on what the response code is.
  {
    case Ezo_board::SUCCESS:
      Serial.println(Sensor.get_last_received_reading());               //the command was successful, print the reading
      phIOT = Sensor.get_last_received_reading();
      break;
 
    case Ezo_board::FAIL:
      Serial.print("Failed ");                          //means the command has failed.
      break;
 
    case Ezo_board::NOT_READY:
      Serial.print("Pending ");                         //the command has not yet been finished calculating.
      break;
 
    case Ezo_board::NO_DATA:
      Serial.print("No Data ");                         //the sensor has no data to send.
      break;
  }

  Serial.print("float ph: ");
  Serial.println(phIOT);
}

If that code works on the identical hardware setup, the hardware seems to be extremely timing critical. The only difference in the relevant code part is that you call the update() method of the ArduinoIoT instance in every loop round and that may slightly delay the rest of the code. This is unexpected for me but I don't have that hardware to try myself.

Print the value of millis() each time receive_reading is called (in the online version). Post the results. It will be interesting to see the timing of that setup.

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