-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
51 lines (38 loc) · 1.33 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
"""
Main script
Do your stuff here, this file is similar to the loop() function on Arduino
Example on how to perform an update of the Nextion display content
"""
# system packages
import time
# custom packages
from nextion import NexHardware, NexUpload
# define communication pins for Nextion display
tx_pin = 21
rx_pin = 22
# create Nextion hardware interface
nh = NexHardware(rx_pin=rx_pin, tx_pin=tx_pin)
# init nextion communication interface
nh.nexInit()
# create a upload instance
nex_download = NexUpload(nh, "everything.tft", 115200)
# ============================================================================
# ============================ Special functions =============================
# print file infos
print('Update file name: "{}" with size of "{}" byte'.
format(nex_download.file_name, nex_download.file_size))
# perform update
print('Performing update, please wait ...')
result = nex_download.upload()
if result:
print('Update done successfully')
else:
print('Update failed')
print()
# ============================================================================
# ============================= End of example ===============================
print('Returning to REPL in 5 seconds')
# wait for 5 more seconds to safely finish the may still running threads
time.sleep(5)