Skip to content

Commit

Permalink
New pump control
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanclewis committed Nov 13, 2024
1 parent 011e056 commit 0761918
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 0 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified Arduino to Pi Testing/.DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include <Wire.h>
#include <Ezo_i2c.h>

// Define the pumps
Ezo_board PMP1 = Ezo_board(56, "PMP1"); // pH up
Ezo_board PMP2 = Ezo_board(57, "PMP2"); // pH down
Ezo_board PMP3 = Ezo_board(58, "PMP3"); // Nutrient pump

// Track the state of each pump
bool pmp1_running = false;
bool pmp2_running = false;
bool pmp3_running = false;

void setup() {
Serial.begin(9600);
Wire.begin();
Serial.println("Enter pump number (1, 2, or 3) to toggle it on/off.");
}

void loop() {
if (Serial.available() > 0) {
char command = Serial.read();

switch (command) {
case '1': // Toggle PMP1
if (!pmp1_running) {
PMP1.send_cmd("d,100"); // Start PMP1 with indefinite dispensing rate
pmp1_running = true;
Serial.println("PMP1 ON");
} else {
PMP1.send_cmd("d,0"); // Stop PMP1
pmp1_running = false;
Serial.println("PMP1 OFF");
}
break;

case '2': // Toggle PMP2
if (!pmp2_running) {
PMP2.send_cmd("d,100"); // Start PMP2 with indefinite dispensing rate
pmp2_running = true;
Serial.println("PMP2 ON");
} else {
PMP2.send_cmd("d,0"); // Stop PMP2
pmp2_running = false;
Serial.println("PMP2 OFF");
}
break;

case '3': // Toggle PMP3
if (!pmp3_running) {
PMP3.send_cmd("d,100"); // Start PMP3 with indefinite dispensing rate
pmp3_running = true;
Serial.println("PMP3 ON");
} else {
PMP3.send_cmd("d,0"); // Stop PMP3
pmp3_running = false;
Serial.println("PMP3 OFF");
}
break;

default:
Serial.println("Invalid input. Enter 1, 2, or 3 to toggle a pump.");
break;
}
}

delay(100); // Short delay to avoid rapid serial checks
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#include <Wire.h>
#include <Ezo_i2c.h>

// Define the sensors and pumps
Ezo_board PH = Ezo_board(99, "PH");
Ezo_board EC = Ezo_board(100, "EC");
Ezo_board RTD = Ezo_board(102, "RTD");
Ezo_board PMP1 = Ezo_board(56, "PMP1"); // pH up
Ezo_board PMP2 = Ezo_board(57, "PMP2"); // pH down

// Thresholds for pump control
float PH_LOWER_LIMIT = 5.5;
float PH_UPPER_LIMIT = 6.5;
float EC_LOWER_LIMIT = 1000.0;
float EC_UPPER_LIMIT = 2000.0;
float PUMP_DOSE = -0.5; // Example dose

void setup() {
Serial.begin(9600);
Wire.begin();
Serial.println("Arduino Ready"); // Signal that Arduino is ready
}

void loop() {
if (Serial.available() > 0) {
char command = Serial.read();
if (command == 'R') { // 'R' for Read sensors
poll_sensors();
}
else if (command == 'P') { // 'P' for Pump control
control_pumps();
}
}
delay(100); // Small delay for stability
}

// Function to read and print sensor values
void poll_sensors() {
float ph_value = read_ph();
float ec_value = read_ec();
float temp_value = read_temp();

Serial.print("pH: "); Serial.println(ph_value);
Serial.print("EC: "); Serial.println(ec_value);
Serial.print("Temperature: "); Serial.println(temp_value);
}

// Function to control pumps based on thresholds
void control_pumps() {
float ph_value = read_ph();

// pH control logic
if (ph_value < PH_LOWER_LIMIT) {
Serial.println("pH below limit. Triggering PMP1...");
PMP1.send_cmd_with_num("d,", PUMP_DOSE); // Dispense pH up
} else if (ph_value > PH_UPPER_LIMIT) {
Serial.println("pH above limit. Triggering PMP2...");
PMP2.send_cmd_with_num("d,", PUMP_DOSE); // Dispense pH down
} else {
Serial.println("pH is within range.");
}
}

// Function to read pH value
float read_ph() {
char sensordata_buffer[32];
PH.send_read_cmd();
delay(1000); // Wait for sensor response
if (PH.receive_cmd(sensordata_buffer, sizeof(sensordata_buffer)) == Ezo_board::SUCCESS) {
return String(sensordata_buffer).toFloat();
} else {
Serial.println("Error reading pH sensor.");
return -1;
}
}

// Function to read EC value
float read_ec() {
char sensordata_buffer[32];
EC.send_read_cmd();
delay(1000);
if (EC.receive_cmd(sensordata_buffer, sizeof(sensordata_buffer)) == Ezo_board::SUCCESS) {
return String(sensordata_buffer).toFloat();
} else {
Serial.println("Error reading EC sensor.");
return -1;
}
}

// Function to read Temperature value
float read_temp() {
char sensordata_buffer[32];
RTD.send_read_cmd();
delay(1000);
if (RTD.receive_cmd(sensordata_buffer, sizeof(sensordata_buffer)) == Ezo_board::SUCCESS) {
return String(sensordata_buffer).toFloat();
} else {
Serial.println("Error reading Temperature sensor.");
return -1;
}
}
Binary file modified Engine/.DS_Store
Binary file not shown.
Binary file added Engine/wired_to_pi_v5/.DS_Store
Binary file not shown.

0 comments on commit 0761918

Please sign in to comment.