Advertisement
iqhtyar2k

EspUploader

Jan 21st, 2024
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 KB | None | 0 0
  1. import serial
  2. import binascii
  3.  
  4. def convert_to_bin(text):
  5.   return binascii.unhexlify(text.replace(" ", ""))
  6.  
  7. def upload_to_serial(data, port, baudrate):
  8.   with serial.Serial(port, baudrate) as ser:
  9.     ser.write(data)
  10.  
  11. if __name__ == "__main__":
  12.   # Buka file teks
  13.   with open("coding.txt", "r") as f:
  14.     text = f.read()
  15.  
  16.   # Konversi file teks ke format biner
  17.   data = convert_to_bin(text)
  18.  
  19.   # Upload data ke serial port
  20.   upload_to_serial(data, "COM3", 9600)
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement