-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
128 lines (91 loc) · 2.51 KB
/
main.py
File metadata and controls
128 lines (91 loc) · 2.51 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import machine
from machine import I2C,Pin,UART
from lcd_api import LcdApi
from pico_i2c_lcd import I2cLcd
from ssd1306 import SSD1306_I2C
from micropyGPS import MicropyGPS
import time
#开始初始化
# ===OLED===
# I2C
oled_i2c_sda = machine.Pin(10)
oled_i2c_scl = machine.Pin(11)
oled_i2c_i2c = machine.I2C(1,sda=oled_i2c_sda,scl=oled_i2c_scl, freq=400000)
oled = SSD1306_I2C(128, 64, oled_i2c_i2c)
oled.fill(0)
oled.show()
oled.text('Initializing...', 0, 32)
oled.show()
# ===LCD1602===
# I2C
lcd1602_i2c_sda = machine.Pin(16)
lcd1602_i2c_scl = machine.Pin(17)
lcd1602_i2c_i2c = machine.I2C(0,sda=lcd1602_i2c_sda,scl=lcd1602_i2c_scl, freq=400000)
I2C_ADDR = 0x27
I2C_NUM_ROWS = 4
I2C_NUM_COLS = 20
lcd = I2cLcd(lcd1602_i2c_i2c, I2C_ADDR, I2C_NUM_ROWS, I2C_NUM_COLS)
lcd.clear()
lcd.move_to(0,0)
lcd.putstr("Initializing...")
lcd.move_to(0,1)
lcd.putstr('Powered By Eric')
# ===UART===
uart_tx=machine.Pin(4)
uart_rx=machine.Pin(5)
com = UART(1, baudrate=9600, tx=uart_tx, rx=uart_rx)
time.sleep(2)
my_gps = MicropyGPS(8)#东八区修正
# 初始化OK清空显示
oled.fill(0)
oled.show()
lcd.clear()
def get_GPS_values():
global rtc,lat,long
time.sleep_ms(100)
cc = com.readline()
for x in cc:
my_gps.update(chr(x))
#lat&long
lat=str(my_gps.latitude[0] + (my_gps.latitude[1] / 60))
long=str(my_gps.longitude[0] + (my_gps.longitude[1] / 60))
#datetime
date = my_gps.date
timestamp = my_gps.timestamp
hour = timestamp[0]
rtc = str(int(timestamp[0]))+":"+str(int(timestamp[1]))+":"+str(int(timestamp[2]))
#return 0 #lat,long,rtc
# 开始显示
while True:
time.sleep_ms(100)
get_GPS_values()
lcd.clear()
lcd.move_to(0,0)
lcd.putstr(lat)
lcd.move_to(0,1)
lcd.putstr(long)
oled.fill(0)
oled.text('Date:', 0, 0)
oled.text(my_gps.date_string(), 40, 0)
oled.text('Time:', 0, 10)
oled.text(rtc, 40, 10)
oled.text('Current:', 0, 20)
oled.text(str(my_gps.satellites_in_use), 70, 20)
oled.text('Alt:', 0, 30)
oled.text((str(my_gps.altitude)+"m"), 32, 30)
oled.text('Course:', 0, 40)
oled.text(str(my_gps.course), 55, 40)
oled.text('Speed:', 0, 50)
oled.text(str(my_gps.speed[2]), 50, 50)
oled.show()
time.sleep_ms(100)
# LCD1602显示经纬度
'''
lcd.move_to(0,0)
lcd.putstr("Hello")
lcd.move_to(0,1)
lcd.putstr("Hello this")'''
# OLED显示其他信息
'''oled.text('Hello', 0, 0)
oled.text('World', 0, 10)
oled.show()'''