-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
011e056
commit 0761918
Showing
8 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
68 changes: 68 additions & 0 deletions
68
Arduino to Pi Testing/pump_primer/pump_primer.ino/pump_primer.ino.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
101 changes: 101 additions & 0 deletions
101
Arduino to Pi Testing/wired_to_pi_no_PMP3/wired_to_pi_no_PMP3/wired_to_pi_no_PMP3.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
Binary file not shown.