-
Notifications
You must be signed in to change notification settings - Fork 0
/
MicroPython_single.py
102 lines (86 loc) · 3.47 KB
/
MicroPython_single.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
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
#Blogs @ https://clevertronics.blogspot.com/search/label/MicroPython
#------------------------------------------BLOG POST #1------------------------------------------------------------
# Hello world, The below are MicroPython codes which are tested on ESP 8266 V.3. All details are mentioned at clevertronics.blogspot.com
#Turn LED on
# Hello world, The below are MicroPython codes which are tested on ESP 8266 V.3. All details are mentioned at clevertronics.blogspot.com
#Turn LED ON
import machine
pin = machine.Pin(2, machine.Pin.OUT)
pin.on()
#------------------------------------------BLOG POST #1------------------------------------------------------------
# Hello world, The below are MicroPython codes which are tested on ESP 8266 V.3. All details are mentioned at clevertronics.blogspot.com
#Blink with Delay
import machine
import time
pin = machine.Pin(2, machine.Pin.OUT)
while True:
pin.on()
time.sleep(0.5)
pin.off()
time.sleep(0.5)
#-----------------------------------------BLOG POST #2------------------------------------------------------
# Hello world, The below are MicroPython codes which are tested on ESP 8266 V.3. All details are mentioned at clevertronics.blogspot.com
#Blink custom number of times
import machine
import time
pin = machine.Pin(2, machine.Pin.OUT)
n=int(input("Enter the number of Blinks you need : "))
for i in range(n):
pin.off()
time.sleep(0.5)
pin.on()
time.sleep(0.5)
#-----------------------------------------BLOG POST #3----------------------------------------------------
# Hello world, The below are MicroPython codes which are tested on ESP 8266 V.3. All details are mentioned at clevertronics.blogspot.com
#PWM, LED fade
from machine import Pin, PWM
from time import sleep
frequency = 5000
led = PWM(Pin(2), frequency)
while True:
for duty_cycle in range(0, 1024):
led.duty(duty_cycle)
sleep(0.005)
#--------------------------------------BLOG POST #4--------------------------------------------------
# Hello world, The below are MicroPython codes which are tested on ESP 8266 V.3. All details are mentioned at clevertronics.blogspot.com
#Read Temperature Sensor
from machine import Pin
from time import sleep
import dht
sensor = dht.DHT11(Pin(14))
while True:
try:
sleep(2)
sensor.measure()
temp = print('Temperature:',sensor.temperature(),'*C','\n')
hum = print('Humidity:',sensor.humidity(),'%','\n','-----------')
except OSError as e:
print('Failed to read sensor.')
#-------------------------------------BLOG POST #4-----------------------------------------------
# Hello world, The below are MicroPython codes which are tested on ESP 8266 V.3. All details are mentioned at clevertronics.blogspot.com
#DHT-11 based simple temperature alert system.
import machine
pin1 = machine.Pin(5, machine.Pin.OUT)
pin2 = machine.Pin(14, machine.Pin.OUT)
from machine import Pin
from time import sleep
import dht
sensor = dht.DHT11(Pin(4))
while True:
try:
sleep(2)
sensor.measure()
print('Temperature:',sensor.temperature(),'*C','\n')
print('Humidity:',sensor.humidity(),'%','\n','-------------------')
except OSError as e:
print('Failed to read sensor.')
if sensor.temperature() >33:
pin1.on()
print('Temperature:',sensor.temperature(),'*C',"Temperature is High(>33*C)",'\n')
else:
pin1.off()
if sensor.humidity() > 90:
pin2.on()
print('Humidity:',sensor.humidity(),'%',"Humidity is High(>90%)",'\n','-------------------')
else:
pin2.off()