-
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
5ed3011
commit 011e056
Showing
9 changed files
with
148 additions
and
218 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
135 changes: 0 additions & 135 deletions
135
Arduino to Pi Testing/wired_to_pi_v2/wired_to_pi_v2/wired_to_pi_v2.ino
This file was deleted.
Oops, something went wrong.
83 changes: 0 additions & 83 deletions
83
Arduino to Pi Testing/wired_to_pi_v3/wired_to_pi_v3/wired_to_pi_v3.ino
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
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,35 @@ | ||
import serial | ||
from datetime import datetime | ||
import time | ||
|
||
# Initialize serial connection to Arduino | ||
ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=1) | ||
time.sleep(2) # Wait for the serial connection to stabilize | ||
|
||
# Log file path | ||
log_file_path = '/home/openstem/Desktop/openstem_ethan/pump_control_log.txt' | ||
|
||
# Function to log messages to a text file | ||
def log_message(message): | ||
with open(log_file_path, 'a') as log_file: | ||
log_file.write(f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')} - {message}\n") | ||
|
||
# Function to trigger pump control on Arduino | ||
def trigger_pump_control(): | ||
try: | ||
ser.write(b'P') # Send 'P' command to trigger pump control | ||
time.sleep(5) # Wait for Arduino to process and respond | ||
|
||
# Read and log Arduino responses | ||
while ser.in_waiting > 0: | ||
line = ser.readline().decode('utf-8').strip() | ||
log_message(line) | ||
print(line) | ||
log_message("Pump control command executed successfully.") | ||
|
||
except Exception as e: | ||
log_message(f"Error: {str(e)}") | ||
|
||
# Execute pump control (3 minute delay to allow for sensor reading and uploading) | ||
time.sleep(180) | ||
trigger_pump_control() |
113 changes: 113 additions & 0 deletions
113
Engine/wired_to_pi_v5/wired_to_pi_v5/wired_to_pi_v5.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,113 @@ | ||
#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 | ||
Ezo_board PMP3 = Ezo_board(58, "PMP3"); // Nutrients | ||
|
||
// 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(); | ||
float ec_value = read_ec(); | ||
|
||
// 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."); | ||
} | ||
|
||
// EC control logic | ||
if (ec_value < EC_LOWER_LIMIT) { | ||
Serial.println("EC below limit. Triggering PMP3..."); | ||
PMP3.send_cmd_with_num("d,", PUMP_DOSE); // Dispense nutrients | ||
} else if (ec_value > EC_UPPER_LIMIT) { | ||
Serial.println("EC above limit. Notification only."); | ||
} else { | ||
Serial.println("EC 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; | ||
} | ||
} |