forked from tanchou/Verilog
Refactor LED handling in fpga_wifi_led module and remove obsolete readSerial.py script
This commit is contained in:
@@ -22,7 +22,7 @@ module fpga_wifi_led (
|
||||
wire tx_fifo_full;
|
||||
|
||||
// === SIGNAUX INTERNES ===
|
||||
reg [5:0] leds_reg;
|
||||
reg [3:0] leds_reg;
|
||||
reg [1:0] state;
|
||||
reg [7:0] received_byte;
|
||||
|
||||
@@ -59,11 +59,13 @@ module fpga_wifi_led (
|
||||
);
|
||||
|
||||
// === ASSIGNATION DES LEDS ===
|
||||
assign o_leds = ~leds_reg;
|
||||
assign o_leds [3:0] = ~leds_reg;
|
||||
assign o_leds[5] = o_tx;
|
||||
assign o_leds[4] = i_rx;
|
||||
|
||||
// === INITIALISATION ===
|
||||
initial begin
|
||||
leds_reg = 6'b000000;
|
||||
leds_reg = 4'b0000;
|
||||
state = IDLE;
|
||||
rx_rd_en = 0;
|
||||
tx_wr_en = 0;
|
||||
@@ -110,7 +112,7 @@ module fpga_wifi_led (
|
||||
state <= SEND_RESPONSE;
|
||||
end else begin
|
||||
// Commande non reconnue, éteindre toutes les LEDs
|
||||
leds_reg <= 6'b000000;
|
||||
leds_reg[2:0] <= 3'b111;
|
||||
state <= IDLE;
|
||||
end
|
||||
end
|
||||
|
28
Semaine_7/ESP32/leds_commands/tests/pyhton/connectESP.py
Normal file
28
Semaine_7/ESP32/leds_commands/tests/pyhton/connectESP.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import socket
|
||||
import time
|
||||
|
||||
# Remplace cette IP par celle affichée par l'ESP32 dans le terminal série
|
||||
ESP32_IP = "192.168.1.105"
|
||||
ESP32_PORT = 1234
|
||||
|
||||
def send_bytes(commands):
|
||||
try:
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
print(f"Connexion a {ESP32_IP}:{ESP32_PORT}...")
|
||||
s.connect((ESP32_IP, ESP32_PORT))
|
||||
print("Connecté.")
|
||||
|
||||
for cmd in commands:
|
||||
if isinstance(cmd, str):
|
||||
cmd = int(cmd, 16) # Exemple : "0x01"
|
||||
print(f"Envoi : 0x{cmd:02X}")
|
||||
s.send(bytes([cmd]))
|
||||
time.sleep(0.1) # Petite pause pour laisser respirer le FPGA
|
||||
|
||||
print("Tous les octets ont été envoyés.")
|
||||
except Exception as e:
|
||||
print("Erreur :", e)
|
||||
|
||||
# Exemple d'envoi
|
||||
commands = [0x02] # Tu peux aussi faire ["0x01", "0x96", "0xA4"]
|
||||
send_bytes(commands)
|
@@ -1,30 +0,0 @@
|
||||
import serial
|
||||
import time
|
||||
|
||||
# Configuration du port série
|
||||
ser = serial.Serial(
|
||||
port='/dev/ttyUSB0', # Remplace par ton port (ex : COM3 sous Windows)
|
||||
baudrate=115200,
|
||||
timeout=1 # En secondes
|
||||
)
|
||||
|
||||
print("Lecture du port série... (Ctrl+C pour quitter)")
|
||||
|
||||
try:
|
||||
while True:
|
||||
# Lire 2 octets
|
||||
data = ser.read(2)
|
||||
|
||||
if len(data) == 2:
|
||||
temperature = data[0]
|
||||
humidite = data[1]
|
||||
print(f"Température: {temperature}°C, Humidité: {humidite}%")
|
||||
else:
|
||||
print("Pas assez de données reçues.")
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print("\nArrêt du script.")
|
||||
finally:
|
||||
ser.close()
|
Reference in New Issue
Block a user