-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathESP32_internals.py
70 lines (43 loc) · 1.92 KB
/
ESP32_internals.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# ESP32_Internals.py
# This sample program shows some information
# and uses some on-board resources to illustrate their query
# (c) 2019-01-29 Claus Kuehnel ([email protected]
import machine, time, sys, uos, ubinascii, esp, esp32
from machine import Timer
from machine import Pin
led = Pin(2, Pin.OUT) # external LED on ESP32 DevKit
def blink():
led.on()
time.sleep_ms(20) # LED on for 20 milliseconds
led.off()
print('\nThis program will show some information')
print('and the usage of some on-board ressources of ESP32 DevKit\n')
print('The external led blinks ones per second\n')
print('This is a {}'.format(uos.uname().machine))
print('Installed firmware version is {}\n'.format(uos.uname().version))
print('Platform is {}'.format(sys.platform))
print('Micropython version is {}'.format(sys.version))
print('Flash size is {:4.2f} MByte'.format(esp.flash_size()/1000000))
print('CPU frequency is {:3.0f} MHz'.format(machine.freq()/1000000))
print('Chip temperature is {:3.1f} *C'.format((esp32.raw_temperature()-32)*5/9))
print('Hall sensor readout is {}\n'.format(esp32.hall_sensor()))
UID = ubinascii.hexlify(machine.unique_id()).decode('utf-8')
print('Length of UID is {} bytes'.format(int(len(UID)/2)))
print('UID is {}\n'.format(UID))
t = Timer(-1) # virtual (RTOS-based) timer
t.init(period=1000, mode=Timer.PERIODIC, callback=lambda f: blink())
print('Press the USR button to change the blink frequency')
print('Ctrl-C stopps the running program')
usrButton = Pin(0, Pin.IN, Pin.PULL_UP) # USR Button
global state
state = 0
while True:
btn = usrButton.value()
if btn == 1 and state == 0:
state = 1
#print('Button released')
t.init(period=1000, mode=Timer.PERIODIC, callback=lambda f: blink())
if btn == 0 and state ==1:
state = 0
#print('Button pressed')
t.init(period=100, mode=Timer.PERIODIC, callback=lambda f: blink())