I am still continuing my hydroponic nutrient monitoring project. In short, I made a hydroponic nutrient monitoring system with I2C connection, and decided to do serial communication with Raspberry Pi 3B+ to save sensor reading data in CSV file. I am curious about why after uploading the sketch, the sensors always gives zero values at first reading on Serial Monitor.
This is the screenshot of my Serial Monitor.
From left to right: timestamp, EC, pH, Temperature.
Everytime I reset the Arduino, the Serial Monitor first will show no values. On the second line, it shows only EC value. The third line only EC and pH value, then the fourth line and so on will show all values.
How to make the Arduino show all sensor values from the start in the Serial Monitor?
Here is my code that I modified from Atlas Scientific page for my project:
#include <Ezo_i2c.h>
#include <Wire.h>
Ezo_board ec = Ezo_board(100, "EC");
Ezo_board ph = Ezo_board(99, "PH");
Ezo_board temp = Ezo_board(102, "RTD");
bool reading_request_phase = true;
uint32_t next_poll_time = 0;
const unsigned int response_delay = 1000;
void setup()
{
Serial.begin(9600);
Wire.begin();
delay(1000);
}
void loop() {
if (reading_request_phase)
{
ec.send_read_cmd();
ph.send_read_cmd();
temp.send_read_cmd();
next_poll_time = millis() + response_delay;
reading_request_phase = false;
}
else
{
if (millis() >= next_poll_time)
{
receive_reading(ec);
receive_reading(ph);
receive_reading(temp);
reading_request_phase = true;
}
}
}
void receive_reading(Ezo_board &Sensor) {
Sensor.receive_read_cmd();
Serial.println();
Serial.print(ec.get_last_received_reading()/1000);
Serial.print(",");
Serial.print(ph.get_last_received_reading());
Serial.print(",");
Serial.print(temp.get_last_received_reading());
Serial.print("");
delay(1000);
}