Skip to content
Extraits de code Groupes Projets
Valider 7f8cf376 rédigé par Simon Collignon's avatar Simon Collignon
Parcourir les fichiers

restructuring

parent 19d5d880
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Pipeline #77829 annulé
Affichage de
avec 7 ajouts et 193 suppressions
env
__pycache__
\ No newline at end of file
Fichier déplacé
env
float valve_percent;
float scale_factor = (4096-1)/100.0;
int avg_depth = 32;
void setup() {
// put your setup code here, to run once:
pinMode(A0, OUTPUT); // sets the pin as output
pinMode(A1, INPUT);
Serial.begin(1000000);
}
void loop() {
// put your main code here, to run repeatedly:
if (Serial.available() > 0) {
char command = Serial.read();
if (command == 'u') { // write command
//--- actuate solenoid valve ---
float valve_percent = 0.0;
String data = Serial.readStringUntil('\n'); // Read the incoming data until newline
char *ptr = strtok(const_cast<char*>(data.c_str()), ",");
valve_percent = atof(ptr);
set_signal(valve_percent);
//--- read pressure
analogReadResolution(14);
int x = analogRead(A1);
for (int i = 0; i < avg_depth-1; i++) {
analogReadResolution(14);
x += analogRead(A1);
}
Serial.println(x/avg_depth);
}
else if (command == 'r') {
set_signal(0.0);
}
}
}
void set_signal(float valve_percent) {
// IMPORTANT NOTE: it has been observed that the reset signal
// doesn't function properly with a 5 V logic high signal (arduino's default).
// A resistive voltage divider is required to set the logic high to 3.3 V.
analogWriteResolution(12);
analogWrite(A0, int(scale_factor*valve_percent));
}
numpy==2.1.3
pyqtgraph==0.13.7
pyserial==3.5
PySide6==6.8.0.2
PySide6_Addons==6.8.0.2
PySide6_Essentials==6.8.0.2
shiboken6==6.8.0.2
simple-pid==2.0.1
Fichier déplacé
Fichier déplacé
Fichier déplacé
Fichier déplacé
Fichier déplacé
Fichier déplacé
Fichier déplacé
import serial
import serial.tools.list_ports
import time
SERIAL_NUMBER : str = "3307142A37323835191D33324B572D44"
# ser = serial.Serial("/dev/tty.usbmodem1101", 9600)
def find_device(serial_number:str) -> str:
"""Check the `hwid` through the list ports for a `SER` key
that matches `serial_number`
"""
for port, desc, hwid in serial.tools.list_ports.comports():
infos = hwid.split(" ")
for info in infos:
if not info.startswith("SER"):
continue
serial_num = info.split("=")[-1]
if not serial_num == serial_number:
break
return port
return ""
MY_PORT : str = find_device(SERIAL_NUMBER)
print(MY_PORT)
device = serial.Serial()
device.port = MY_PORT
device.timeout = 1
device.baudrate = 9600
device.open()
def write_value(valve_percent:float):
device.write(b'w')
data = str(valve_percent)
device.write(data.encode() + b'\n')
def read_value():
device.write(b'r')
time.sleep(0.1)
response = float(device.readline().decode().strip())
return response
def read_pressure():
device.write(b'p')
time.sleep(0.1)
response = float(device.readline().decode().strip())
return response
if __name__ == "__main__":
while True:
print("Enter valve opening percentage:")
valve_percent = input()
if float(valve_percent) < 0:
break
write_value(valve_percent)
print(read_value())
# print(read_pressure())
device.close()
asttokens==2.4.1
colorama==0.4.6
comm==0.2.1
contourpy==1.2.0
cycler==0.12.1
debugpy==1.8.0
decorator==5.1.1
distlib==0.3.7
executing==2.0.1
filelock==3.13.1
fonttools==4.44.0
future==1.0.0
greenlet==3.0.3
ipykernel==6.28.0
ipympl==0.9.3
ipython==8.20.0
ipython-genutils==0.2.0
ipywidgets==8.1.2
iso8601==2.1.0
jedi==0.19.1
jupyter_client==8.6.0
jupyter_core==5.7.1
jupyterlab_widgets==3.0.10
kiwisolver==1.4.5
llvmlite==0.43.0
matplotlib==3.8.1
matplotlib-inline==0.1.6
mendeleev==0.15.0
mpmath==1.3.0
nest-asyncio==1.5.8
numba==0.60.0
numpy==1.26.1
packaging==23.2
pandas==2.2.0
parso==0.8.3
Pillow==10.1.0
platformdirs==3.11.0
prompt-toolkit==3.0.43
psutil==5.9.7
pure-eval==0.2.2
pyfiglet==0.8.post1
Pygments==2.17.2
pyparsing==3.1.1
PyQt5==5.15.10
PyQt5-Qt5==5.15.2
PyQt5-sip==12.13.0
numpy==2.1.3
pyqtgraph==0.13.7
pyserial==3.5
python-dateutil==2.8.2
pytz==2024.1
pywin32==306
PyYAML==6.0.2
pyzmq==25.1.2
qutip==5.0.3.post1
rdkit==2024.3.3
scipy==1.11.3
six==1.16.0
SQLAlchemy==2.0.25
stack-data==0.6.3
sympy==1.12.1
tornado==6.4
traitlets==5.14.1
typing_extensions==4.9.0
tzdata==2023.4
virtualenv==20.25.1
wcwidth==0.2.13
widgetsnbextension==4.0.10
PySide6==6.8.0.2
PySide6_Addons==6.8.0.2
PySide6_Essentials==6.8.0.2
shiboken6==6.8.0.2
simple-pid==2.0.1
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter