ESP8266-Workshop: Unterschied zwischen den Versionen
Anlumo (Diskussion | Beiträge) |
Anlumo (Diskussion | Beiträge) |
||
(8 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
Zeile 60: | Zeile 60: | ||
* [http://esp.opentu.net/ WebREPL] | * [http://esp.opentu.net/ WebREPL] | ||
* [https://docs.micropython.org/en/latest/esp8266/esp8266/tutorial/index.html Dokumentation] | * [https://docs.micropython.org/en/latest/esp8266/esp8266/tutorial/index.html Dokumentation] | ||
= Workshop-Notizen = | |||
== Pinout des Zusatzboards == | |||
{| | |||
|- | |||
! GPIO !! Funktion | |||
|- | |||
| 0 || Neopixel | |||
|- | |||
| 5 || rote LED | |||
|- | |||
| 13 || linker Button | |||
|- | |||
| 15 || rechter Button | |||
|} | |||
Am ADC 0 hängt der Helligkeitssensor. | |||
== Generell == | |||
Firmware flashen: | |||
<pre>esptool.py.exe --port COM15 --baud 460800 write_flash --flash_size=detect 0 esp8266-20170612-v1.9.1.bin | |||
</pre> | |||
COM15 durch den Port ersetzen (zB /dev/ttyUSB0 unter Linux). | |||
Modul laden/entladen: | |||
<pre>import meinmodul | |||
del meinmodul</pre> | |||
== LED ansteuern == | |||
<pre>import machine | |||
pin = machine.Pin(5, machine.Pin.OUT) | |||
pin.value(0) | |||
pin.value(1)</pre> | |||
== PWM == | |||
<pre>import machine | |||
pin = machine.Pin(5, machine.Pin.OUT) | |||
pwm = machine.PWM(pin) | |||
pwm.freq(5) | |||
pwm.duty(512)</pre> | |||
== Button == | |||
<pre>import machine | |||
pin = machine.Pin(13, machine.Pin.IN) | |||
pin.value()</pre> | |||
== Interrupts == | |||
<pre>from machine import Pin | |||
import utime | |||
def callback(p): | |||
led=Pin(5, Pin.OUT) | |||
led.value(0) | |||
utime.sleep_ms(100) | |||
led.value(1) | |||
pin = Pin(13, Pin.IN) | |||
pin.irq(trigger=Pin.IRQ_FALLING|Pin.IRQ_RISING, handler=callback)</pre> | |||
== ADC (Helligkeitssensor) == | |||
<pre>import machine | |||
adc = machine.ADC(0) | |||
adc.read()</pre> | |||
== Timer == | |||
<pre>import machine | |||
pin = machine.Pin(5, machine.Pin.OUT) | |||
adc = machine.ADC(0) | |||
def readsensor(t): | |||
pin.value(adc.read() < 800) | |||
tim = machine.Timer(-1) | |||
tim.init(period=100, mode=Timer.PERIODIC, callback=readsensor)</pre> | |||
== Neopixel == | |||
<pre>import machine, neopixel | |||
np = neopixel.NeoPixel(machine.Pin(0), 1) | |||
np[0] = (255, 0, 0) | |||
np.write()</pre> | |||
== Netzwerk == | |||
=== Setup (nur einmal notwendig!) === | |||
<pre>import network | |||
nic = network.WLAN(network.STA_IF) | |||
nic.active(True) | |||
nic.connect('metalab','') | |||
nic.ifconfig() | |||
import webrepl_setup</pre> | |||
=== Sockets === | |||
<pre>import socket | |||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |||
s.connect(("127.0.0.1", 1234)) | |||
s.send("Hello World\n".encode('utf-8')) | |||
s.close()</pre> |