8000 Added ep8266 ADC example · librarysteve/lib-python@d1775f2 · GitHub
[go: up one dir, main page]

Skip to content

Commit d1775f2

Browse files
committed
Added ep8266 ADC example
1 parent 6a632f4 commit d1775f2

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

examples/esp8266/01_potentiometer.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
[Slide Potentiometer NodeMcu ESP8266] ===============================================================================
4+
5+
ESP8266 pinout:
6+
https://i.imgur.com/HgVTxCh.png
7+
8+
Slide Potentiometer:
9+
- connect VCC sensor line to "+3.3v" board pin
10+
- connect GND sensor line to "ground" board pin
11+
- connect DATA sensor line to board A0 pib (ADC - analog to digital conversion on dedicated pin)
12+
13+
Environment prepare:
14+
In your Blynk App project:
15+
- add "Gauge" widget,
10000 16+
- bind it to Virtual Pin V1
17+
- set name "Potentiometer"
18+
- set label /pin.##/
19+
- set update time=1 sec and assign 0-1024 values range to it
20+
21+
22+
- Run the App (green triangle in the upper right corner).
23+
- define SSID and WiFi password that will be used by ESP32 board
24+
- define your auth token for current example and run it
25+
26+
This started program will periodically call and execute event handler "read_virtual_pin_handler".
27+
that will try to get data from potentiometer and write it to related virtual pin.
28+
Within App widget gauge value will be updated each 1 sec.
29+
=====================================================================================================================
30+
Additional info about blynk you can find by examining such resources:
31+
32+
Downloads, docs, tutorials: http://www.blynk.cc
33+
Sketch generator: http://examples.blynk.cc
34+
Blynk community: http://community.blynk.cc
35+
Social networks: http://www.fb.com/blynkapp
36+
http://twitter.com/blynk_app
37+
=====================================================================================================================
38+
"""
39+
import blynklib
40+
import network
41+
import utime as time
42+
import machine
43+
44+
WIFI_SSID = 'YourWifiSSID'
45+
WIFI_PASS = 'YourWifiPassword'
46+
BLYNK_AUTH = 'YourAuthToken'
47+
48+
print("Connecting to WiFi network '{}'".format(WIFI_SSID))
49+
wifi = network.WLAN(network.STA_IF)
50+
wifi.active(True)
51+
wifi.connect(WIFI_SSID, WIFI_PASS)
52+
while not wifi.isconnected():
53+
time.sleep(1)
54+
print('WiFi connect retry ...')
55+
print('WiFi IP:', wifi.ifconfig()[0])
56+
57+
print("Connecting to Blynk server...")
58+
blynk = blynklib.Blynk(BLYNK_AUTH)
59+
adc = machine.ADC(0)
60+
61+
62+
@blynk.handle_event('read V1')
63+
def read_handler(vpin):
64+
p_value = adc.read()
65+
print('Current potentiometer value={}'.format(p_value))
66+
blynk.virtual_write(vpin, p_value)
67+
68+
69+
while True:
70+
blynk.run()

examples/esp8266/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ Examine [this document][blynk-esp32-readme] to get more details how to compile *
118118
***Note!!*** During custom firmware creation your libraries will be converted and adopted to esp8266 environment
119119
automatically. So you can create custom build and then just copy *.mpy files from docker system
120120
```bash
121-
docker cp micropython:/micropython/ports/esp8266/build/frozen_mpy/blinklib.mpy blinklib.mpy
121+
docker cp micropython:/micropython/ports/esp8266/build/frozen_mpy/blynklib.mpy blynklib.mpy
122122
```
123123

124124
After *.mpy files can be placed to **/lib** directory of esp8266 board with **ampy** tool and simply imported

0 commit comments

Comments
 (0)
0