arduino-photometrics/exec/time.py

23 lines
442 B
Python
Executable file

import serial
import time
ARDUINO_PORT = '/dev/ttyACM0'
BAUD_RATE = 9600
try:
ser = serial.Serial(ARDUINO_PORT, BAUD_RATE)
time.sleep(2)
except serial.SerialException as e:
print(f"Error : fail to open serial port {ARDUINO_PORT}: {e}")
exit()
epoch = int(time.time())
commande_rtc = f"T{epoch}\n"
ser.write(commande_rtc.encode())
ser.close()
print(f"Cmd send : {commande_rtc.strip()}")
print(f"Epoch send: {epoch}")